compose-destinations: Cannot use BottomSheets navigation without AnimatedNavigator
Example how I’d expect it work:
@Composable
fun DefaultNavHost() {
val bottomSheetNavigator = rememberBottomSheetNavigator()
val navController = rememberNavController(bottomSheetNavigator)
ModalBottomSheetLayout(
bottomSheetNavigator = bottomSheetNavigator,
sheetShape = defaultSheetShape,
sheetBackgroundColor = BgDefault
) {
DestinationsNavHost(
navController = navController,
navGraph = NavGraphs.root,
dependenciesContainerBuilder = {
val onboardingViewModel: OnboardingViewModel = get()
dependency(onboardingViewModel)
}
)
}
}
I would like to avoid using animations-lib in my project because they change default animation that I need. The code above gives error:
FATAL EXCEPTION: main
java.lang.IllegalStateException: You need to use 'rememberAnimatedNavHostEngine' to get an engine that can use BottomSheet and pass that into the 'DestinationsNavHost'
OK, I add this line engine = rememberAnimatedNavHostEngine(),
Now error is:
FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not find Navigator with name "animatedComposable". You must call NavController.addNavigator() for each navigation type.
so I assume it’s impossible to use BottomSheets without animation. However, that is possible with pure Compose navigation. Can this be fixed? Or what I’m doing wrong
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (8 by maintainers)
I got same error:
It turns out we must use
rememberAnimatedNavController()
and notrememberNavController()
When using:
👍🏻
The reason is to disable transactions right? If I have some time today I’ll look into it. It should be similar to what you did, I’ll let you know 🙂
NavGraphs.root.nestedGraphs() or something similar to get nested graphs 😁
Creating your own engine is something you definitely shouldn’t need to do though. Disabling animations should be easy. I’ve done it in the past similar to what you did, but I cannot remember from top of my head 🤔
OK, I managed to make it work by:
However, I had to use the
animations-core
dependency, otherwise I got exception:So, after I failed above I tried another way - creating my own
DefaultNavHostEngine
.First of all, I changed
compose-destinations
dependency tocore
and added dependency tonavigation-material
:Then copied impl from the lib and adjusted:
I’ve added
is DestinationStyle.BottomSheet
case to default implementation. I almost succeeded, the thing is thatDestinationScopeImpl.Default
fromCallComposable
is internal in the lib:Is there a way to workaround it?