|
| 1 | +package com.firebaseui.android.demo.auth.fullcustomization.common |
| 2 | + |
| 3 | +import androidx.annotation.DrawableRes |
| 4 | +import androidx.compose.foundation.Image |
| 5 | +import androidx.compose.foundation.layout.Arrangement |
| 6 | +import androidx.compose.foundation.layout.Box |
| 7 | +import androidx.compose.foundation.layout.BoxWithConstraints |
| 8 | +import androidx.compose.foundation.layout.Column |
| 9 | +import androidx.compose.foundation.layout.ColumnScope |
| 10 | +import androidx.compose.foundation.layout.Spacer |
| 11 | +import androidx.compose.foundation.layout.fillMaxSize |
| 12 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 13 | +import androidx.compose.foundation.layout.height |
| 14 | +import androidx.compose.foundation.layout.heightIn |
| 15 | +import androidx.compose.foundation.layout.padding |
| 16 | +import androidx.compose.foundation.layout.safeDrawingPadding |
| 17 | +import androidx.compose.foundation.layout.size |
| 18 | +import androidx.compose.foundation.rememberScrollState |
| 19 | +import androidx.compose.foundation.verticalScroll |
| 20 | +import androidx.compose.material3.MaterialTheme |
| 21 | +import androidx.compose.material3.Surface |
| 22 | +import androidx.compose.material3.Text |
| 23 | +import androidx.compose.runtime.Composable |
| 24 | +import androidx.compose.ui.Modifier |
| 25 | +import androidx.compose.ui.layout.ContentScale |
| 26 | +import androidx.compose.ui.res.painterResource |
| 27 | +import androidx.compose.ui.semantics.contentDescription |
| 28 | +import androidx.compose.ui.semantics.semantics |
| 29 | +import androidx.compose.ui.unit.dp |
| 30 | +import com.firebaseui.android.demo.R |
| 31 | + |
| 32 | +/** |
| 33 | + * The page frame shared by the MFA and reauthentication screens: mascot, headline, a single |
| 34 | + * elevated card, and bottom-anchored actions. |
| 35 | + * |
| 36 | + * The email and phone steps predate this and inline the same structure themselves. |
| 37 | + * |
| 38 | + * verticalScroll measures content with infinite max height, and Column distributes weights |
| 39 | + * against the MIN height when max is infinite (RowColumnMeasurePolicy.kt) — so |
| 40 | + * heightIn(min = viewport) makes the weighted spacers expand (centering content, anchoring the |
| 41 | + * actions to the bottom) when everything fits, and collapse to zero (plain scrolling) when it |
| 42 | + * doesn't. |
| 43 | + */ |
| 44 | +@Composable |
| 45 | +fun AuthPage( |
| 46 | + @DrawableRes mascot: Int, |
| 47 | + mascotDescription: String, |
| 48 | + title: String, |
| 49 | + cardContentDescription: String, |
| 50 | + actions: @Composable ColumnScope.() -> Unit, |
| 51 | + card: @Composable ColumnScope.() -> Unit, |
| 52 | +) { |
| 53 | + Box(modifier = Modifier.fillMaxSize()) { |
| 54 | + // Full-bleed, and deliberately outside the safeDrawingPadding below so it runs edge to |
| 55 | + // edge under the system bars — same as MainUI and PhoneSignInUI do for their slots. |
| 56 | + Image( |
| 57 | + painter = painterResource(id = R.drawable.custom_background), |
| 58 | + contentDescription = null, |
| 59 | + contentScale = ContentScale.Crop, |
| 60 | + modifier = Modifier.fillMaxSize(), |
| 61 | + ) |
| 62 | + |
| 63 | + BoxWithConstraints( |
| 64 | + modifier = Modifier |
| 65 | + .fillMaxSize() |
| 66 | + .safeDrawingPadding(), |
| 67 | + ) { |
| 68 | + Column( |
| 69 | + modifier = Modifier |
| 70 | + .fillMaxWidth() |
| 71 | + .verticalScroll(rememberScrollState()) |
| 72 | + .heightIn(min = maxHeight) |
| 73 | + .padding(horizontal = 40.dp, vertical = 24.dp), |
| 74 | + ) { |
| 75 | + Spacer(modifier = Modifier.weight(1f)) |
| 76 | + |
| 77 | + Column(modifier = Modifier.fillMaxWidth()) { |
| 78 | + Image( |
| 79 | + painter = painterResource(id = mascot), |
| 80 | + contentDescription = mascotDescription, |
| 81 | + modifier = Modifier.size(72.dp), |
| 82 | + ) |
| 83 | + Spacer(modifier = Modifier.height(8.dp)) |
| 84 | + Text( |
| 85 | + text = title, |
| 86 | + style = MaterialTheme.typography.headlineSmall, |
| 87 | + color = MaterialTheme.colorScheme.primary, |
| 88 | + ) |
| 89 | + Spacer(modifier = Modifier.height(24.dp)) |
| 90 | + |
| 91 | + HardOffsetShadow(shape = AuthFieldShape, modifier = Modifier.fillMaxWidth()) { |
| 92 | + Surface( |
| 93 | + modifier = Modifier |
| 94 | + .fillMaxWidth() |
| 95 | + .semantics { contentDescription = cardContentDescription }, |
| 96 | + color = MaterialTheme.colorScheme.surface, |
| 97 | + shape = AuthFieldShape, |
| 98 | + ) { |
| 99 | + Column( |
| 100 | + modifier = Modifier.padding(16.dp), |
| 101 | + verticalArrangement = Arrangement.spacedBy(16.dp), |
| 102 | + content = card, |
| 103 | + ) |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + Spacer(modifier = Modifier.weight(1f)) |
| 109 | + Spacer(modifier = Modifier.height(24.dp)) |
| 110 | + |
| 111 | + Column(modifier = Modifier.fillMaxWidth(), content = actions) |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | +} |
0 commit comments