Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
How do I use a Button in a swiftUI view? The view will just contain the Button and some Texts. When the button is tapped it will execute a function that will change the words in the Texts and then wait for another Button tap and repeat. I could readily do it with UIKit but with swiftUI a Button seems to be more involved than I expected.
So the way you can do it is to create a custom button that you can use on many views.
/// Custom button that can be used in any view
struct CustomButton: View {
// This is the custom method called from other views
var action: () -> ()
var body: some View {
VStack {
Button(action: { self.action() }) {
Text("Tap me")
}
}
}
}
And then, you can use it this way on your main view and change the text for example. You can add anything you want in the changeMyText method.
// Your main view
struct ContentView: View {
// Keep track of the change of a tap
#State private var buttonTapped = false
var body: some View {
VStack(spacing: 50) {
Text(buttonTapped ? "My second Text" : "My first text")
// Declare your custom button with desired functions
CustomButton(action: { self.changeMytext() })
}
}
// Method where you perform whatever you need
func changeMytext() {
self.buttonTapped.toggle()
}
}
Related
I'm looking to reinitialise some settings and state data when my PluginSidebar is reopened, but I'm struggling to find anything useful in wp.data core/editor or similar that I could use to best create a subscription.
Does gutenberg provide any such data where I can check to see if the side panel is open or shut, so that I could fire a function of my choice every time it opens?
At present, I have a mutationObserver in place listening to see if it opens, which is quite clunky.
Some pseudo-code of my preferred approach.
subscribe(() => {
if (select('core/editor').isPluginSidebarOpen()) {
open = true
} else {
open = false
}
})
Your pseudo-code is so very close.. the function exists and is called isPluginSidebarOpened and comes from core/edit-post, eg:
import { subscribe, select } from '#wordpress/data';
subscribe(() => {
if (select('core/edit-post').isPluginSidebarOpened()) {
// Is open..
} else {
// Is closed..
}
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
So I've been building my first app and when I recently updated to Xcode 12 multiple issues have occurred...
I have noticed that there is no longer app and scene delegate files but my project is still using it. Wondering how I clean this up without copying and pasting everything into a new project.
I also am having multiple warnings saying:
"The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.0.99."
I currently have my Deployment target to iOS 13. If I change it to 9 my URLIMAGE module comes up an error as it has a minimum of 11. When I change it to 11 I have 999+ errors...
example below:
I have no idea what to put it to!
I am also seeing along with URLImage that my firebase isn't properly working and that most of my UI has disappeared.
I am running through an instagram tutorial and my "Home" feed is now blank. My story feed file is still working fine though, not sure if it has something to do with firebase or URLImage?
I have played around with the view and added in a rectangle underneath my story scrollview and it has appeared so I suspect it has something to do with firebase.
Current code:
import SwiftUI
import URLImage
import Firebase
struct HomeView: View {
#ObservedObject var homeViewModel = HomeViewModel()
var body: some View {
NavigationView {
ScrollView(.vertical, showsIndicators: false) {
Story()
Rectangle().frame(width: 200, height: 200).foregroundColor(.red)
if !homeViewModel.isLoading {
ForEach(self.homeViewModel.posts, id: \.postId) { post in
VStack(alignment: .center) {
HeaderCell(post: post)
FooterCell(post: post)
}.background(Color.white).cornerRadius(10)
.padding(.leading, 10).padding(.trailing, 10)
}
}
}
This is my HomeViewModel:
import Foundation
import SwiftUI
import Firebase
class HomeViewModel: ObservableObject {
#Published var posts: [Post] = []
#Published var isLoading = false
var listener: ListenerRegistration!
// init() {
// loadTimeline()
// }
func loadTimeline() {
self.posts = []
isLoading = true
Api.Post.loadTimeline(onSuccess: { (posts) in
self.isLoading = false
if self.posts.isEmpty {
self.posts = posts
}
}, newPost: { (post) in
if !self.posts.isEmpty {
self.posts.insert(post, at: 0)
}
}) { (listener) in
self.listener = listener
}
}
}
Any help would be very much appreciated!
Without seeing your code, it's hard to say what exactly is the cause for the issues you're seeing. However, to answer some of your questions:
You can still use the old way the app is set up (using the AppDelegate and SceneDelegate. See my answer here for more details
You can safely ignore the warnings. If it bothers you a lot, check out this answer for a way to match the deployment target of your pods.
As for why your UI has disappeared, it would be useful if you could provide a couple of relevant code snippets and a few lines from your log output. Also, make sure to check if your Security Rules are set up correctly.
we are trying to use OnNavigatedFrom and OnNavigatedTo but the "OnNavigatedTo" is not called when needed
ViewModelOne:
_navigationService.NavigateAsync("ViewModelPageTwo", useModalNavigation: false);
ViewModelTwo:
var parameters = new NavigationParameters()
{
{
"Pesquisa",
TextoPesquisa
},
{
"DataEnvioInicial",
DataEnvioInicio
},
{
"DataEnvioFim",
DataEnvioFim
},
{
"DataHistoricoInicio",
DataHistoricoInicio
},
{
"DataHistoricoFim",
DataHistoricoFim
},
{
"TodasAsCaixas",
PesquisaEmTodasCaixas
}
};
_navigationService.GoBackAsync(parameters);
The problem is that ViewModelOne -> OnNavigatedTo not trigger when GoBackAsync from ViewModelTwo
So what's happening is when you call GoBackAsync, you are actually going back to the TabbedPage, not the actual Tab. For now, you can implement INavigationAware on the actual TabbedPage, and then pass your parameters to the selected Tab's VM in the code-behind. Not optimal, but it will work for now. There is actually a discussion on the GitHub site talking about the various issues when dealing with TabbedPages and it's children during navigation. YOu can follow it here:
https://github.com/PrismLibrary/Prism/issues/650
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
What is the difference between Meteor.templateName.events and Meteor.templateName.helpers.
and how do I know which one I need to implement for my template?
In short, helpers are functions you can use with {{}} as if they were variables in your Blaze templates. Events are functions you can bind to DOM events.
Example:
Template:
<template name="example">
<button>{{buttonLabel}}</button>
</template>
JS:
Template.example.helpers({
'buttonLabel': function(){ return "Click me"; }
});
Template.example.events({
'click button': function() {
// put your action here
console.log("button was clicked");
}
});
With this, your template will have a button with the label "Click me", returned by the buttonLabel helper. And when you click the button, the code inside the function bound to a button click event will be triggered (in this case, just printing "button was clicked" on the console).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Publishers sometimes release Epub titles without including all of the required browser-specific css declaration properties and prefixes. For example, a title might include a -webkit-transform declaration but omit transform or vice versa.
There are a number of tools available to assist developer workflow in the creation of new content Stackoverflow: How to automatically add browser prefix to CSS3 properties?; however, I am looking for a way to parse an entire Epub and add any missing properties.
We will assume that all the relevant CSS is in .css files. You can open the epub by unzipping it, and this will expose the CSS files, wherever they might be. You can then simply run these through your favorite prefixing tool, then zip the book back up.
The problem is that AFAIK prefixing tools typically expect the transform property and add the -webkit-transform counterpart. I am not sure these tools will work if only -webkit-transform is there and you want transform to be added. You'll have to check each tool to see if it provides this behavior. In the worst case, you could write your own plugin for a CSS transformation framework like rework to do what you need.
Ended up solving the problem using postcss with plugins postcss-unprefix and autoprefixer. postcss-unprefix removes existing prefixes and autoprefixer then adds any needed ones.
var fs = require('fs')
var postcss = require('postcss');
var input = process.argv[2]; // the source of the css
var output = process.argv[3]; // where to write the output
fs.readFile(input, 'utf8', function (err, result) {
if (err) {
console.log(err);
process.exit(1);
}
processCss(result, function (err, result) {
if (err) {
console.log(err);
process.exit(1);
} else {
fs.writeFileSync(output, result, "utf8");
process.exit(0);
}
})
});
function processCss(cssString, callback) {
postcss([require('postcss-unprefix'), require('autoprefixer')])
.process(cssString, { from: 'in.css', to: 'out.css' })
.then(function ( error, result ) {
if (result) {
callback(String.trim(result.css));
} else {
callback(null, error);
}
});
}