Comments (10)
This widget is not supposed to be used with ViewPager. Read the specs. You're supposed to crossfade between - let's say - Fragments.
from ahbottomnavigation.
Maybe not entirely necessary, as you can do it this way
mBottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() { @Override public void onTabSelected(int position, boolean wasSelected) { mContainer.setCurrentItem(position); } });
But doing it this way still doesn't fully follow the spec, as it allows for horizontal scrolling between tabs, so you have to override that as well. That's why this implementation would be nice, as it eliminates a lot of boilerplate code and follows the spec.
from ahbottomnavigation.
@consp1racy That doesn't mean it can't be used with a ViewPager. You can disable the horizontal swipe, and leverage the ViewPager's ability to instantiate, manage, and recycle fragments.
from ahbottomnavigation.
@ncapdevi Correct, I like and use this behavior myself. However since ViewPager
itself is not issuing swipes, ergo not changing current position, it does not need to notify anyone of it rendering the need for suggested listener obsolete.
You can change the current item either by clicking a bottom navigation item or calling setCurrentItem
on the bottom navigation view in which case the associated OnTabSelectedListener
is invoked and the change propagated to the view pager. In any case bottom navigation is always the cause of change in the view pager. One issue comes to mind. Saved state. One of these would make a solution:
- Either saving last selected item (library maintainer),
- or setting current item before assigning listener (library client)
- or creating a
setupWithViewPager
method which does the above for you (library maintainer).
@aurelhubert I advise picking whatever TabLayout
does for the sake of consistency.
Off-topic:
This got me thinking how to crossfade the fragments when we're using the view pager to manage them. We could disable caching pages on the view pager so the fragments are not preloaded and then override [onCreateAnimation
](http://developer.android.com/reference/android/support/v4/app/Fragment.html#onCreateAnimation%28int, boolean, int%29) in each fragment we're using and supply a fade animation. What do you think of this? Would it be possible to verify this behavior?
from ahbottomnavigation.
Agreed. I posted this before I actually implemented it, and the OnTabSelectedListener seems to suffice without being cluttered.
Off-topic:
That's actually something I have in my pipeline to worry about as well. If it's too much of a hassle, then it negates the benefits of using a ViewPager, and means that we should be managing Tabs/Stacks entirely on our own, which is a bit of a hassle. I also (blasphemy!!!) don't feel the need to live and die by the spec sheet. It really depends on your application, and if the slide animation makes sense. That being said, it happens to not make sense for my application, and so I'll be needing to figure out a way to crossfade between tabs. I'd love for Android to implement some sort of ViewPager-esque object for this specific purpose, but who knows when that will come up. Once I get to that bridge and need to cross it, I'll send you any solution that I come up with if you'd like?
from ahbottomnavigation.
@ncapdevi TBH I didn't even know this thing was in MD until I saw the library. This is something I'd expect on iOS and old HTCs.
Definitely! If you find anything, hit me up. Thank you.
from ahbottomnavigation.
@ncapdevi @consp1racy I've detected the lack of saveStateInstance (for example when the orientation changes). If you have any suggestions for the implementation or want to submit pull requests, it could be great guys 👍 Maybe we can rename the issue?
from ahbottomnavigation.
@ncapdevi @consp1racy If you want to develop the functionality, feel free to ask for a pull request (I'm not sure to have the time to look at this in the next days). Thansk!
from ahbottomnavigation.
@ncapdevi crossfading between fragments is super easy, it just takes fragmentTransaction.setCustomAnimations(fade_in, fade_out) . No? Crossfading views might be trickier but not so difficult I’d say (Transition APIs would do this).
Apart from that, in my opinion this widget should be left completely unlinked to the child-switch process. It should just fire callbacks when a certain item is clicked, and let the client do whatever. We can’t predict how it’s going to be used.
I would also (except for very simple apps) not use any ViewPager here, since the bottom navigation is intended to give access to top level fragments, and these are presumably heavy. I would not like them to stay in memory. But that’s just my case.
Congrats for the library, I’m starting to use it now and will definitely work on state restoration, which is quite mandatory for me.
from ahbottomnavigation.
Thanks for all the feedback. I will close this issue for now (because of all the reasons listed in this thread). @miav feel free to submit a pull request :)
from ahbottomnavigation.
Related Issues (20)
- Not compatible with support library HOT 1
- Error org.gradle.execution.MultipleBuildFailures: Android Dragger - Kotlin
- NotFoundException HOT 1
- icon does not show icon (using selector) HOT 1
- 请我支持Lottie动画吗?
- Selected item borders on Pixel 3
- Change Color of a only one tab icon
- Change color of selected icon
- How I can change accentColor and inactiveColor of only one tab, others will be the same
- Item backgroundColor show error
- Animators may only be run on Looper threads Exception when displaying icon on Bottom Navigation
- notification is not shown when proguard is enabled
- Migrate artifacts from jcenter HOT 3
- How can I change the size of icon.
- How can I set create custom tab selector?
- 'FragmentPagerAdapter' is deprecated?
- Navigation Menu icon and text not sync with each other
- FAB or center icon in bottom nav
- JCenter end of life HOT 1
- Hide Tab programmatically
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 ahbottomnavigation.