Actually, it happens when I open a bottom sheet while it’s navigating between 2 of them. So let’s fork Google Accompanist !First, We tried to pop to the first back stack entry: but by monkey testing we get the error below. Unfortunately, we can’t change what it does without forking the library. You can do it easily on button click, but how to do it if the user swipes down the bottom sheet or clicks on backdrop? In these two cases, the ++code>onSheetDismiss++/code> function from accompanist SheetContentHost is called. Partial solution: navigate back to Home instead of calling ++code>hide()++/code> But if you close the sheet when you click on the backdrop or when you call ++code>hide()++/code> on the state, you don’t want the previous bottom sheet from the back stack to show up. I don’t want to navigate back when close a bottomSheet → I just want to close all bottom sheetsīy default, when you navigate from a bottom sheet to another, you can use the Android back button to nav back (see Troubleshooting section if it’s not working). It enables other possibilities we won’t discuss right now. Passing a sheetState as a parameter enables us to skip the half expanded state if we want. Accompanist doesn’t let us do, so we have to create a function for it: However, it’s very common to skip ++code>halfExpanded++/code> state, and compose-material enables us to do so. Two hacks we found to enhance Accompanist library Half expanded state → If we want to skip it?Ī ModalBottomSheetLayout can be in 3 states : ++code>hidden, expanded and halfExpanded++/code>. Then you just need to navigate with the ++code> navController++/code> to open bottom sheets and navigate between them. For example, the fact that a bottom sheet with 0dp height will crash. That way, in the ++code>NavHost++/code> where you specify the compose destination, the library has an indication to tell if you want to open a bottom sheet or just navigate to another full screen composable.Īnother advantage of using this library is that it already fixes some bugs linked to the bottom sheet itself. The second key point is the Kotlin extension of compose ++code> NavGraphBuilder++/code> to specify a second kind of destination: ++code>bottomSheet++/code>. ![]() This navigator is a normal navigator from ++code>androidx.navigation++/code> that can manage the bottomSheetState (to show and hide bottom sheet) and navigate between the multiple bottom sheets. The first is that it uses the ++code> ModalBottomSheetLayout++/code> and wraps it with a ++code> BottomSheetNavigator++/code>.Use the compose library, for example use 1.2.0 version which is compatible with Kotlin 1.7.0 Android Accompanist Navigation Material library Key points of the library As a bonus, it should be good to navigate to a second screen or to go to the bottom sheet “X B” from “Y A” (spoiler: it’s included in the library).Ĭompose and other Android library dependencies ![]() Also, it’s not possible to skip the half extended position of the bottom sheet using the accompanist default implementation. Blue represents what doesn’t currently exist in the Google Accompanist library. This scheme represents what we want the most.
0 Comments
Leave a Reply. |