Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add account controls and collapsible pages

Neeraj Gupta877736c8c1da
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/ActionButton.kt b/android/packages/components/src/main/kotlin/io/ente/components/ActionButton.kt
index dffda77ce8..cdd2015742 100644
--- a/android/packages/components/src/main/kotlin/io/ente/components/ActionButton.kt
+++ b/android/packages/components/src/main/kotlin/io/ente/components/ActionButton.kt
@@ -5,12 +5,13 @@ import androidx.compose.animation.core.tween
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@@ -18,9 +19,13 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.semantics.clearAndSetSemantics
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
@@ -53,14 +58,15 @@ public fun ActionButton(
size: ActionSize = ActionSize.Large,
density: ActionDensity = ActionDensity.Regular,
enabled: Boolean = true,
+ loading: Boolean = false,
) {
val palette = LocalEntePalette.current
val interactionSource = remember { MutableInteractionSource() }
val pressed by interactionSource.collectIsPressedAsState()
- val colors = actionColors(variant, palette, enabled, pressed)
+ val colors = actionColors(variant, palette, enabled, pressed && !loading)
val scale by
animateFloatAsState(
- targetValue = if (pressed && enabled) 0.98f else 1f,
+ targetValue = if (pressed && enabled && !loading) 0.98f else 1f,
animationSpec = tween(EnteMotion.quick),
label = "actionScale",
)
@@ -73,19 +79,20 @@ public fun ActionButton(
shape = RoundedCornerShape(if (inlineLink) 0.dp else EnteRadius.button),
modifier =
actionModifier
+ .semantics { contentDescription = label }
.graphicsLayer {
scaleX = scale
scaleY = scale
}
.clickable(
- enabled = enabled,
+ enabled = enabled && !loading,
role = Role.Button,
interactionSource = interactionSource,
indication = null,
onClick = onClick,
),
) {
- Row(
+ Box(
modifier =
Modifier.padding(
horizontal = if (inlineLink) 0.dp else EnteSpacing.xl,
@@ -99,11 +106,11 @@ public fun ActionButton(
},
)
.heightIn(min = if (inlineLink) 0.dp else 24.dp),
- horizontalArrangement = Arrangement.Center,
- verticalAlignment = Alignment.CenterVertically,
+ contentAlignment = Alignment.Center,
) {
Text(
text = label,
+ modifier = Modifier.alpha(if (loading) 0f else 1f).clearAndSetSemantics {},
maxLines = 2,
overflow = TextOverflow.Ellipsis,
style =
@@ -119,6 +126,13 @@ public fun ActionButton(
null
},
)
+ if (loading) {
+ CircularProgressIndicator(
+ modifier = Modifier.size(20.dp).clearAndSetSemantics {},
+ color = colors.foreground,
+ strokeWidth = 2.dp,
+ )
+ }
}
}
}
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/Avatar.kt b/android/packages/components/src/main/kotlin/io/ente/components/Avatar.kt
index dcc1fafe4c..d461fbb725 100644
--- a/android/packages/components/src/main/kotlin/io/ente/components/Avatar.kt
+++ b/android/packages/components/src/main/kotlin/io/ente/components/Avatar.kt
@@ -1,6 +1,7 @@
package io.ente.components
import android.icu.text.BreakIterator
+import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
@@ -13,6 +14,12 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.painter.Painter
+import androidx.compose.ui.layout.ContentScale
+import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.semantics.clearAndSetSemantics
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.role
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -24,10 +31,10 @@ public fun Avatar(
modifier: Modifier = Modifier,
identity: String = name,
size: AvatarSize = AvatarSize.Regular,
+ painter: Painter? = null,
) {
val palette = LocalEntePalette.current
val colorIndex = remember(identity) { avatarIndex(identity) }
- val initials = remember(name) { avatarInitials(name) }
val color = avatarColors(palette)[colorIndex]
Box(
modifier =
@@ -35,10 +42,19 @@ public fun Avatar(
.size(size.dimension)
.clip(CircleShape)
.background(color)
- .border(size.border, palette.background, CircleShape),
+ .border(size.border, palette.background, CircleShape)
+ .clearAndSetSemantics {
+ contentDescription = name
+ role = Role.Image
+ },
contentAlignment = Alignment.Center,
) {
- Text(initials, style = size.textStyle, color = Color.White)
+ if (painter == null) {
+ val initials = remember(name) { avatarInitials(name) }
+ Text(initials, style = size.textStyle, color = Color.White)
+ } else {
+ Image(painter, null, Modifier.matchParentSize(), contentScale = ContentScale.Crop)
+ }
}
}
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/CollapsingPage.kt b/android/packages/components/src/main/kotlin/io/ente/components/CollapsingPage.kt
new file mode 100644
index 0000000000..379d7af125
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/CollapsingPage.kt
@@ -0,0 +1,255 @@
+package io.ente.components
+
+import androidx.compose.animation.core.CubicBezierEasing
+import androidx.compose.animation.core.animate
+import androidx.compose.animation.core.tween
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.RowScope
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.offset
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.LazyListScope
+import androidx.compose.material3.Icon
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableFloatStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.alpha
+import androidx.compose.ui.draw.clipToBounds
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
+import androidx.compose.ui.input.nestedscroll.NestedScrollSource
+import androidx.compose.ui.input.nestedscroll.nestedScroll
+import androidx.compose.ui.layout.Layout
+import androidx.compose.ui.platform.LocalDensity
+import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.semantics.clearAndSetSemantics
+import androidx.compose.ui.semantics.heading
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.Constraints
+import androidx.compose.ui.unit.Velocity
+import androidx.compose.ui.unit.constrainHeight
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import kotlin.math.roundToInt
+
+@Composable
+public fun CollapsingPage(
+ title: String,
+ backLabel: String,
+ back: () -> Unit,
+ modifier: Modifier = Modifier,
+ identifier: String? = null,
+ eyebrow: String? = null,
+ subtitle: String? = null,
+ actions: @Composable RowScope.() -> Unit = {},
+ content: LazyListScope.() -> Unit,
+) {
+ val palette = LocalEntePalette.current
+ val density = LocalDensity.current
+ val titleHeight = with(density) { (32 + if (eyebrow == null) 0 else 30).sp.toDp() }
+ val collapsedTitleHeight = with(density) { 24.sp.toDp() }
+ val subtitleHeight = with(density) { 16.sp.toDp() }
+ val toolbarHeight = maxOf(56.dp, collapsedTitleHeight)
+ val expandedHeight =
+ maxOf(
+ if (subtitle == null) 92.dp else 110.dp,
+ 48.dp +
+ titleHeight +
+ (if (subtitle == null) 0.dp else 2.dp + subtitleHeight * 2) +
+ 16.dp,
+ )
+ val contentTop =
+ 48.dp +
+ if (subtitle == null) 0.dp
+ else minOf(subtitleHeight, maxOf(0.dp, toolbarHeight - titleHeight))
+ val expansion = expandedHeight - toolbarHeight
+ val extent = with(density) { expansion.toPx() }
+ var offset by remember { mutableFloatStateOf(0f) }
+ val scroll =
+ remember(extent) {
+ object : NestedScrollConnection {
+ fun consume(delta: Float): Offset {
+ val previous = offset
+ offset = (offset - delta).coerceIn(0f, extent)
+ return Offset(0f, previous - offset)
+ }
+
+ override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset =
+ if (available.y < 0) consume(available.y) else Offset.Zero
+
+ override fun onPostScroll(
+ consumed: Offset,
+ available: Offset,
+ source: NestedScrollSource,
+ ): Offset = if (available.y > 0) consume(available.y) else Offset.Zero
+
+ override suspend fun onPostFling(
+ consumed: Velocity,
+ available: Velocity,
+ ): Velocity {
+ if (offset > 1f && offset < extent) {
+ animate(
+ offset,
+ extent,
+ animationSpec = tween(160, easing = HeaderEaseOut),
+ ) { value, _ ->
+ offset = value
+ }
+ }
+ return Velocity.Zero
+ }
+ }
+ }
+ val progress = (offset / extent).coerceIn(0f, 1f)
+ val eased = HeaderEaseInOut.transform(progress)
+ val titleTop = contentTop + ((toolbarHeight - collapsedTitleHeight) / 2 - contentTop) * eased
+ Column(modifier.fillMaxSize().background(palette.background).nestedScroll(scroll)) {
+ Box(Modifier.fillMaxWidth().height(expandedHeight - expansion * progress).clipToBounds()) {
+ IconAction(
+ onClick = back,
+ modifier =
+ Modifier.align(Alignment.TopStart)
+ .height(toolbarHeight)
+ .padding(start = 4.dp)
+ .then(identifier?.let { Modifier.testTag("$it.back") } ?: Modifier),
+ kind = IconActionKind.Unfilled,
+ size = 48.dp,
+ ) {
+ Icon(painterResource(R.drawable.component_back), backLabel, Modifier.size(24.dp))
+ }
+ Row(
+ Modifier.fillMaxWidth()
+ .offset(y = titleTop)
+ .height(titleHeight + (collapsedTitleHeight - titleHeight) * eased)
+ .padding(start = EnteSpacing.lg + 36.dp * eased, end = EnteSpacing.lg),
+ verticalAlignment = Alignment.Top,
+ horizontalArrangement = Arrangement.spacedBy(EnteSpacing.sm),
+ ) {
+ HeaderTitle(
+ title,
+ eyebrow,
+ eased,
+ Modifier.weight(1f)
+ .semantics(mergeDescendants = true) { heading() }
+ .then(identifier?.let { Modifier.testTag("$it.title") } ?: Modifier),
+ )
+ actions()
+ }
+ if (subtitle != null && progress < 1f) {
+ Text(
+ subtitle,
+ Modifier.offset(y = contentTop + titleHeight + 2.dp)
+ .padding(start = EnteSpacing.lg + 36.dp * eased, end = EnteSpacing.lg)
+ .alpha(1 - eased)
+ .then(
+ if (progress >= 0.99f) Modifier.clearAndSetSemantics {} else Modifier
+ ),
+ style = EnteTypography.mini,
+ color = palette.mutedText,
+ maxLines = 2,
+ overflow = TextOverflow.Ellipsis,
+ )
+ }
+ }
+ LazyColumn(
+ modifier =
+ Modifier.weight(1f)
+ .then(identifier?.let { Modifier.testTag("$it.scroll") } ?: Modifier),
+ contentPadding =
+ PaddingValues(
+ start = EnteSpacing.lg,
+ end = EnteSpacing.lg,
+ bottom = EnteSpacing.lg,
+ ),
+ content = content,
+ )
+ }
+}
+
+@Composable
+private fun HeaderTitle(title: String, eyebrow: String?, progress: Float, modifier: Modifier) {
+ val palette = LocalEntePalette.current
+ val titleStyle =
+ EnteTypography.display2.copy(
+ fontSize = (24 - 4 * progress).sp,
+ lineHeight = (32 - 8 * progress).sp,
+ )
+ if (eyebrow == null) {
+ Text(
+ title,
+ modifier,
+ style = titleStyle,
+ color = palette.text,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
+ } else {
+ val eyebrowHeight = with(LocalDensity.current) { 30.sp.toPx() }
+ Layout(
+ content = {
+ Text(
+ eyebrow,
+ style =
+ EnteTypography.display2.copy(
+ fontSize = (16 + 4 * progress).sp,
+ lineHeight = (30 - 6 * progress).sp,
+ ),
+ color = palette.mutedText,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
+ Text(
+ title,
+ style = titleStyle,
+ color = palette.text,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
+ },
+ modifier = modifier,
+ ) { children, constraints ->
+ val width = constraints.maxWidth
+ val prefixWidth =
+ (children[0].maxIntrinsicWidth(Constraints.Infinity) + 6.dp.roundToPx())
+ .coerceAtMost((width - 24.dp.roundToPx()).coerceAtLeast(0))
+ val horizontal = HeaderEaseOut.transform(progress)
+ val titleX = (prefixWidth * horizontal).roundToInt()
+ val titleY = (eyebrowHeight * (1 - HeaderEaseIn.transform(progress))).roundToInt()
+ val prefix =
+ children[0].measure(
+ Constraints(
+ maxWidth =
+ (width +
+ ((prefixWidth - 6.dp.roundToPx()).coerceAtLeast(0) - width) *
+ horizontal)
+ .roundToInt()
+ )
+ )
+ val label = children[1].measure(Constraints(maxWidth = width - titleX))
+ layout(width, constraints.constrainHeight(label.height + titleY)) {
+ prefix.placeRelative(0, 0)
+ label.placeRelative(titleX, titleY)
+ }
+ }
+ }
+}
+
+private val HeaderEaseInOut = CubicBezierEasing(0.42f, 0f, 0.58f, 1f)
+private val HeaderEaseOut = CubicBezierEasing(0f, 0f, 0.58f, 1f)
+private val HeaderEaseIn = CubicBezierEasing(0.42f, 0f, 1f, 1f)
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/InputField.kt b/android/packages/components/src/main/kotlin/io/ente/components/InputField.kt
index 0cff7b98c1..3f8af81aaa 100644
--- a/android/packages/components/src/main/kotlin/io/ente/components/InputField.kt
+++ b/android/packages/components/src/main/kotlin/io/ente/components/InputField.kt
@@ -109,7 +109,10 @@ public fun InputField(
.clip(shape)
.background(if (enabled) palette.surface else palette.fill)
.border(1.dp, border, shape)
- .padding(EnteSpacing.lg),
+ .padding(
+ horizontal = EnteSpacing.lg,
+ vertical = if (singleLine) 0.dp else EnteSpacing.lg,
+ ),
verticalAlignment =
if (singleLine) Alignment.CenterVertically else Alignment.Top,
) {
@@ -117,7 +120,10 @@ public fun InputField(
it()
Spacer(Modifier.width(EnteSpacing.sm))
}
- Box(Modifier.weight(1f)) {
+ Box(
+ Modifier.weight(1f)
+ .padding(vertical = if (singleLine) EnteSpacing.lg else 0.dp)
+ ) {
if (value.isEmpty() && placeholder != null) {
Text(placeholder, style = EnteTypography.body, color = hintColor)
}
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/MenuRow.kt b/android/packages/components/src/main/kotlin/io/ente/components/MenuRow.kt
index 7ebdd747ca..cfeb474687 100644
--- a/android/packages/components/src/main/kotlin/io/ente/components/MenuRow.kt
+++ b/android/packages/components/src/main/kotlin/io/ente/components/MenuRow.kt
@@ -28,6 +28,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextOverflow
@@ -79,7 +80,12 @@ public fun MenuRow(
) {
leading?.let {
CompositionLocalProvider(LocalContentColor provides palette.mutedText) {
- Box(Modifier.size(36.dp), contentAlignment = Alignment.Center) { it() }
+ Box(
+ Modifier.size(36.dp).clearAndSetSemantics {},
+ contentAlignment = Alignment.Center,
+ ) {
+ it()
+ }
}
}
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(EnteSpacing.xs)) {
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/Theme.kt b/android/packages/components/src/main/kotlin/io/ente/components/Theme.kt
index c6983c2390..4ecc8718f3 100644
--- a/android/packages/components/src/main/kotlin/io/ente/components/Theme.kt
+++ b/android/packages/components/src/main/kotlin/io/ente/components/Theme.kt
@@ -26,6 +26,7 @@ public class Palette
internal constructor(
public val isDark: Boolean,
public val primary: Color,
+ public val primarySurface: Color,
public val primaryDark: Color,
public val primaryDarker: Color,
public val text: Color,
@@ -110,6 +111,12 @@ private fun palette(app: EnteApp, dark: Boolean): Palette {
return Palette(
isDark = dark,
primary = primary,
+ primarySurface =
+ when (app) {
+ EnteApp.Photos -> Color(if (dark) 0xFF292929 else 0xFFDDEEDF)
+ EnteApp.Auth -> Color(if (dark) 0xFF271C32 else 0xFFF4E7FC)
+ EnteApp.Locker -> Color(if (dark) 0xFF292929 else 0xFFE7EFFA)
+ },
primaryDark =
when (app) {
EnteApp.Photos -> Color(0xFF069D1E)
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/VerificationCodeField.kt b/android/packages/components/src/main/kotlin/io/ente/components/VerificationCodeField.kt
new file mode 100644
index 0000000000..d6db07f667
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/VerificationCodeField.kt
@@ -0,0 +1,162 @@
+package io.ente.components
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
+import androidx.compose.foundation.interaction.MutableInteractionSource
+import androidx.compose.foundation.interaction.collectIsFocusedAsState
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.heightIn
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.widthIn
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.foundation.text.BasicTextField
+import androidx.compose.foundation.text.KeyboardActions
+import androidx.compose.foundation.text.KeyboardOptions
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.DisposableEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberUpdatedState
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.ExperimentalComposeUiApi
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.autofill.AutofillNode
+import androidx.compose.ui.autofill.AutofillType
+import androidx.compose.ui.draw.alpha
+import androidx.compose.ui.focus.onFocusChanged
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.SolidColor
+import androidx.compose.ui.layout.boundsInWindow
+import androidx.compose.ui.layout.onGloballyPositioned
+import androidx.compose.ui.platform.LocalAutofill
+import androidx.compose.ui.platform.LocalAutofillTree
+import androidx.compose.ui.semantics.clearAndSetSemantics
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.error
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.text.input.KeyboardType
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+
+@OptIn(ExperimentalComposeUiApi::class)
+@Composable
+public fun VerificationCodeField(
+ label: String,
+ value: String,
+ onValueChange: (String) -> Unit,
+ modifier: Modifier = Modifier,
+ error: String? = null,
+ enabled: Boolean = true,
+ keyboardActions: KeyboardActions = KeyboardActions.Default,
+) {
+ val palette = LocalEntePalette.current
+ val interactionSource = remember { MutableInteractionSource() }
+ val focused by interactionSource.collectIsFocusedAsState()
+ val canAutofill by rememberUpdatedState(enabled)
+ val update by
+ rememberUpdatedState<(String) -> Unit>({ input ->
+ onValueChange(input.filter { it in '0'..'9' }.take(6))
+ })
+ val autofill = LocalAutofill.current
+ val autofillTree = LocalAutofillTree.current
+ val autofillNode = remember {
+ AutofillNode(
+ autofillTypes = listOf(AutofillType.SmsOtpCode),
+ onFill = { if (canAutofill) update(it) },
+ )
+ }
+ DisposableEffect(autofillTree, autofillNode) {
+ autofillTree += autofillNode
+ onDispose {
+ autofill?.cancelAutofillForNode(autofillNode)
+ autofillTree.children.remove(autofillNode.id)
+ }
+ }
+ Column(modifier, verticalArrangement = Arrangement.spacedBy(EnteSpacing.sm)) {
+ BasicTextField(
+ value = value,
+ onValueChange = update,
+ enabled = enabled,
+ singleLine = true,
+ keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),
+ keyboardActions = keyboardActions,
+ interactionSource = interactionSource,
+ cursorBrush = SolidColor(Color.Transparent),
+ modifier =
+ Modifier.widthIn(max = 324.dp)
+ .fillMaxWidth()
+ .onGloballyPositioned { autofillNode.boundingBox = it.boundsInWindow() }
+ .onFocusChanged {
+ if (it.isFocused) autofill?.requestAutofillForNode(autofillNode)
+ else autofill?.cancelAutofillForNode(autofillNode)
+ }
+ .semantics {
+ contentDescription = label
+ if (error != null) error(error)
+ },
+ decorationBox = { input ->
+ Box {
+ Row(
+ Modifier.fillMaxWidth().clearAndSetSemantics {},
+ horizontalArrangement = Arrangement.spacedBy(6.dp),
+ ) {
+ repeat(6) { index ->
+ val filled = index < value.length
+ val active = focused && index == value.length.coerceAtMost(5)
+ val shape = RoundedCornerShape(EnteRadius.large)
+ val border =
+ when {
+ !enabled -> palette.faintBorder
+ error != null -> palette.danger
+ filled || active -> palette.primary
+ else -> palette.border
+ }
+ Box(
+ Modifier.weight(1f)
+ .heightIn(min = 52.dp)
+ .background(
+ when {
+ !enabled -> palette.fill
+ filled && error == null -> palette.primarySurface
+ else -> palette.surface
+ },
+ shape,
+ )
+ .border(
+ if (error != null || filled || active) 2.dp else 1.dp,
+ border,
+ shape,
+ ),
+ contentAlignment = Alignment.Center,
+ ) {
+ Text(
+ value.getOrNull(index)?.toString() ?: " ",
+ style =
+ EnteTypography.body.copy(
+ fontSize = 20.sp,
+ lineHeight = 26.sp,
+ fontWeight = FontWeight.Bold,
+ ),
+ color =
+ when {
+ !enabled -> palette.mutedText
+ error != null -> palette.danger
+ else -> palette.primary
+ },
+ )
+ }
+ }
+ }
+ Box(Modifier.size(1.dp).alpha(0f)) { input() }
+ }
+ },
+ )
+ if (error != null) Text(error, style = EnteTypography.mini, color = palette.danger)
+ }
+}
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/settings/SettingsPage.kt b/android/packages/components/src/main/kotlin/io/ente/components/settings/SettingsPage.kt
new file mode 100644
index 0000000000..a0df624004
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/settings/SettingsPage.kt
@@ -0,0 +1,26 @@
+package io.ente.components.settings
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.ColumnScope
+import androidx.compose.foundation.layout.safeDrawingPadding
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import io.ente.components.CollapsingPage
+import io.ente.components.EnteSpacing
+
+@Composable
+public fun SettingsPage(
+ title: String,
+ backLabel: String,
+ back: () -> Unit,
+ modifier: Modifier = Modifier,
+ identifier: String? = null,
+ content: @Composable ColumnScope.() -> Unit,
+) {
+ CollapsingPage(title, backLabel, back, modifier.safeDrawingPadding(), identifier) {
+ item {
+ Column(verticalArrangement = Arrangement.spacedBy(EnteSpacing.sm), content = content)
+ }
+ }
+}
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/settings/SettingsToggle.kt b/android/packages/components/src/main/kotlin/io/ente/components/settings/SettingsToggle.kt
new file mode 100644
index 0000000000..6d370ebf51
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/settings/SettingsToggle.kt
@@ -0,0 +1,67 @@
+package io.ente.components.settings
+
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.heightIn
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.requiredSize
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.selection.toggleable
+import androidx.compose.material3.Switch
+import androidx.compose.material3.SwitchDefaults
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.scale
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.unit.dp
+import io.ente.components.EnteSpacing
+import io.ente.components.EnteTypography
+import io.ente.components.LocalEntePalette
+import io.ente.components.MenuGroup
+
+@Composable
+public fun SettingsToggle(
+ title: String,
+ checked: Boolean,
+ onCheckedChange: (Boolean) -> Unit,
+ modifier: Modifier = Modifier,
+ enabled: Boolean = true,
+) {
+ val palette = LocalEntePalette.current
+ MenuGroup(modifier) {
+ Row(
+ Modifier.fillMaxWidth()
+ .toggleable(checked, enabled, Role.Switch, onCheckedChange)
+ .padding(horizontal = EnteSpacing.lg, vertical = EnteSpacing.sm)
+ .heightIn(min = 44.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Text(
+ title,
+ Modifier.weight(1f),
+ style = EnteTypography.body,
+ color = if (enabled) palette.text else palette.disabledText,
+ )
+ Box(Modifier.size(40.dp, 31.dp), contentAlignment = Alignment.Center) {
+ Switch(
+ checked,
+ onCheckedChange = null,
+ enabled = enabled,
+ modifier = Modifier.requiredSize(52.dp, 32.dp).scale(40f / 52f),
+ colors =
+ SwitchDefaults.colors(
+ checkedTrackColor = palette.primary,
+ checkedThumbColor = Color.White,
+ uncheckedTrackColor = palette.fill,
+ uncheckedThumbColor = palette.primary,
+ uncheckedBorderColor = palette.primary,
+ ),
+ )
+ }
+ }
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/ActionButton.swift b/apple/packages/EnteComponents/Sources/EnteComponents/ActionButton.swift
index eb3cbadc36..74ff4bac0b 100644
--- a/apple/packages/EnteComponents/Sources/EnteComponents/ActionButton.swift
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/ActionButton.swift
@@ -20,10 +20,12 @@ public enum ActionSize: Sendable {
}
public struct ActionButton: View {
+ @Environment(\.isEnabled) private var enabled
private let title: String
private let variant: ActionVariant
private let size: ActionSize
private let density: ActionDensity
+ private let loading: Bool
private let action: () -> Void
public init(
@@ -31,12 +33,14 @@ public struct ActionButton: View {
variant: ActionVariant = .primary,
size: ActionSize = .large,
density: ActionDensity = .regular,
+ loading: Bool = false,
action: @escaping () -> Void
) {
self.title = title
self.variant = variant
self.size = size
self.density = density
+ self.loading = loading
self.action = action
}
@@ -47,6 +51,13 @@ public struct ActionButton: View {
.underline(variant == .criticalText || variant == .link)
.lineLimit(2)
.font(density == .regular ? EnteTypography.bodyBold : EnteTypography.body)
+ .opacity(loading ? 0 : 1)
+ .overlay {
+ if loading {
+ ActionProgress()
+ .accessibilityHidden(true)
+ }
+ }
.frame(maxWidth: size == .large ? .infinity : nil, minHeight: inlineLink ? nil : 24)
.padding(.horizontal, inlineLink ? 0 : EnteSpacing.xl)
.padding(.vertical, inlineLink ? 4 : density == .regular ? 14 : 12)
@@ -54,16 +65,19 @@ public struct ActionButton: View {
.buttonStyle(
ActionStyle(
variant: variant,
+ enabled: enabled,
cornerRadius: inlineLink ? 0 : EnteRadius.button
)
)
+ .disabled(loading)
+ .accessibilityLabel(title)
}
}
private struct ActionStyle: ButtonStyle {
@Environment(\.entePalette) private var palette
- @Environment(\.isEnabled) private var enabled
let variant: ActionVariant
+ let enabled: Bool
let cornerRadius: CGFloat
func makeBody(configuration: Configuration) -> some View {
@@ -93,3 +107,17 @@ private struct ActionStyle: ButtonStyle {
}
}
}
+
+private struct ActionProgress: View {
+ @State private var rotating = false
+
+ var body: some View {
+ Circle()
+ .trim(from: 0.15, to: 0.85)
+ .stroke(style: StrokeStyle(lineWidth: 2, lineCap: .round))
+ .frame(width: 20, height: 20)
+ .rotationEffect(.degrees(rotating ? 360 : 0))
+ .animation(.linear(duration: 0.8).repeatForever(autoreverses: false), value: rotating)
+ .onAppear { rotating = true }
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/Avatar.swift b/apple/packages/EnteComponents/Sources/EnteComponents/Avatar.swift
index aae882beba..93c343092b 100644
--- a/apple/packages/EnteComponents/Sources/EnteComponents/Avatar.swift
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/Avatar.swift
@@ -3,25 +3,41 @@ import SwiftUI
public struct Avatar: View {
@Environment(\.entePalette) private var palette
private let name: String
+ private let image: Image?
private let identity: String
private let size: AvatarSize
- public init(_ name: String, identity: String? = nil, size: AvatarSize = .regular) {
+ public init(
+ _ name: String, image: Image? = nil, identity: String? = nil, size: AvatarSize = .regular
+ ) {
self.name = name
+ self.image = image
self.identity = identity ?? name
self.size = size
}
public var body: some View {
- Text(avatarInitials(name))
- .font(size.font)
- .foregroundStyle(Color.white)
- .frame(width: size.dimension, height: size.dimension)
- .background(colour)
- .clipShape(Circle())
- .overlay {
- Circle().stroke(palette.background, lineWidth: size.border)
+ Group {
+ if let image {
+ image.resizable().renderingMode(.original).scaledToFill()
+ } else {
+ Text(avatarInitials(name))
+ .font(size.font)
+ .foregroundStyle(Color.white)
+ .lineLimit(1)
+ .minimumScaleFactor(0.1)
}
+ }
+ .frame(width: size.dimension, height: size.dimension)
+ .background(colour)
+ .clipShape(Circle())
+ .contentShape(Circle())
+ .overlay {
+ Circle().strokeBorder(palette.background, lineWidth: size.border)
+ }
+ .accessibilityElement(children: .ignore)
+ .accessibilityLabel(name)
+ .accessibilityAddTraits(.isImage)
}
private var colour: Color {
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/CollapsingPage.swift b/apple/packages/EnteComponents/Sources/EnteComponents/CollapsingPage.swift
new file mode 100644
index 0000000000..0e567f25c9
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/CollapsingPage.swift
@@ -0,0 +1,232 @@
+import EnteFonts
+import SwiftUI
+
+public struct CollapsingPage<Actions: View, Content: View>: View {
+ @Environment(\.entePalette) private var palette
+ @State private var progress: CGFloat = 0
+ @ScaledMetric(relativeTo: .title) private var titleHeight: CGFloat = 32
+ @ScaledMetric(relativeTo: .title) private var eyebrowHeight: CGFloat = 30
+ @ScaledMetric(relativeTo: .title) private var collapsedTitleHeight: CGFloat = 24
+ @ScaledMetric(relativeTo: .caption) private var subtitleHeight: CGFloat = 16
+ private let title: String
+ private let eyebrow: String?
+ private let subtitle: String?
+ private let identifier: String?
+ private let backLabel: String
+ private let back: () -> Void
+ private let actions: Actions
+ private let content: Content
+
+ public init(
+ _ title: String,
+ eyebrow: String? = nil,
+ subtitle: String? = nil,
+ identifier: String? = nil,
+ backLabel: String,
+ back: @escaping () -> Void,
+ @ViewBuilder actions: () -> Actions = { EmptyView() },
+ @ViewBuilder content: () -> Content,
+ ) {
+ self.title = title
+ self.eyebrow = eyebrow
+ self.subtitle = subtitle
+ self.identifier = identifier
+ self.backLabel = backLabel
+ self.back = back
+ self.actions = actions()
+ self.content = content()
+ }
+
+ public var body: some View {
+ let metrics = HeaderMetrics(
+ titleHeight: titleHeight, eyebrowHeight: eyebrowHeight,
+ collapsedTitleHeight: collapsedTitleHeight, subtitleHeight: subtitleHeight,
+ hasEyebrow: eyebrow != nil, hasSubtitle: subtitle != nil)
+ GeometryReader { viewport in
+ ZStack(alignment: .top) {
+ CollapsingScrollView(
+ expansion: metrics.expansion,
+ identifier: identifier.map { "\($0).scroll" },
+ onScroll: { value in
+ if progress != value { progress = value }
+ }
+ ) {
+ VStack(alignment: .leading, spacing: 0) {
+ Color.clear.frame(height: metrics.expansion)
+ content.padding(.horizontal, EnteSpacing.lg).padding(
+ .bottom, EnteSpacing.lg)
+ }
+ .frame(
+ minHeight: max(0, viewport.size.height - metrics.toolbarHeight)
+ + metrics.expansion,
+ alignment: .top)
+ }
+ .padding(.top, metrics.toolbarHeight)
+ .ignoresSafeArea(.container, edges: .bottom)
+ CollapsingHeader(
+ progress: $progress, title: title, eyebrow: eyebrow, subtitle: subtitle,
+ identifier: identifier, backLabel: backLabel, back: back, actions: actions,
+ metrics: metrics)
+ }
+ }
+ .foregroundStyle(palette.text)
+ .background(palette.background)
+ }
+}
+
+private struct CollapsingHeader<Actions: View>: View {
+ @Environment(\.entePalette) private var palette
+ @Binding var progress: CGFloat
+ let title: String
+ let eyebrow: String?
+ let subtitle: String?
+ let identifier: String?
+ let backLabel: String
+ let back: () -> Void
+ let actions: Actions
+ let metrics: HeaderMetrics
+
+ var body: some View {
+ let eased = headerEase(progress, firstControlX: 0.42, secondControlX: 0.58)
+ let titleTop =
+ metrics.contentTop
+ + ((metrics.toolbarHeight - metrics.collapsedTitleHeight) / 2 - metrics.contentTop)
+ * eased
+ ZStack(alignment: .topLeading) {
+ IconAction(kind: .unfilled, size: 48, action: back) {
+ Glyph.back.image.resizable().scaledToFit()
+ .frame(width: 24, height: 24)
+ .flipsForRightToLeftLayoutDirection(true)
+ }
+ .frame(height: metrics.toolbarHeight)
+ .padding(.leading, 4)
+ .accessibilityLabel(backLabel)
+ .accessibilityIdentifier(identifier.map { "\($0).back" } ?? "")
+ HStack(alignment: .top, spacing: EnteSpacing.sm) {
+ titleView(progress: eased)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .frame(
+ height: metrics.expandedTitleHeight
+ + (metrics.collapsedTitleHeight - metrics.expandedTitleHeight) * eased,
+ alignment: .top
+ )
+ .accessibilityElement(children: .combine)
+ .accessibilityAddTraits(.isHeader)
+ .accessibilityIdentifier(identifier.map { "\($0).title" } ?? "")
+ actions
+ }
+ .padding(.leading, EnteSpacing.lg + 36 * eased)
+ .padding(.trailing, EnteSpacing.lg)
+ .offset(y: titleTop)
+ if let subtitle {
+ Text(subtitle)
+ .font(EnteTypography.mini)
+ .foregroundStyle(palette.mutedText)
+ .lineLimit(2)
+ .padding(.leading, EnteSpacing.lg + 36 * eased)
+ .padding(.trailing, EnteSpacing.lg)
+ .offset(y: metrics.contentTop + metrics.expandedTitleHeight + 2)
+ .opacity(1 - eased)
+ .accessibilityHidden(progress >= 0.99)
+ }
+ }
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .frame(height: metrics.expandedHeight - metrics.expansion * progress, alignment: .top)
+ .clipped()
+ .background(palette.background)
+ }
+
+ @ViewBuilder
+ private func titleView(progress: CGFloat) -> some View {
+ if let eyebrow {
+ HeaderTitleLayout(progress: progress, eyebrowHeight: metrics.eyebrowHeight) {
+ Text(eyebrow)
+ .font(EnteFont.outfit(size: 16 + 4 * progress, relativeTo: .title))
+ .foregroundStyle(palette.mutedText)
+ .lineLimit(1)
+ Text(title)
+ .font(EnteFont.outfit(size: 24 - 4 * progress, relativeTo: .title))
+ .lineLimit(1)
+ }
+ } else {
+ Text(title)
+ .font(EnteFont.outfit(size: 24 - 4 * progress, relativeTo: .title))
+ .lineLimit(1)
+ }
+ }
+}
+
+private struct HeaderMetrics {
+ let titleHeight: CGFloat
+ let eyebrowHeight: CGFloat
+ let collapsedTitleHeight: CGFloat
+ let subtitleHeight: CGFloat
+ let hasEyebrow: Bool
+ let hasSubtitle: Bool
+
+ var toolbarHeight: CGFloat { max(56, collapsedTitleHeight) }
+ var expandedTitleHeight: CGFloat { titleHeight + (hasEyebrow ? eyebrowHeight : 0) }
+ var expandedHeight: CGFloat {
+ max(
+ hasSubtitle ? 110 : 92,
+ 48 + expandedTitleHeight + (hasSubtitle ? 2 + subtitleHeight * 2 : 0) + 16)
+ }
+ var expansion: CGFloat { expandedHeight - toolbarHeight }
+ var contentTop: CGFloat {
+ 48 + (hasSubtitle ? min(subtitleHeight, max(0, toolbarHeight - expandedTitleHeight)) : 0)
+ }
+}
+
+private struct HeaderTitleLayout: Layout {
+ let progress: CGFloat
+ let eyebrowHeight: CGFloat
+
+ func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
+ let title = subviews[1].sizeThatFits(proposal)
+ return CGSize(
+ width: proposal.width ?? title.width,
+ height: title.height + eyebrowHeight * (1 - progress))
+ }
+
+ func placeSubviews(
+ in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()
+ ) {
+ let prefixWidth = min(
+ subviews[0].sizeThatFits(.unspecified).width + 6, max(0, bounds.width - 24))
+ let horizontal = headerEase(progress, firstControlX: 0, secondControlX: 0.58)
+ let titleX = prefixWidth * horizontal
+ let titleY =
+ eyebrowHeight * (1 - headerEase(progress, firstControlX: 0.42, secondControlX: 1))
+ subviews[0].place(
+ at: bounds.origin,
+ proposal: ProposedViewSize(
+ width: bounds.width + (max(0, prefixWidth - 6) - bounds.width) * horizontal,
+ height: nil))
+ subviews[1].place(
+ at: CGPoint(x: bounds.minX + titleX, y: bounds.minY + titleY),
+ proposal: ProposedViewSize(width: bounds.width - titleX, height: nil))
+ }
+}
+
+private func headerEase(_ progress: CGFloat, firstControlX: CGFloat, secondControlX: CGFloat)
+ -> CGFloat
+{
+ if progress <= 0 { return 0 }
+ if progress >= 1 { return 1 }
+ var lower: CGFloat = 0
+ var upper: CGFloat = 1
+ for _ in 0..<14 {
+ let t = (lower + upper) / 2
+ let remaining = 1 - t
+ let x =
+ 3 * remaining * remaining * t * firstControlX
+ + 3 * remaining * t * t * secondControlX + t * t * t
+ if x < progress {
+ lower = t
+ } else {
+ upper = t
+ }
+ }
+ let t = (lower + upper) / 2
+ return t * t * (3 - 2 * t)
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/CollapsingScrollView.swift b/apple/packages/EnteComponents/Sources/EnteComponents/CollapsingScrollView.swift
new file mode 100644
index 0000000000..56c05ff60b
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/CollapsingScrollView.swift
@@ -0,0 +1,93 @@
+import SwiftUI
+import UIKit
+
+struct CollapsingScrollView<Content: View>: UIViewControllerRepresentable {
+ let expansion: CGFloat
+ let identifier: String?
+ let onScroll: (CGFloat) -> Void
+ @ViewBuilder var content: Content
+
+ func makeUIViewController(context: Context) -> Controller {
+ Controller(content: content, environment: context.environment)
+ }
+
+ func updateUIViewController(_ controller: Controller, context: Context) {
+ controller.expansion = expansion
+ controller.scrollView.accessibilityIdentifier = identifier
+ controller.scrollView.isScrollEnabled = context.environment.isScrollEnabled
+ controller.onScroll = { offset in
+ onScroll(min(1, max(0, offset / expansion)))
+ }
+ controller.host.rootView = HostedContent(content: content, environment: context.environment)
+ }
+
+ struct HostedContent: View {
+ let content: Content
+ let environment: EnvironmentValues
+
+ var body: some View {
+ content.environment(\.self, environment).ignoresSafeArea()
+ }
+ }
+
+ final class Controller: UIViewController, UIScrollViewDelegate {
+ let scrollView = UIScrollView()
+ let host: UIHostingController<HostedContent>
+ var expansion: CGFloat = 0
+ var onScroll: (CGFloat) -> Void = { _ in }
+
+ init(content: Content, environment: EnvironmentValues) {
+ host = UIHostingController(
+ rootView: HostedContent(content: content, environment: environment))
+ super.init(nibName: nil, bundle: nil)
+ }
+
+ @available(*, unavailable)
+ required init?(coder: NSCoder) { return nil }
+
+ override func loadView() {
+ view = scrollView
+ scrollView.delegate = self
+ scrollView.contentInsetAdjustmentBehavior = .always
+ addChild(host)
+ host.sizingOptions = .intrinsicContentSize
+ host.view.backgroundColor = .clear
+ host.view.translatesAutoresizingMaskIntoConstraints = false
+ scrollView.addSubview(host.view)
+ NSLayoutConstraint.activate([
+ host.view.leadingAnchor.constraint(
+ equalTo: scrollView.contentLayoutGuide.leadingAnchor),
+ host.view.trailingAnchor.constraint(
+ equalTo: scrollView.contentLayoutGuide.trailingAnchor),
+ host.view.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor),
+ host.view.bottomAnchor.constraint(
+ equalTo: scrollView.contentLayoutGuide.bottomAnchor),
+ host.view.widthAnchor.constraint(equalTo: scrollView.frameLayoutGuide.widthAnchor),
+ ])
+ host.didMove(toParent: self)
+ }
+
+ func scrollViewDidScroll(_ scrollView: UIScrollView) {
+ onScroll(scrollView.contentOffset.y)
+ }
+
+ func scrollViewWillEndDragging(
+ _ scrollView: UIScrollView, withVelocity velocity: CGPoint,
+ targetContentOffset: UnsafeMutablePointer<CGPoint>
+ ) {
+ targetContentOffset.pointee.y = snappedOffset(targetContentOffset.pointee.y)
+ }
+
+ func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
+ let target = snappedOffset(scrollView.contentOffset.y)
+ if !decelerate && target != scrollView.contentOffset.y {
+ scrollView.setContentOffset(
+ CGPoint(x: scrollView.contentOffset.x, y: target), animated: true)
+ }
+ }
+
+ private func snappedOffset(_ offset: CGFloat) -> CGFloat {
+ offset > 1 && offset < expansion ? expansion : offset
+ }
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/InputField.swift b/apple/packages/EnteComponents/Sources/EnteComponents/InputField.swift
index f16c93a9e5..adf1fe2a36 100644
--- a/apple/packages/EnteComponents/Sources/EnteComponents/InputField.swift
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/InputField.swift
@@ -1,6 +1,6 @@
import SwiftUI
-public struct InputField: View {
+public struct InputField<Leading: View, Trailing: View>: View {
@Binding private var text: String
@FocusState private var focused: Bool
@Environment(\.entePalette) private var palette
@@ -10,8 +10,9 @@ public struct InputField: View {
private let placeholder: String
private let message: String?
private let state: InputState
- private let secure: Bool
private let lines: ClosedRange<Int>
+ private let leading: Leading
+ private let trailing: Trailing
public init(
text: Binding<String>,
@@ -20,8 +21,9 @@ public struct InputField: View {
placeholder: String = "",
message: String? = nil,
state: InputState = .normal,
- secure: Bool = false,
lines: ClosedRange<Int> = 1...1,
+ @ViewBuilder leading: () -> Leading = { EmptyView() },
+ @ViewBuilder trailing: () -> Trailing = { EmptyView() },
) {
_text = text
self.label = label
@@ -29,69 +31,30 @@ public struct InputField: View {
self.placeholder = placeholder
self.message = message
self.state = state
- self.secure = secure
self.lines = lines
+ self.leading = leading()
+ self.trailing = trailing()
}
public var body: some View {
let prompt = Text(placeholder)
.foregroundColor(enabled ? palette.hintText : palette.disabledText)
- let shape = RoundedRectangle(cornerRadius: EnteRadius.large, style: .continuous)
- VStack(alignment: .leading, spacing: EnteSpacing.sm) {
- if let label {
- HStack(spacing: 2) {
- Text(label).foregroundStyle(enabled ? palette.text : palette.disabledText)
- if required {
- Text("*").font(EnteTypography.bodyBold).foregroundStyle(palette.danger)
- }
- }
- .font(EnteTypography.body)
+ InputFrame(
+ label: label, required: required, message: message, state: state, focused: focused,
+ focus: { focused = true }
+ ) {
+ HStack(spacing: EnteSpacing.sm) {
+ leading.foregroundStyle(enabled ? palette.hintText : palette.disabledText)
+ TextField(
+ label ?? placeholder, text: $text, prompt: prompt,
+ axis: lines.upperBound == 1 ? .horizontal : .vertical
+ )
+ .lineLimit(lines)
+ .focused($focused)
+ .accessibilityLabel(label ?? placeholder)
}
- Group {
- if secure {
- SecureField(label ?? placeholder, text: $text, prompt: prompt)
- } else {
- TextField(
- label ?? placeholder, text: $text, prompt: prompt,
- axis: lines.upperBound == 1 ? .horizontal : .vertical
- )
- .lineLimit(lines)
- }
- }
- .textFieldStyle(.plain)
- .accessibilityLabel(label ?? placeholder)
- .accessibilityHint(state == .error ? message ?? "" : "")
- .focused($focused)
- .font(EnteTypography.body)
- .foregroundStyle(enabled ? palette.text : palette.disabledText)
- .tint(palette.primary)
- .padding(EnteSpacing.lg)
- .frame(minHeight: 52)
- .background {
- shape.fill(enabled ? palette.surface : palette.fill)
- .onTapGesture { focused = true }
- }
- .overlay { shape.strokeBorder(borderColor, lineWidth: 1) }
- if let message {
- Text(message)
- .font(EnteTypography.mini)
- .foregroundStyle(statusColor)
- }
- }
- }
-
- private var borderColor: Color {
- if state != .normal {
- return statusColor
- }
- return focused ? palette.hintText : palette.faintBorder
- }
-
- private var statusColor: Color {
- switch state {
- case .normal: palette.mutedText
- case .error: palette.danger
- case .success: palette.primary
+ } trailing: {
+ trailing
}
}
}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/InputFrame.swift b/apple/packages/EnteComponents/Sources/EnteComponents/InputFrame.swift
new file mode 100644
index 0000000000..ee38591e8a
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/InputFrame.swift
@@ -0,0 +1,62 @@
+import SwiftUI
+
+struct InputFrame<Field: View, Trailing: View>: View {
+ @Environment(\.entePalette) private var palette
+ @Environment(\.isEnabled) private var enabled
+ let label: String?
+ var required = false
+ let message: String?
+ let state: InputState
+ let focused: Bool
+ let focus: () -> Void
+ @ViewBuilder var field: Field
+ @ViewBuilder var trailing: Trailing
+
+ var body: some View {
+ let shape = RoundedRectangle(cornerRadius: EnteRadius.large, style: .continuous)
+ VStack(alignment: .leading, spacing: EnteSpacing.sm) {
+ if let label {
+ HStack(spacing: 2) {
+ Text(label).foregroundStyle(enabled ? palette.text : palette.disabledText)
+ if required {
+ Text("*").font(EnteTypography.bodyBold).foregroundStyle(palette.danger)
+ }
+ }
+ .font(EnteTypography.body)
+ }
+ HStack(spacing: EnteSpacing.sm) {
+ field
+ .textFieldStyle(.plain)
+ .accessibilityHint(state == .error ? message ?? "" : "")
+ .font(EnteTypography.body)
+ .foregroundStyle(enabled ? palette.text : palette.disabledText)
+ .tint(palette.primary)
+ .padding(.vertical, EnteSpacing.lg)
+ trailing.foregroundStyle(enabled ? palette.hintText : palette.disabledText)
+ }
+ .padding(.horizontal, EnteSpacing.lg)
+ .frame(minHeight: 52)
+ .background {
+ shape.fill(enabled ? palette.surface : palette.fill)
+ .onTapGesture(perform: focus)
+ }
+ .overlay {
+ shape.strokeBorder(
+ state != .normal
+ ? statusColor : focused ? palette.hintText : palette.faintBorder,
+ lineWidth: 1)
+ }
+ if let message {
+ Text(message).font(EnteTypography.mini).foregroundStyle(statusColor)
+ }
+ }
+ }
+
+ private var statusColor: Color {
+ switch state {
+ case .normal: palette.mutedText
+ case .error: palette.danger
+ case .success: palette.primary
+ }
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/MenuRow.swift b/apple/packages/EnteComponents/Sources/EnteComponents/MenuRow.swift
index d07ccd69b1..78a9bfac53 100644
--- a/apple/packages/EnteComponents/Sources/EnteComponents/MenuRow.swift
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/MenuRow.swift
@@ -1,10 +1,10 @@
import SwiftUI
-public struct MenuRow: View {
+public struct MenuRow<Leading: View>: View {
@Environment(\.entePalette) private var palette
private let title: String
private let subtitle: String?
- private let image: Image?
+ private let leading: Leading?
private let selected: Bool
private let showsChevron: Bool
private let action: () -> Void
@@ -12,14 +12,14 @@ public struct MenuRow: View {
public init(
_ title: String,
subtitle: String? = nil,
- image: Image? = nil,
+ @ViewBuilder leading: () -> Leading,
selected: Bool = false,
showsChevron: Bool = false,
action: @escaping () -> Void
) {
self.title = title
self.subtitle = subtitle
- self.image = image
+ self.leading = leading()
self.selected = selected
self.showsChevron = showsChevron
self.action = action
@@ -28,9 +28,8 @@ public struct MenuRow: View {
public var body: some View {
Button(action: action) {
HStack(spacing: EnteSpacing.md) {
- if let image {
- image.resizable().scaledToFit()
- .frame(width: 18, height: 18)
+ if let leading {
+ leading
.frame(width: 36, height: 36)
.foregroundStyle(palette.mutedText)
.accessibilityHidden(true)
@@ -65,7 +64,7 @@ public struct MenuRow: View {
.accessibilityHidden(true)
}
}
- .padding(.leading, image == nil ? EnteSpacing.lg : EnteSpacing.md)
+ .padding(.leading, leading == nil ? EnteSpacing.lg : EnteSpacing.md)
.padding(.trailing, EnteSpacing.md)
.padding(.vertical, 9)
.frame(minHeight: 58)
@@ -76,6 +75,23 @@ public struct MenuRow: View {
}
}
+public extension MenuRow where Leading == EmptyView {
+ init(
+ _ title: String,
+ subtitle: String? = nil,
+ selected: Bool = false,
+ showsChevron: Bool = false,
+ action: @escaping () -> Void
+ ) {
+ self.title = title
+ self.subtitle = subtitle
+ leading = nil
+ self.selected = selected
+ self.showsChevron = showsChevron
+ self.action = action
+ }
+}
+
private struct MenuRowStyle: ButtonStyle {
@Environment(\.entePalette) private var palette
@Environment(\.isEnabled) private var enabled
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/PasswordField.swift b/apple/packages/EnteComponents/Sources/EnteComponents/PasswordField.swift
new file mode 100644
index 0000000000..3d939dfa46
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/PasswordField.swift
@@ -0,0 +1,144 @@
+import EnteFonts
+import SwiftUI
+import UIKit
+
+public struct PasswordField<Trailing: View>: View {
+ @Binding private var text: String
+ @State private var focused = false
+ @Environment(\.entePalette) private var palette
+ @Environment(\.isEnabled) private var enabled
+ private let label: String?
+ private let required: Bool
+ private let isRevealed: Bool
+ private let placeholder: String
+ private let message: String?
+ private let state: InputState
+ private let contentType: UITextContentType
+ private let returnKeyType: UIReturnKeyType
+ private let onSubmit: () -> Void
+ private let trailing: Trailing
+
+ public init(
+ _ label: String? = nil,
+ text: Binding<String>,
+ required: Bool = false,
+ isRevealed: Bool = false,
+ placeholder: String = "",
+ message: String? = nil,
+ state: InputState = .normal,
+ contentType: UITextContentType = .password,
+ returnKeyType: UIReturnKeyType = .done,
+ onSubmit: @escaping () -> Void = {},
+ @ViewBuilder trailing: () -> Trailing = { EmptyView() },
+ ) {
+ self.label = label
+ self.required = required
+ _text = text
+ self.isRevealed = isRevealed
+ self.placeholder = placeholder
+ self.message = message
+ self.state = state
+ self.contentType = contentType
+ self.returnKeyType = returnKeyType
+ self.onSubmit = onSubmit
+ self.trailing = trailing()
+ }
+
+ public var body: some View {
+ InputFrame(
+ label: label, required: required, message: message, state: state, focused: focused,
+ focus: { focused = true }
+ ) {
+ PasswordEditor(
+ text: $text, focused: $focused, isRevealed: isRevealed,
+ label: label ?? placeholder, placeholder: placeholder, enabled: enabled,
+ textColor: UIColor(enabled ? palette.text : palette.disabledText),
+ hintColor: UIColor(enabled ? palette.hintText : palette.disabledText),
+ tintColor: UIColor(palette.primary), contentType: contentType,
+ returnKeyType: returnKeyType, onSubmit: onSubmit
+ )
+ .privacySensitive()
+ } trailing: {
+ trailing
+ }
+ }
+}
+
+private struct PasswordEditor: UIViewRepresentable {
+ @Binding var text: String
+ @Binding var focused: Bool
+ let isRevealed: Bool
+ let label: String
+ let placeholder: String
+ let enabled: Bool
+ let textColor: UIColor
+ let hintColor: UIColor
+ let tintColor: UIColor
+ let contentType: UITextContentType
+ let returnKeyType: UIReturnKeyType
+ let onSubmit: () -> Void
+
+ func makeUIView(context: Context) -> UITextField {
+ let field = UITextField()
+ field.delegate = context.coordinator
+ field.addTarget(
+ context.coordinator, action: #selector(Coordinator.changed), for: .editingChanged)
+ field.autocorrectionType = .no
+ field.autocapitalizationType = .none
+ field.spellCheckingType = .no
+ field.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
+ return field
+ }
+
+ func updateUIView(_ field: UITextField, context: Context) {
+ context.coordinator.parent = self
+ field.font = .inter(size: 14, weight: .medium)
+ field.adjustsFontForContentSizeCategory = true
+ field.textColor = textColor
+ field.tintColor = tintColor
+ field.attributedPlaceholder = NSAttributedString(
+ string: placeholder, attributes: [.foregroundColor: hintColor])
+ field.accessibilityLabel = label
+ field.isEnabled = enabled
+ field.textContentType = contentType
+ field.returnKeyType = returnKeyType
+ if field.text != text { field.text = text }
+ if field.isSecureTextEntry == isRevealed {
+ let selection = field.selectedTextRange
+ field.isSecureTextEntry = !isRevealed
+ if field.isFirstResponder {
+ field.text = ""
+ field.insertText(text)
+ field.selectedTextRange = selection
+ }
+ }
+ if focused && enabled && !field.isFirstResponder { field.becomeFirstResponder() }
+ if (!focused || !enabled) && field.isFirstResponder { field.resignFirstResponder() }
+ }
+
+ func sizeThatFits(_ proposal: ProposedViewSize, uiView: UITextField, context: Context)
+ -> CGSize?
+ {
+ CGSize(
+ width: proposal.width ?? uiView.intrinsicContentSize.width,
+ height: uiView.intrinsicContentSize.height)
+ }
+
+ func makeCoordinator() -> Coordinator { Coordinator(self) }
+
+ final class Coordinator: NSObject, UITextFieldDelegate {
+ var parent: PasswordEditor
+ init(_ parent: PasswordEditor) { self.parent = parent }
+
+ @objc func changed(_ field: UITextField) {
+ let value = field.text ?? ""
+ if parent.text != value { parent.text = value }
+ }
+ func textFieldDidBeginEditing(_ field: UITextField) { parent.focused = true }
+ func textFieldDidEndEditing(_ field: UITextField) { parent.focused = false }
+ func textFieldShouldReturn(_ field: UITextField) -> Bool {
+ parent.onSubmit()
+ return true
+ }
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/Selection.swift b/apple/packages/EnteComponents/Sources/EnteComponents/Selection.swift
index 937661536f..743550427b 100644
--- a/apple/packages/EnteComponents/Sources/EnteComponents/Selection.swift
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/Selection.swift
@@ -101,19 +101,19 @@ public struct EnteToggleStyle: ToggleStyle {
HStack {
configuration.label
Spacer(minLength: EnteSpacing.md)
- RoundedRectangle(cornerRadius: 16, style: .continuous)
+ RoundedRectangle(cornerRadius: 12, style: .continuous)
.fill(configuration.isOn ? palette.primary : palette.fill)
.overlay {
Circle()
- .fill(configuration.isOn ? palette.reverseText : palette.primary)
- .frame(width: 25, height: 25)
- .padding(3)
+ .fill(.white)
+ .frame(width: 20, height: 20)
+ .padding(2)
.frame(
maxWidth: .infinity,
alignment: configuration.isOn ? .trailing : .leading,
)
}
- .frame(width: 51, height: 31)
+ .frame(width: 40, height: 24)
.animation(.easeInOut(duration: EnteMotion.quick), value: configuration.isOn)
}
.frame(minHeight: 44)
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/Settings/SettingsPage.swift b/apple/packages/EnteComponents/Sources/EnteComponents/Settings/SettingsPage.swift
new file mode 100644
index 0000000000..04757c5ce4
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/Settings/SettingsPage.swift
@@ -0,0 +1,29 @@
+import SwiftUI
+
+public struct SettingsPage<Content: View>: View {
+ private let title: String
+ private let identifier: String?
+ private let backLabel: String
+ private let back: () -> Void
+ private let content: Content
+
+ public init(
+ _ title: String,
+ identifier: String? = nil,
+ backLabel: String,
+ back: @escaping () -> Void,
+ @ViewBuilder content: () -> Content,
+ ) {
+ self.title = title
+ self.identifier = identifier
+ self.backLabel = backLabel
+ self.back = back
+ self.content = content()
+ }
+
+ public var body: some View {
+ CollapsingPage(title, identifier: identifier, backLabel: backLabel, back: back) {
+ VStack(alignment: .leading, spacing: EnteSpacing.sm) { content }
+ }
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/Settings/SettingsToggle.swift b/apple/packages/EnteComponents/Sources/EnteComponents/Settings/SettingsToggle.swift
new file mode 100644
index 0000000000..0dea26f0f6
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/Settings/SettingsToggle.swift
@@ -0,0 +1,21 @@
+import SwiftUI
+
+public struct SettingsToggle: View {
+ @Binding private var isOn: Bool
+ private let title: String
+
+ public init(_ title: String, isOn: Binding<Bool>) {
+ self.title = title
+ _isOn = isOn
+ }
+
+ public var body: some View {
+ MenuGroup {
+ Toggle(title, isOn: $isOn)
+ .font(EnteTypography.body)
+ .toggleStyle(EnteToggleStyle())
+ .padding(.horizontal, EnteSpacing.lg)
+ .padding(.vertical, EnteSpacing.sm)
+ }
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/Theme.swift b/apple/packages/EnteComponents/Sources/EnteComponents/Theme.swift
index 8ef120f5be..05691e1523 100644
--- a/apple/packages/EnteComponents/Sources/EnteComponents/Theme.swift
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/Theme.swift
@@ -10,6 +10,7 @@ public enum EnteApp: Sendable {
public struct Palette: Sendable {
public let isDark: Bool
public let primary: Color
+ public let primarySurface: Color
public let primaryDark: Color
public let primaryDarker: Color
public let text: Color
@@ -47,9 +48,16 @@ public struct Palette: Sendable {
primaryDark = Color(hex: 0x0E5FD9)
primaryDarker = Color(hex: 0x0B4CAD)
}
+ let primarySurface: UInt =
+ switch app {
+ case .photos: dark ? 0x292929 : 0xDDEEDF
+ case .auth: dark ? 0x271C32 : 0xF4E7FC
+ case .locker: dark ? 0x292929 : 0xE7EFFA
+ }
return Palette(
isDark: dark,
primary: primary,
+ primarySurface: Color(hex: primarySurface),
primaryDark: primaryDark,
primaryDarker: primaryDarker,
text: dark ? .white : .black,
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/VerificationCodeField.swift b/apple/packages/EnteComponents/Sources/EnteComponents/VerificationCodeField.swift
new file mode 100644
index 0000000000..7748286981
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/VerificationCodeField.swift
@@ -0,0 +1,88 @@
+import EnteFonts
+import SwiftUI
+
+public struct VerificationCodeField: View {
+ @Binding private var code: String
+ @State private var input: String
+ @FocusState private var focused: Bool
+ @Environment(\.entePalette) private var palette
+ @Environment(\.isEnabled) private var enabled
+ private let label: String
+ private let error: String?
+
+ public init(_ label: String, code: Binding<String>, error: String? = nil) {
+ self.label = label
+ _code = code
+ _input = State(initialValue: code.wrappedValue)
+ self.error = error
+ }
+
+ public var body: some View {
+ VStack(alignment: .leading, spacing: EnteSpacing.sm) {
+ TextField("", text: $input)
+ .onChange(of: input) { value in
+ let digits = String(value.filter { $0.isASCII && $0.isNumber }.prefix(6))
+ input = digits
+ code = digits
+ }
+ .onChange(of: code) { input = $0 }
+ .textFieldStyle(.plain)
+ .keyboardType(.numberPad)
+ .textContentType(.oneTimeCode)
+ .autocorrectionDisabled()
+ .focused($focused)
+ .foregroundStyle(.clear)
+ .tint(.clear)
+ .font(EnteFont.inter(size: 20, weight: .bold, relativeTo: .title3))
+ .frame(minHeight: 52)
+ .accessibilityLabel(label)
+ .accessibilityHint(error ?? "")
+ .privacySensitive()
+ .overlay {
+ HStack(spacing: 6) {
+ let digits = Array(code)
+ ForEach(0..<6) { index in
+ let filled = index < digits.count
+ let active = focused && index == min(code.count, 5)
+ Text(index < digits.count ? String(digits[index]) : " ")
+ .font(EnteFont.inter(size: 20, weight: .bold, relativeTo: .title3))
+ .foregroundStyle(
+ !enabled
+ ? palette.mutedText
+ : error != nil ? palette.danger : palette.primary
+ )
+ .frame(maxWidth: .infinity, minHeight: 52)
+ .background(
+ !enabled
+ ? palette.fill
+ : filled && error == nil
+ ? palette.primarySurface : palette.surface,
+ in: RoundedRectangle(cornerRadius: EnteRadius.large)
+ )
+ .overlay {
+ RoundedRectangle(cornerRadius: EnteRadius.large)
+ .strokeBorder(
+ borderColor(index: index),
+ lineWidth: error != nil || filled || active ? 2 : 1)
+ }
+ }
+ }
+ .allowsHitTesting(false)
+ .accessibilityHidden(true)
+ }
+ .frame(maxWidth: 324)
+ .animation(.easeOut(duration: EnteMotion.quick), value: code)
+ .animation(.easeOut(duration: EnteMotion.quick), value: focused)
+ if let error {
+ Text(error).font(EnteTypography.mini).foregroundStyle(palette.danger)
+ }
+ }
+ }
+
+ private func borderColor(index: Int) -> Color {
+ if !enabled { return palette.faintBorder }
+ if error != nil { return palette.danger }
+ return index < code.count || focused && index == min(code.count, 5)
+ ? palette.primary : palette.border
+ }
+}