Giter VIP home page Giter VIP logo

Comments (8)

dkwasniak avatar dkwasniak commented on May 25, 2024 3

Great. My solution base on the same concept. Thanks for help! :)

from simple-stack.

Zhuinden avatar Zhuinden commented on May 25, 2024

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.

dkwasniak avatar dkwasniak commented on May 25, 2024

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.

Zhuinden avatar Zhuinden commented on May 25, 2024

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.

dkwasniak avatar dkwasniak commented on May 25, 2024

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.

Zhuinden avatar Zhuinden commented on May 25, 2024

@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.

Zhuinden avatar Zhuinden commented on May 25, 2024

If you run into any issues, feel free to reach out!

from simple-stack.

Zhuinden avatar Zhuinden commented on May 25, 2024

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.

https://github.com/Zhuinden/simple-stack/blob/f28fcae66287dbb92faefdc905cd2901dd3e7e8d/simple-stack-example-multistack-view/src/main/java/com/zhuinden/simplestackdemomultistack/core/navigation/Multistack.kt

from simple-stack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.