Skip to content

Commit

Permalink
fix: [ANDROAPP-6083] Adds device's navigation bars padding to bottom …
Browse files Browse the repository at this point in the history
…sheet (#235)
  • Loading branch information
ferdyrod authored Apr 30, 2024
1 parent e9b76f0 commit 50ceab6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.hisp.dhis.mobile.ui.designsystem.component.internal.bottomSheet

import android.annotation.SuppressLint
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext

// TODO - hack to get navigation bar padding does not take into account IME padding (reflection)
// TODO - Should be remove when google publish https://issuetracker.google.com/issues/274872542
@Composable
@SuppressLint("DiscouragedApi")
actual fun rememberDimensionByName(name: String): Int {
val resources = LocalContext.current.resources
return remember {
val id = resources.getIdentifier(name, "dimen", "android")
if (id == 0) 0 else resources.getDimensionPixelSize(id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import androidx.compose.foundation.gestures.ScrollableState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredHeight
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
Expand All @@ -34,6 +35,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import org.hisp.dhis.mobile.ui.designsystem.component.internal.bottomSheet.rememberDimensionByName
import org.hisp.dhis.mobile.ui.designsystem.theme.InternalSizeValues
import org.hisp.dhis.mobile.ui.designsystem.theme.Shape
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing
Expand Down Expand Up @@ -159,6 +161,10 @@ fun BottomSheetShell(
) {
val sheetState = rememberModalBottomSheetState(true)
val scope = rememberCoroutineScope()
// TODO - hack to get navigation bar padding does not take into account IME padding (reflection)
// TODO - Should be remove when google publish https://issuetracker.google.com/issues/274872542
val topInsets = WindowInsets(top = rememberDimensionByName("status_bar_height"))
val bottomInsets = WindowInsets(bottom = rememberDimensionByName("navigation_bar_height"))

ModalBottomSheet(
modifier = modifier,
Expand Down Expand Up @@ -188,11 +194,13 @@ fun BottomSheetShell(
}
}
},
windowInsets = topInsets,
) {
val canScrollForward by derivedStateOf { contentScrollState.canScrollForward }

Column(
modifier = Modifier.systemBarsPadding(),
modifier = Modifier
.padding(bottomInsets.asPaddingValues()),
) {
Column(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.hisp.dhis.mobile.ui.designsystem.component.internal.bottomSheet

import androidx.compose.runtime.Composable

// TODO - hack to get navigation bar padding does not take into account IME padding (reflection)
// TODO - Should be remove when google publish https://issuetracker.google.com/issues/274872542

@Composable
expect fun rememberDimensionByName(name: String): Int
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.hisp.dhis.mobile.ui.designsystem.component.internal.bottomSheet

import androidx.compose.runtime.Composable

// TODO - hack to get navigation bar padding does not take into account IME padding
// TODO - Should be remove when google published https://issuetracker.google.com/issues/274872542
@Composable
actual fun rememberDimensionByName(name: String) = 0

0 comments on commit 50ceab6

Please sign in to comment.