Comments (6)
@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.
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:
- Start app, i.e.
HomeFragment
ExploreFragment
ActivityFragment
HomeFragment
- Press button, i.e. go to
InnerHomeFragment
ExploreFragment
ActivityFragment
And now we press the back button a few times. What happens is the following:
ExploreFragment
InnerHomeFragment
HomeFragment
- 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.
@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.
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.
@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.
@Minification done in #102
from android-extensions.
Related Issues (13)
- Wrong order of selected tabs during back press? HOT 7
- StackNavigator shared element transition between activities HOT 3
- Minimal steps needed to implement speed dial HOT 1
- version 1.2.1 no definition for MultiStackNaviagor HOT 2
- Is this a property delegation in the declaration of the multiStackNavigator? HOT 2
- BackStackType Unlimited/Restricted in version 1.2.1 not working correctly HOT 4
- Bug: bad transformation on list when going back to it HOT 6
- How to integrate Material Search Bar with RecyclerView? HOT 2
- How to add multiple viewholders in recyclerview? HOT 4
- Can't perform this action after onSaveInstanceState HOT 5
- Kotlin-gradle-publin declared twice with different versions HOT 1
- How to use MaterialFadeThrough Transition as StackTransactionModifier? HOT 6
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 android-extensions.