Skip to content

Commit ebdd7a9

Browse files
authored
Merge pull request #2685 from brandonpage/login-nav-bar
Fix LoginView nav bar when button is not shown.
2 parents 0d6bb0e + c1cf132 commit ebdd7a9

1 file changed

Lines changed: 33 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: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ 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
4750
import androidx.compose.foundation.layout.padding
4851
import androidx.compose.foundation.layout.size
4952
import androidx.compose.foundation.shape.RoundedCornerShape
@@ -87,6 +90,7 @@ import androidx.compose.ui.draw.shadow
8790
import androidx.compose.ui.graphics.Color
8891
import androidx.compose.ui.graphics.graphicsLayer
8992
import androidx.compose.ui.platform.LocalContext
93+
import androidx.compose.ui.platform.LocalDensity
9094
import androidx.compose.ui.platform.LocalInspectionMode
9195
import androidx.compose.ui.res.stringResource
9296
import androidx.compose.ui.semantics.contentDescription
@@ -174,16 +178,14 @@ fun LoginView() {
174178
}
175179

176180
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-
} ?: {}
181+
val bottomAppBar = viewModel.bottomAppBar ?: {
182+
DefaultBottomAppBar(
183+
backgroundColor = viewModel.dynamicBackgroundColor,
184+
button = bottomAppBarButton,
185+
loading = viewModel.loading.value,
186+
showButton = !viewModel.authFinished.value
187+
)
188+
}
187189

188190
LoginView(
189191
loginUrlData = viewModel.loginUrl,
@@ -368,21 +370,27 @@ internal fun DefaultBottomAppBar(
368370
targetValue = if (loading) LOADING_ALPHA else VISIBLE_ALPHA,
369371
animationSpec = tween(durationMillis = SLOW_ANIMATION_MS),
370372
)
373+
val heightModifier = if (button == null || !showButton) {
374+
Modifier.height(WindowInsets.navigationBars.getBottom(LocalDensity.current).pxToDp())
375+
} else {
376+
Modifier.defaultMinSize()
377+
}
371378

372-
AnimatedVisibility(
373-
visible = showButton,
374-
enter = fadeIn(animationSpec = tween(durationMillis = SLOW_ANIMATION_MS)),
375-
exit = fadeOut(animationSpec = tween(durationMillis = SLOW_ANIMATION_MS)),
379+
BottomAppBar(
380+
containerColor = backgroundColor.value,
381+
contentPadding = PaddingValues(0.dp),
382+
modifier = heightModifier.graphicsLayer(alpha = alpha),
376383
) {
377-
BottomAppBar(
378-
containerColor = backgroundColor.value,
379-
modifier = Modifier.graphicsLayer(alpha = alpha)
384+
AnimatedVisibility(
385+
visible = showButton,
386+
enter = fadeIn(animationSpec = tween(durationMillis = SLOW_ANIMATION_MS)),
387+
exit = fadeOut(animationSpec = tween(durationMillis = SLOW_ANIMATION_MS)),
380388
) {
381-
Row(
382-
modifier = Modifier.fillMaxWidth(),
383-
horizontalArrangement = Arrangement.Center,
384-
) {
385-
if (button != null) {
389+
if (button != null) {
390+
Row(
391+
modifier = Modifier.fillMaxWidth(),
392+
horizontalArrangement = Arrangement.Center,
393+
) {
386394
val buttonShape = RoundedCornerShape(CORNER_RADIUS.dp)
387395
CompositionLocalProvider(
388396
LocalRippleConfiguration provides RippleConfiguration(color = colorScheme.onSecondary)
@@ -442,6 +450,9 @@ internal fun ToolTipWrapper(contentDescription: Int, content: @Composable (descr
442450
}
443451
}
444452

453+
@Composable
454+
internal fun Int.pxToDp() = with(LocalDensity.current) { this@pxToDp.toDp() }
455+
445456
// Get access to host activity from within Compose. tail rec makes this safe.
446457
private tailrec fun Context.getActivity(): FragmentActivity? = when (this) {
447458
is FragmentActivity -> this

0 commit comments

Comments
 (0)