Comments (8)
Great. My solution base on the same concept. Thanks for help! :)
from simple-stack.
Hi, thanks for reaching out!
If you are using the MultiStack class from the simple-stack-example-multistack
along with a custom state changer like in that example (the MainActivity
),
then it seems to me that calling multistack.setSelectedStack(StackType.values()[itemIndex].name());
gets evaluated in the state changer based on the previously shown view - what stack it belonged to, and what kind of animation it should show.
setStateChanger()
should call an initialize state change (so previous state will be empty list), but it should initialize to the previously saved state as new state, and NOT the default key.
Meaning in the example, going from MAIL to CLOUDSYNC will show a state change of [[], [CloudSync, Another]]
- but this means that you are supposed to initialize to the top state of the other stack, without initializing to CloudSync first.
So I don't seem to be reproducing the two-step initialization and would need to see more code to know what's up.
from simple-stack.
Hi, thanks for fast replay.
I am using method setSelectedStack when I am changing tabs in the bottom navigation.
Base on your answer I think I found the proper solution, but I will try to explain it better to you.
Here is my initialization code:
`private fun initMultistack(savedInstanceState: Bundle?) {
multistack = Multistack()
multistack!!.add(HOME.name, BackstackDelegate(null))
multistack!!.add(SEARCH.name, BackstackDelegate(null))
multistack!!.add(CONTACT.name, BackstackDelegate(null))
multistack!!.add(EXTRA.name, BackstackDelegate(null))
multistack!!.add(PROFILE.name, BackstackDelegate(null))
val nonConfigurationInstance: Multistack.NonConfigurationInstance? = lastCustomNonConfigurationInstance as? Multistack.NonConfigurationInstance
multistack!!.onCreate(savedInstanceState)
multistack!!.onCreate(HOME.name, savedInstanceState, nonConfigurationInstance, HomeKey())
multistack!!.onCreate(SEARCH.name, savedInstanceState, nonConfigurationInstance, SearchKey())
multistack!!.onCreate(CONTACT.name, savedInstanceState, nonConfigurationInstance, ContactKey())
multistack!!.onCreate(EXTRA.name, savedInstanceState, nonConfigurationInstance, ExtraKey())
multistack!!.onCreate(PROFILE.name, savedInstanceState, nonConfigurationInstance, ProfileKey())
}`
My previous solution was:
Backstack.getKey<Key>(context).selectDelegate(context).backstack.goTo(newKey)
Currently I have something like this:
fun ViewGroup.goTo(newKey: Key, animationType: ExtradomAnimationUtils.AnimationType, stackIdentifier: String? = null) { newKey.animationType = animationType newKey.parentStackIdentifier = stackIdentifier ?: Backstack.getKey<Key>(context).stackIdentifier() Backstack.getKey<Key>(context).selectDelegate(context).backstack.goTo(newKey) })
Github formatting is not working well for this part of code.
Here is pastebin url: https://pastebin.com/8WELEq6J
My solution base on changing stack identifier for a particular key on the fly. It means when I want to reach out SearchResultView from HomeView the stack identifier for SearchResultKey is HOME.name, but when I want to reach out SearchResultView from SearchView ( default view for SEARCH.name stack) then I returning default stack identifier for SearchResultKey.
I found one problem with my solution. I have two different SearchResultView in the application. One in HOME.name stack and one in SEARCH.name stack.
Here is the rest of the code for better understanding: https://pastebin.com/3bRB45Y7
from simple-stack.
Consider making multistack
be lateinit
, that way you don't need to write the !!
s.
I found one problem with my solution. I have two different SearchResultView in the application. One in HOME.name stack and one in SEARCH.name stack.
This should not be a problem as long as SearchResultKey
knows what stack it is in, and that equals()
is not true for the two keys of the two views of the same type.
However, I've been thinking about this but the API doesn't really seem to allow calling setStateChanger()
on a BackstackDelegate (or a BackstackManager) without calling an initialize
state change (which is what sets up the initial view for you that it animates out with goTo()
).
I wonder if you really do need to jump between the stacks in order to navigate to the SearchResultView?
from simple-stack.
Maybe I don't have to change stack but I don't have any idea how to do that. My goal is to go to the SearchResultView but with current implementation it is connected with SEARCH.name stack.
Do you have any idea?
from simple-stack.
@avonil the simple solution (I do not know if your design requires otherwise) would be to give the selected stack of SearchResultView
as an input parameter for the constructor so that you have a "parentStack" instead of directly binding the view to only one given stack.
from simple-stack.
If you run into any issues, feel free to reach out!
from simple-stack.
It's probably been a while and it's not relevant at this point, but I've updated the Multistack sample as per simple-stack 2.0
which makes it more convenient to use than with the original BackstackDelegate-based version.
from simple-stack.
Related Issues (20)
- Allow removing a `Backstack.CompletionListener` from inside the listener itself HOT 5
- Clarification: can a service be registered/unregistered more than once? HOT 5
- Can I Use @styles/Theme.MyComposeTheme on AndroidManifests.xml? HOT 3
- Question: What is the purpose of RegistrationViewModel inside ServiceProvider in extension-compose-example? HOT 4
- What is the proper way to add a key to the top even if it already exists in the backstack? HOT 2
- Publish to MavenCentral instead of just Jitpack.io
- Unable to start activity ComponentInfo{com.xxxxxxxxxx.yyyyyy/com.xxxxxxxxxx.yyyyyy.activities.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment q2.v1: could not find Fragment constructor HOT 7
- How to 'lookup<>()' scoped class from an Android Service HOT 2
- Lazy initialization of ScopedServices HOT 2
- KMM support? HOT 2
- Screen can get the service from wrong scope during back animation HOT 6
- Backstack is not available in a child Fragment's onCreate after process death
- DialogFragment and BottomDialogFragment as part of navigation stack, question HOT 2
- Verify that the new `setParentServices()`'s `lookupFromScope(..., EXPLICIT)` behavior is what is expected
- Updating the Compose example to Compose 1.5.0 requires AGP 8.1
- Should Simple Stack be used in new projects HOT 14
- Crash due to activity.onBackPressed() when removing fragment hosting a WebView in AndroidView {} + FADE HOT 15
- Backstack with espresso HOT 3
- The service does not exist in any accessible scopes HOT 11
- Up navigation examples are hard to find HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-stack.