Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add grouped information rows and simplify component theming

Neeraj Guptaf9c546a5f854
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/Rows.kt b/android/packages/components/src/main/kotlin/io/ente/components/Rows.kt
new file mode 100644
index 0000000000..5ca70f3473
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/Rows.kt
@@ -0,0 +1,84 @@
+package io.ente.components
+
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.heightIn
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.HorizontalDivider
+import androidx.compose.material3.LocalContentColor
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.dp
+
+@Composable
+public fun InfoRow(
+ title: String,
+ modifier: Modifier = Modifier,
+ subtitle: String? = null,
+ leading: @Composable () -> Unit,
+) {
+ val palette = LocalEntePalette.current
+ Row(
+ modifier
+ .fillMaxWidth()
+ .heightIn(min = 54.dp)
+ .padding(horizontal = EnteSpacing.md, vertical = 9.dp)
+ .semantics(mergeDescendants = true) {},
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ CompositionLocalProvider(LocalContentColor provides palette.mutedText) {
+ Box(Modifier.size(36.dp), contentAlignment = Alignment.Center) { leading() }
+ }
+ Spacer(Modifier.width(EnteSpacing.md))
+ Column(Modifier.weight(1f)) {
+ Text(
+ title,
+ maxLines = 2,
+ overflow = TextOverflow.Ellipsis,
+ style = EnteTypography.body,
+ color = palette.text,
+ )
+ if (!subtitle.isNullOrEmpty()) {
+ Spacer(Modifier.height(EnteSpacing.xs))
+ Text(
+ subtitle,
+ maxLines = 2,
+ overflow = TextOverflow.Ellipsis,
+ style = EnteTypography.mini,
+ color = palette.mutedText,
+ )
+ }
+ }
+ }
+}
+
+@Composable
+public fun MenuGroup(modifier: Modifier = Modifier, content: @Composable () -> Unit) {
+ val palette = LocalEntePalette.current
+ Surface(
+ modifier = modifier.fillMaxWidth(),
+ color = palette.surface,
+ contentColor = palette.text,
+ shape = RoundedCornerShape(EnteRadius.button),
+ ) {
+ Column { content() }
+ }
+}
+
+@Composable
+public fun EnteDivider(modifier: Modifier = Modifier) {
+ HorizontalDivider(modifier, color = LocalEntePalette.current.faintBorder)
+}
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 66f515503b..8cb9f27a9e 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
@@ -28,6 +28,7 @@ internal constructor(
public val primary: Color,
public val primaryDarker: Color,
public val text: Color,
+ public val mutedText: Color,
public val hintText: Color,
public val disabledText: Color,
public val reverseText: Color,
@@ -35,6 +36,7 @@ internal constructor(
public val fill: Color,
public val fillDarker: Color,
public val fillDarkest: Color,
+ public val faintBorder: Color,
public val danger: Color,
public val dangerDarker: Color,
)
@@ -44,6 +46,8 @@ public val LocalEntePalette: ProvidableCompositionLocal<Palette> = staticComposi
}
public object EnteSpacing {
+ public val xs: Dp = 4.dp
+ public val md: Dp = 12.dp
public val xl: Dp = 20.dp
}
@@ -72,6 +76,7 @@ public object EnteTypography {
lineHeight = 20.sp,
)
public val bodyBold: TextStyle = body.copy(fontWeight = FontWeight.SemiBold)
+ public val mini: TextStyle = body.copy(fontSize = 12.sp, lineHeight = 16.sp)
}
@Composable
@@ -96,6 +101,7 @@ private fun palette(app: EnteApp, dark: Boolean): Palette {
primary = primary,
primaryDarker = primaryDarker,
text = if (dark) Color.White else Color.Black,
+ mutedText = Color(if (dark) 0xFF999999 else 0xFF666666),
hintText = Color(0xFF969696),
disabledText = Color(if (dark) 0xFF414141 else 0xFFD6D6D6),
reverseText = if (dark) Color.Black else Color.White,
@@ -103,6 +109,7 @@ private fun palette(app: EnteApp, dark: Boolean): Palette {
fill = Color(if (dark) 0xFF0A0A0A else 0xFFEAEAEA),
fillDarker = Color(if (dark) 0xFF141414 else 0xFFDEDEDE),
fillDarkest = Color(if (dark) 0xFF292929 else 0xFFD2D2D2),
+ faintBorder = Color(if (dark) 0xFF2A2A2A else 0xFFEBEBEB),
danger = Color(0xFFF63A3A),
dangerDarker = Color(0xFFC52E2E),
)
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/ActionButton.swift b/apple/packages/EnteComponents/Sources/EnteComponents/ActionButton.swift
index ff68beac23..8e953b9064 100644
--- a/apple/packages/EnteComponents/Sources/EnteComponents/ActionButton.swift
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/ActionButton.swift
@@ -20,7 +20,6 @@ public enum ActionSize: Sendable {
}
public struct ActionButton: View {
- @Environment(\.entePalette) private var palette
private let title: String
private let variant: ActionVariant
private let size: ActionSize
@@ -58,7 +57,6 @@ public struct ActionButton: View {
.buttonStyle(
ActionStyle(
variant: variant,
- palette: palette,
cornerRadius: inlineLink ? 0 : EnteRadius.button
)
)
@@ -67,9 +65,9 @@ public struct ActionButton: View {
}
private struct ActionStyle: ButtonStyle {
+ @Environment(\.entePalette) private var palette
@Environment(\.isEnabled) private var enabled
let variant: ActionVariant
- let palette: Palette
let cornerRadius: CGFloat
func makeBody(configuration: Configuration) -> some View {
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/IconAction.swift b/apple/packages/EnteComponents/Sources/EnteComponents/IconAction.swift
index b4f512b704..f43b7ff357 100644
--- a/apple/packages/EnteComponents/Sources/EnteComponents/IconAction.swift
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/IconAction.swift
@@ -1,7 +1,6 @@
import SwiftUI
public struct IconAction<Content: View>: View {
- @Environment(\.entePalette) private var palette
private let kind: IconActionKind
private let enabled: Bool
private let size: CGFloat
@@ -31,7 +30,6 @@ public struct IconAction<Content: View>: View {
.buttonStyle(
IconActionStyle(
kind: kind,
- palette: palette,
cornerRadius: kind == .circular ? size / 2 : EnteRadius.medium
)
)
@@ -48,9 +46,9 @@ public enum IconActionKind: Sendable {
}
private struct IconActionStyle: ButtonStyle {
+ @Environment(\.entePalette) private var palette
@Environment(\.isEnabled) private var enabled
let kind: IconActionKind
- let palette: Palette
let cornerRadius: CGFloat
func makeBody(configuration: Configuration) -> some View {
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/Rows.swift b/apple/packages/EnteComponents/Sources/EnteComponents/Rows.swift
new file mode 100644
index 0000000000..0c83335b61
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/Rows.swift
@@ -0,0 +1,68 @@
+import SwiftUI
+
+public struct InfoRow<Leading: View>: View {
+ @Environment(\.entePalette) private var palette
+ private let title: String
+ private let subtitle: String?
+ private let leading: Leading
+
+ public init(_ title: String, subtitle: String? = nil, @ViewBuilder leading: () -> Leading) {
+ self.title = title
+ self.subtitle = subtitle
+ self.leading = leading()
+ }
+
+ public var body: some View {
+ HStack(spacing: EnteSpacing.md) {
+ leading
+ .frame(width: 36, height: 36)
+ .foregroundStyle(palette.mutedText)
+ VStack(alignment: .leading, spacing: EnteSpacing.xs) {
+ Text(title)
+ .font(EnteTypography.body)
+ .foregroundStyle(palette.text)
+ .lineLimit(2)
+ if let subtitle, !subtitle.isEmpty {
+ Text(subtitle)
+ .font(EnteTypography.mini)
+ .foregroundStyle(palette.mutedText)
+ .lineLimit(2)
+ }
+ }
+ Spacer(minLength: 0)
+ }
+ .padding(.horizontal, EnteSpacing.md)
+ .padding(.vertical, 9)
+ .frame(minHeight: 54)
+ .accessibilityElement(children: .combine)
+ }
+}
+
+public struct MenuGroup<Content: View>: View {
+ @Environment(\.entePalette) private var palette
+ private let content: Content
+
+ public init(@ViewBuilder content: () -> Content) {
+ self.content = content()
+ }
+
+ public var body: some View {
+ VStack(alignment: .leading, spacing: 0) {
+ content
+ }
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .foregroundStyle(palette.text)
+ .background(palette.surface)
+ .clipShape(RoundedRectangle(cornerRadius: EnteRadius.button, style: .continuous))
+ }
+}
+
+public struct EnteDivider: View {
+ @Environment(\.entePalette) private var palette
+
+ public init() {}
+
+ public var body: some View {
+ palette.faintBorder.frame(height: 1)
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/Theme.swift b/apple/packages/EnteComponents/Sources/EnteComponents/Theme.swift
index 45f87a64bb..29ee3730dc 100644
--- a/apple/packages/EnteComponents/Sources/EnteComponents/Theme.swift
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/Theme.swift
@@ -12,6 +12,7 @@ public struct Palette: Sendable {
public let primary: Color
public let primaryDarker: Color
public let text: Color
+ public let mutedText: Color
public let hintText: Color
public let disabledText: Color
public let reverseText: Color
@@ -19,6 +20,7 @@ public struct Palette: Sendable {
public let fill: Color
public let fillDarker: Color
public let fillDarkest: Color
+ public let faintBorder: Color
public let danger: Color
public let dangerDarker: Color
@@ -41,6 +43,7 @@ public struct Palette: Sendable {
primary: primary,
primaryDarker: primaryDarker,
text: dark ? .white : .black,
+ mutedText: Color(hex: dark ? 0x999999 : 0x666666),
hintText: Color(hex: 0x969696),
disabledText: Color(hex: dark ? 0x414141 : 0xD6D6D6),
reverseText: dark ? .black : .white,
@@ -48,6 +51,7 @@ public struct Palette: Sendable {
fill: Color(hex: dark ? 0x0A0A0A : 0xEAEAEA),
fillDarker: Color(hex: dark ? 0x141414 : 0xDEDEDE),
fillDarkest: Color(hex: dark ? 0x292929 : 0xD2D2D2),
+ faintBorder: Color(hex: dark ? 0x2A2A2A : 0xEBEBEB),
danger: Color(hex: 0xF63A3A),
dangerDarker: Color(hex: 0xC52E2E)
)
@@ -55,6 +59,8 @@ public struct Palette: Sendable {
}
public enum EnteSpacing {
+ public static let xs: CGFloat = 4
+ public static let md: CGFloat = 12
public static let xl: CGFloat = 20
}
@@ -71,6 +77,7 @@ public enum EnteTypography {
public static let display2 = EnteFont.outfit(size: 24, relativeTo: .title)
public static let body = EnteFont.inter(size: 14, weight: .medium, relativeTo: .body)
public static let bodyBold = EnteFont.inter(size: 14, weight: .semibold, relativeTo: .body)
+ public static let mini = EnteFont.inter(size: 12, weight: .medium, relativeTo: .caption)
}
public struct EnteTheme<Content: View>: View {