Further breaks down the bottom bar to facilitate recompositions.

This commit is contained in:
Vitor Pamplona
2023-06-07 12:25:49 -04:00
parent ccfbfeffe2
commit eaae672a30
@@ -67,11 +67,16 @@ fun keyboardAsState(): State<Keyboard> {
view.getWindowVisibleDisplayFrame(rect) view.getWindowVisibleDisplayFrame(rect)
val screenHeight = view.rootView.height val screenHeight = view.rootView.height
val keypadHeight = screenHeight - rect.bottom val keypadHeight = screenHeight - rect.bottom
keyboardState.value = if (keypadHeight > screenHeight * 0.15) {
val newKeyboardValue = if (keypadHeight > screenHeight * 0.15) {
Keyboard.Opened Keyboard.Opened
} else { } else {
Keyboard.Closed Keyboard.Closed
} }
if (newKeyboardValue != keyboardState.value) {
keyboardState.value = newKeyboardValue
}
} }
view.viewTreeObserver.addOnGlobalLayoutListener(onGlobalListener) view.viewTreeObserver.addOnGlobalLayoutListener(onGlobalListener)
@@ -87,6 +92,16 @@ fun keyboardAsState(): State<Keyboard> {
fun AppBottomBar(accountViewModel: AccountViewModel, navEntryState: State<NavBackStackEntry?>, nav: (Route, Boolean) -> Unit) { fun AppBottomBar(accountViewModel: AccountViewModel, navEntryState: State<NavBackStackEntry?>, nav: (Route, Boolean) -> Unit) {
val isKeyboardOpen by keyboardAsState() val isKeyboardOpen by keyboardAsState()
if (isKeyboardOpen == Keyboard.Closed) { if (isKeyboardOpen == Keyboard.Closed) {
RenderBottomMenu(accountViewModel, navEntryState, nav)
}
}
@Composable
private fun RenderBottomMenu(
accountViewModel: AccountViewModel,
navEntryState: State<NavBackStackEntry?>,
nav: (Route, Boolean) -> Unit
) {
Column() { Column() {
Divider( Divider(
thickness = 0.25.dp thickness = 0.25.dp
@@ -101,7 +116,6 @@ fun AppBottomBar(accountViewModel: AccountViewModel, navEntryState: State<NavBac
} }
} }
} }
}
} }
@Composable @Composable
@@ -180,6 +194,18 @@ private fun RowScope.BottomIcon(
} }
} }
NavigationIcon(icon, size, iconSize, selected, hasNewItems, onClick)
}
@Composable
private fun RowScope.NavigationIcon(
icon: Int,
size: Dp,
iconSize: Dp,
selected: Boolean,
hasNewItems: Boolean,
onClick: (Boolean) -> Unit
) {
BottomNavigationItem( BottomNavigationItem(
icon = { icon = {
NotifiableIcon( NotifiableIcon(