Coder Social home page Coder Social logo

Comments (6)

tunjid avatar tunjid commented on August 24, 2024

@Minification
The root function is called only once; when the tab is visited for the the first time. After that, tapping on a previously visited tab will just show the fragment returned by the root function previously.

    override val navigator: MultiStackNavigator by multiStackNavigationController(
            tabs.size,
            R.id.content_container,
            RouteFragment.Companion::newInstance // Will be called once for each index
    )

As far as inner fragments go, their state will be preserved automatically as the FragmentManager takes care of it. If you wanted to show a different fragment at the root of each index, like with Instagram, you could do

    override val navigator: MultiStackNavigator by multiStackNavigationController(
            4,
            R.id.content_container,
            { index -> 
                when(index) {
                0 -> HomeFragment()
                1 -> ExploreFragment()
                2 -> ActivityFragment()
                3 -> ProfileFragment()
            }
    )

Within each inner fragment, if you wanted to go deeper into the tab, you can just get an instance of the navigator and push the new fragment like so:

class HomeFragment {
        private val navigator by activityNavigatorController<MultiStackNavigator>()

    fun goToPost(post: Post) {
        navigator.push(PostFragment.newInstance(post)
    }
}

Hope that helps.

from android-extensions.

Minification avatar Minification commented on August 24, 2024

Hi,

thanks for you quick reply, I think I understood.

I'm not sure if there isn't a bug, though. Assume we are using the example you gave above and HomeFragment has a button which takes us to InnerHomeFragment. Now I perform the following actions:

  1. Start app, i.e. HomeFragment
  2. ExploreFragment
  3. ActivityFragment
  4. HomeFragment
  5. Press button, i.e. go to InnerHomeFragment
  6. ExploreFragment
  7. ActivityFragment

And now we press the back button a few times. What happens is the following:

  1. ExploreFragment
  2. InnerHomeFragment
  3. HomeFragment
  4. App shuts down gracefully (i.e. without errors)

Instead of the last step, I would have expected ActivityFragment, then ExploreFragment, then HomeFragment to show and then the app to shut down gracefully upon another back button press.

Is this inteded behaviour?

from android-extensions.

tunjid avatar tunjid commented on August 24, 2024

@Minification Ah is see what you mean. The implementation of this is in MultiStackVisitor in MultiStackNavigator.kt; the assumption was no tab can exist twice in the nav history which is exactly what Instagram does. This can be modified, but like in the post you referenced, "Instagram-like navigation" is what I was going for with this.

from android-extensions.

Minification avatar Minification commented on August 24, 2024

I see, I believe instagram mostly circumvents this by swipes and button clicks navigating to fragments/activities without a bottom navigation view.

Would it be possible to make the MultiStackVisitor a overridable component of MultiStackNavigator, such that one could implement other behaviours?

But I believe I can work around this and essentially get my app to work about the same way that instagram does, thanks for taking the time to reply to this thread.

from android-extensions.

tunjid avatar tunjid commented on August 24, 2024

@Minification that can be done, but probably not till this weekend or the next. You can submit a PR for it with tests if you want, all you need to do is selectively call this line with some boolean flag and it should work: https://github.com/tunjid/Android-Extensions/blob/develop/navigation/src/main/java/com/tunjid/androidx/navigation/MultiStackNavigator.kt#L251

from android-extensions.

tunjid avatar tunjid commented on August 24, 2024

@Minification done in #102

from android-extensions.

Related Issues (13)

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.