Scenario:
Application is tab-based; one tab is a container view having a 'Picker (Data) View'.
Picker View: the Picker is initially loaded with data via #State -> #Binder.
A 'Front Page' (Greetings) View is initially displayed over the Picker View within a ZStack{}.
User Acknowledges the front page which disappears to reveal the Picker View (#2).
Note: Data is received by the Picker per debug check.
The hidden Picker View shows the initial data.
Problem:
The revealed Picker View becomes empty; after dismissing the Front Page/View.
The following is a debug listing via BreakPoint of data:
Observation:
I want to access the data source ASAP to populate the Picker View to avoid having the user wait for the data. Hence the data is initially access prior to revealing the Picker View.
However,
the Picker View apparently gets re-rendered just prior to being displayed.
Note: I see the populated picker page if I comment-out the front-page code.
👉 I've added a boolean filter to avoid calling the Picker with an empty data payload.
Question:
How do I make the data more permanent; that is, stay until it is dismissed?
Do I have to make a concrete copy of a #Binding variable?
Non-SwiftUI fix:
Use a Singleton for the persistent data vector; and hence not influenced by the life of the controlling View:
final class DataSource {
static let shared = DataSource()
var myVar:String = "Hello World"
var countryNames: [String]?
}
This is so simple that it's elegant.
Still, I would like to use combine here, but the data life is too volatile.
I plan to review this paradigm further into my project as I become more proficient in Combine.
If anyone has a SwiftUI/Combine method of accessing, holding/sharing data that doesn't require a Singleton object, please post.
Related
I have a custom paragraph type - which has 2 fields:
Display Mode,
View to be rendered
I want to let users choose Display Mode in this paragraph, then I will render view based on this Display Mode value.
The problem is, it seems there is no way for me to get this Display Mode value inside view template(views-view-unformatted.html) or hook (HOOK_preprocess_views_view).
Only what I can access is view object, which definitely does not have any parent entity info.
Any idea?
Under what conditions would a #State assignment not get set within the same code block?
I am battling a SwiftUI state issue and have found that in a block executed within a sheet closure, a view #State object is not retaining its value immediately after being set. If you look at the screenshot of the debugger break. The line directly above the green breakpoint sets the self.imageSource #State variable to selectedSelectedSource which is an enum. You can see in the watches that the value of selectedSource (First blue line) is ".library." Yet the value of self.imageSource (second blue line) is ".none"
I have tried multiple variations of this sheet code using all the patterns presentationMode, #binding the show variable, callbacks, asyncs and every time the #State imageSource never gets set. Ironically if I use an action sheet, it works without issue.
Please I am looking for answers pertaining to the mechanics of #State that would explain this behaviour.
I made a very simple table component. It takes a model, and builds a table from it.
http://emberjs.jsbin.com/raqomebeqi/1
Since its very primitive and has hard-coded property names, I decided to make an in-component representation of the model, to sort, filter the content of the table. It also allows to show just certain columns from the bounded model. (columns property)
http://emberjs.jsbin.com/raqomebeqi/2
The problem: It doesn't react to the changes of the model anymore. In the first example If I hit the 'change' button, it takes the first record, and set a new name. One can see the change in the table. In the second case Ember inspector shows the change of the name, but the table shows the old value.
I know I could do
data: Ember.computed('model.#each.name', function(){
//...
})
to monitor the changes on the name, but it is not very dynamic. How could I make my data react to each and every change on the model?
If you want your data to react on every change, you could do:
data: Ember.computed('model', function(){
//...
})
UPDATE:
This is not working
In my app I have a route where I'm using queryParams to filter an array.. When I add a new item to the array that matches the filter criteria the template does not update with the new item.
Super simple example bin at http://emberjs.jsbin.com/qetami/1#/colors?type=secondary
In that example, while filtered to Secondary colors click the Add Color button and add a new color with Color Type set to secondary. The color does not immediately appear. If you change the filter then go back to Secondary it appears. It automatically appears when on the unfiltered/default route.
I've tried with and without the queryParams hook in the Colors route with no luck.
This seems like it should be straight forward but I've run into a wall.
I couldn't really get something working with .observes() however I came up with a working version of your example if you leverage actions bubbling up through the routes so that you have a good spot to call this.refresh() in order to reload the filtered model.
http://jsbin.com/qomiba/3/edit
Side-note, I found it confusing that you had references to 'colors' in different places that meant different things.
From emberjs.com/guides
This will offload searching all of the possible records to the server,
while still creating a live updating list that includes records
created and modified on the client.
App.PostsFavoritedRoute = Ember.Route.extend({
model: function() {
var store = this.store;
// Create a filter for all favorited posts that will be displayed in
// the template. Any favorited posts that are already in the store
// will be displayed immediately;
// Kick off a query to the server for all posts that
// the user has favorited. As results from the query are
// returned from the server, they will also begin to appear.
return store.filter('post', { favorited: true }, function(post) {
return post.get('isFavorited');
});
}
});
I am working with 4 views using a Tab Bar. The first view has a tableview of rounds of golf. The second view allows the user to enter data for a new round. I have a button on the "Add Round" view that saves the inputted data to Core Data. When the user saves the round I want the view to segue back to the "home screen" where the rounds are displayed. I created a segue called "SavetoHomeSegue" in storyboard.
This is the code I use to switch between the views
[self performSegueWithIdentifier:#"SavetoHomeSegue" sender:self];
[self.tabBarController setSelectedIndex:0];
Here is my issue: When I switch back to the "Home Screen" the tableview now appears for the first tab AND the second tab. Also, it doesn't seem like the "Add Round" view was properly unloaded as I was previously having to manually clear the data inputs in the textfields. How do I transition from one tab to another and properly unload the views? I have posted my views below:
Home Screen View -
Add Round View -
You definitely shouldn't be segueing between tab bar vc's. Just save the data and refresh the other view on viewWillAppear. Call setSelectedViewController when necessary, but never segue between tab bar vc's.