setOnContextualToolbarLifecycleListener

Set the ToolbarCoordinatorLayout.OnContextualToolbarLifecycleListener to listen to the lifecycle of the contextual toolbar. Can be implemented in a LaunchedScope to handle the lifecycle of the contextual toolbar, i.e. LaunchedEffect(Unit) { documentState.setOnContextualToolbarLifecycleListener(object : ToolbarCoordinatorLayout.OnContextualToolbarLifecycleListener { override fun onPrepareContextualToolbar(toolbar: ContextualToolbar<*>) { if (toolbar is AnnotationCreationToolbar) { // Register grouping rule to tell toolbar how to group menu items. toolbar.setMenuItemGroupingRule(object : PresetMenuItemGroupingRule(context) { override fun getGroupPreset(capacity: Int, itemsCount: Int) = AnnotationCreationToolbarItemPresets.FOUR_ITEMS_GROUPING; }) } } }) }