I have some items in a modal sheet layout and when I press an Item, I navigate to another screen. However, when I press back button in the detail screen, the modal sheet reappears with a flashing behavior. I think this is because of recomposition but is there a way to prevent the recomposition without using a box and hiding-revealing the other screen? Any help is appreciated.
Maybe you need to pop the bottom sheet from the backstack?
When navigating to your detail screen from the bottom sheet, get the instance of the BottomSheetNavigator you used to create the ModalBottomSheetLayout and do:
bottomSheetNavigator.popBackStack(backstackEntry, true)
You get the backstackEntry from the lambda when calling bottomSheet(route)
Related
I am currently migrating my old Android app (based on xml-views) to Jetpack Compose. I use a Single Activity for all my composables (views). I use a NavController to navigate. There is something that is not clear to me:
In classic xml views, when you scroll or enter something in a text field on a particular screen for example, and you open a new Activity, and you press the backbutton, the scroll position and the text entry on the previous screen is still visible. In Compose, the screen is reset to its starting position when pressing backbutton. For some screens this is not a problem, but for others it is. Can someone help me how to solve this in Compose?
I need to open a bottom sheet with some content, and I want the accessibility focus to stay in that bottom sheet. I've tried to open the sheet in a view, in a separate fragment, in a PopupWindow, but anyway it was possible to move the focus "bellow" my sheet. Is there any way to solve that?
Thank you.
Initially the bottom sheet is remains hidden, when I click on some place then bottom sheet should appear and when I click clear icon then the bottom sheet should be hidden actual manner, which is should be on initial state.
Initial App launch code:
bottomSheetInfoBehavior.setHideable(true);
bottomSheetInfoBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
After clicking on some place then this is the code which pops up the bottom sheet:
bottomSheetInfoBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
Finally when the clear icon is clicked then this the code that is hiding the bottom sheet (NOT WORKING):
bottomSheetInfoBehavior.setHideable(true);
bottomSheetInfoBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
Expected Result is:
When the clear icon is clicked then the bottom sheet should not appear in the screen, that should be disabled..! and should not visible in screen..!
You should use Bottom sheet's dismiss method in clear button.
And
use show method to show the BottomSheet dialog.
Keep the reference of BottomSheetDialog and use is accordingly.
From the code you have shared u are setting the state/behaviour of the BottomSheet which will be taken care by these method's automatically.
Ref:
BottomSheetDialog
I'm using Jetpack Navigation to handle the bottom navigation controller. It works great; however, I am looking for a way to improve the UX.
Is it possible to disable the tab that the user is currently navigated to?
I'm able to "spam" the current tab in the bottom navigation, which reloads data & the UI unnecessarily. If this behavior (of re-tapping the current tab) is intended, is there a way to retain the state of the fragment, so that when navigated away & to, it doesn't recreate?
How I handle the bottom navigation:
navController = NavHostFragment.findNavController(navigation_host_fragment)
NavigationUI.setupWithNavController(bottom_navigation_view, navController)
As per this issue:
Feel free to set a OnNavigationItemReselectedListener, which takes precedence over the OnNavigationItemSelectedListener set by NavigationUI: setOnNavigationItemReselectedListener
bottom_navigation_view.setOnNavigationItemReselectedListener {
// Do nothing
}
I would like to use the new Navigation Component for my next application but I can't quite wrap my head around the overall flow of navigation.
The Android team recommends a single activity as an entry point. They also suggest that conditional elements like a login / register should not be the entry point.
But then how do you display the login and register buttons if the entry screen is supposed to be the home screen?
Another idea is to use a Splash screen, have the logic there to determine if the user is already logged in, if so go to the home screen, if not show the login / register screen(s).
My other issue is with the single activity. My home screen would need to be a screen with a Bottom Navigation.
How do you tie all of this the "right way"? Do I need to have a separate navigation graph for the Home view, with the Bottom Navigation and the many screens that will flow from there?
All the examples I have found have been very straightforward, and the few I have seen with a Splash screen splitting into Home and Login have a very simple Home fragment, which in my case would be . more complex with the Bottom Nav.
Thanks.
One way to do this, you hide the bottom navigation in the login and popup the homepage when you navigate to the login page so the user would not be able to go back to the splash screen
1-you can hide the bottom naviagtion bar in the login fragment like this
val toolbar = activity!!.findViewById<Toolbar>(R.id.toolbar)
val bottombar = activity!!.findViewById<BottomNavigationView>(R.id.bottomNavigationView)
toolbar.visibility = View.GONE
bottombar.visibility = View.GONE
2- popup the splash fragment when you navigate to the login page
<action
android:id="#+id/action_splashFragment_to_loginFragment"
app:destination="#id/loginFragment"
app:popUpTo="#+id/splashFragment"
app:popUpToInclusive="true"/>
Hopefully it will work for you
Simple example =
Single activity, Multi fragment with bottom navigation bar and with Android Navigation comp.
Plan:
Show a splash screen with a timer like 3000 milis.
End of the milis navigate the user to login screen if already logged (check it on splash) navigate user to home screen
Now you can show a bottom nav. bar. For example "Home" "News"
You can handle backPresses in navigation. Handle for home (Disable to returning splash)
That's all folks!