Skip to content

Commit a19a6cd

Browse files
committed
Fix LoginView nav bar when button is not shown.
1 parent 0d6bb0e commit a19a6cd

1 file changed

Lines changed: 37 additions & 22 deletions

File tree

  • libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/components

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/components/LoginView.kt

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,16 @@ import androidx.compose.foundation.layout.Arrangement
4141
import androidx.compose.foundation.layout.Box
4242
import androidx.compose.foundation.layout.PaddingValues
4343
import androidx.compose.foundation.layout.Row
44+
import androidx.compose.foundation.layout.WindowInsets
45+
import androidx.compose.foundation.layout.defaultMinSize
4446
import androidx.compose.foundation.layout.fillMaxSize
4547
import androidx.compose.foundation.layout.fillMaxWidth
4648
import androidx.compose.foundation.layout.height
49+
import androidx.compose.foundation.layout.navigationBars
50+
import androidx.compose.foundation.layout.navigationBarsPadding
4751
import androidx.compose.foundation.layout.padding
4852
import androidx.compose.foundation.layout.size
53+
import androidx.compose.foundation.layout.statusBarsPadding
4954
import androidx.compose.foundation.shape.RoundedCornerShape
5055
import androidx.compose.material.icons.Icons
5156
import androidx.compose.material.icons.automirrored.filled.ArrowBack
@@ -87,13 +92,15 @@ import androidx.compose.ui.draw.shadow
8792
import androidx.compose.ui.graphics.Color
8893
import androidx.compose.ui.graphics.graphicsLayer
8994
import androidx.compose.ui.platform.LocalContext
95+
import androidx.compose.ui.platform.LocalDensity
9096
import androidx.compose.ui.platform.LocalInspectionMode
9197
import androidx.compose.ui.res.stringResource
9298
import androidx.compose.ui.semantics.contentDescription
9399
import androidx.compose.ui.semantics.semantics
94100
import androidx.compose.ui.text.font.FontWeight
95101
import androidx.compose.ui.text.style.TextOverflow
96102
import androidx.compose.ui.tooling.preview.Preview
103+
import androidx.compose.ui.unit.Dp
97104
import androidx.compose.ui.unit.DpSize
98105
import androidx.compose.ui.unit.dp
99106
import androidx.compose.ui.unit.sp
@@ -174,16 +181,14 @@ fun LoginView() {
174181
}
175182

176183
val bottomAppBarButton = bioAuthButton ?: idpButton ?: customButton
177-
val bottomAppBar = viewModel.bottomAppBar ?: bottomAppBarButton?.let { button ->
178-
{
179-
DefaultBottomAppBar(
180-
backgroundColor = viewModel.dynamicBackgroundColor,
181-
button = button,
182-
loading = viewModel.loading.value,
183-
showButton = !viewModel.authFinished.value
184-
)
185-
}
186-
} ?: {}
184+
val bottomAppBar = viewModel.bottomAppBar ?: {
185+
DefaultBottomAppBar(
186+
backgroundColor = viewModel.dynamicBackgroundColor,
187+
button = bottomAppBarButton,
188+
loading = viewModel.loading.value,
189+
showButton = !viewModel.authFinished.value
190+
)
191+
}
187192

188193
LoginView(
189194
loginUrlData = viewModel.loginUrl,
@@ -368,21 +373,28 @@ internal fun DefaultBottomAppBar(
368373
targetValue = if (loading) LOADING_ALPHA else VISIBLE_ALPHA,
369374
animationSpec = tween(durationMillis = SLOW_ANIMATION_MS),
370375
)
376+
val heightModifier = if (button == null) {
377+
Modifier.height(WindowInsets.navigationBars.getBottom(LocalDensity.current).pxToDp())
378+
} else {
379+
Modifier.defaultMinSize()
380+
}
371381

372-
AnimatedVisibility(
373-
visible = showButton,
374-
enter = fadeIn(animationSpec = tween(durationMillis = SLOW_ANIMATION_MS)),
375-
exit = fadeOut(animationSpec = tween(durationMillis = SLOW_ANIMATION_MS)),
382+
BottomAppBar(
383+
containerColor = backgroundColor.value,
384+
contentPadding = PaddingValues(0.dp),
385+
modifier = heightModifier.graphicsLayer(alpha = alpha),
386+
windowInsets = WindowInsets.navigationBars,
376387
) {
377-
BottomAppBar(
378-
containerColor = backgroundColor.value,
379-
modifier = Modifier.graphicsLayer(alpha = alpha)
388+
AnimatedVisibility(
389+
visible = showButton && (button != null),
390+
enter = fadeIn(animationSpec = tween(durationMillis = SLOW_ANIMATION_MS)),
391+
exit = fadeOut(animationSpec = tween(durationMillis = SLOW_ANIMATION_MS)),
380392
) {
381-
Row(
382-
modifier = Modifier.fillMaxWidth(),
383-
horizontalArrangement = Arrangement.Center,
384-
) {
385-
if (button != null) {
393+
if (button != null) {
394+
Row(
395+
modifier = Modifier.fillMaxWidth(),
396+
horizontalArrangement = Arrangement.Center,
397+
) {
386398
val buttonShape = RoundedCornerShape(CORNER_RADIUS.dp)
387399
CompositionLocalProvider(
388400
LocalRippleConfiguration provides RippleConfiguration(color = colorScheme.onSecondary)
@@ -442,6 +454,9 @@ internal fun ToolTipWrapper(contentDescription: Int, content: @Composable (descr
442454
}
443455
}
444456

457+
@Composable
458+
internal fun Int.pxToDp() = with(LocalDensity.current) { this@pxToDp.toDp() }
459+
445460
// Get access to host activity from within Compose. tail rec makes this safe.
446461
private tailrec fun Context.getActivity(): FragmentActivity? = when (this) {
447462
is FragmentActivity -> this

0 commit comments

Comments
 (0)