Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add native UI foundations

Neeraj Gupta291073774464
diff --git a/android/packages/components/build.gradle.kts b/android/packages/components/build.gradle.kts
new file mode 100644
index 0000000000..e5c9d87f18
--- /dev/null
+++ b/android/packages/components/build.gradle.kts
@@ -0,0 +1,34 @@
+import org.jetbrains.kotlin.gradle.dsl.JvmTarget
+
+plugins {
+ id("com.android.library")
+ id("org.jetbrains.kotlin.android")
+ id("org.jetbrains.kotlin.plugin.compose")
+}
+
+kotlin { explicitApi() }
+
+android {
+ namespace = "io.ente.components"
+ compileSdk = 36
+
+ defaultConfig { minSdk = 24 }
+
+ buildFeatures { compose = true }
+
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_17
+ targetCompatibility = JavaVersion.VERSION_17
+ }
+}
+
+kotlin { compilerOptions { jvmTarget.set(JvmTarget.JVM_17) } }
+
+dependencies {
+ implementation(project(":fonts"))
+
+ api("androidx.compose.material3:material3")
+ api("androidx.compose.ui:ui")
+ api("androidx.compose.ui:ui-text")
+ api(platform("androidx.compose:compose-bom:2025.02.00"))
+}
diff --git a/android/packages/components/src/main/AndroidManifest.xml b/android/packages/components/src/main/AndroidManifest.xml
new file mode 100644
index 0000000000..cc947c5679
--- /dev/null
+++ b/android/packages/components/src/main/AndroidManifest.xml
@@ -0,0 +1 @@
+<manifest />
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/Actions.kt b/android/packages/components/src/main/kotlin/io/ente/components/Actions.kt
new file mode 100644
index 0000000000..29044a5a79
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/Actions.kt
@@ -0,0 +1,156 @@
+package io.ente.components
+
+import androidx.compose.animation.core.animateFloatAsState
+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.fillMaxWidth
+import androidx.compose.foundation.layout.heightIn
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.text.style.TextDecoration
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.dp
+
+public enum class ActionVariant {
+ Primary,
+ Secondary,
+ Neutral,
+ Critical,
+ CriticalText,
+ Link,
+}
+
+public enum class ActionDensity {
+ Regular,
+ Compact,
+}
+
+public enum class ActionSize {
+ Small,
+ Large,
+}
+
+@Composable
+public fun ActionButton(
+ label: String,
+ onClick: () -> Unit,
+ modifier: Modifier = Modifier,
+ variant: ActionVariant = ActionVariant.Primary,
+ size: ActionSize = ActionSize.Large,
+ density: ActionDensity = ActionDensity.Regular,
+ enabled: Boolean = true,
+) {
+ val palette = LocalEntePalette.current
+ val interactionSource = remember { MutableInteractionSource() }
+ val pressed by interactionSource.collectIsPressedAsState()
+ val colors = actionColors(variant, palette, enabled, pressed)
+ val scale by
+ animateFloatAsState(
+ targetValue = if (pressed && enabled) 0.98f else 1f,
+ animationSpec = tween(EnteMotion.quick),
+ label = "actionScale",
+ )
+ val inlineLink = variant == ActionVariant.Link && size == ActionSize.Small
+ val actionModifier = if (size == ActionSize.Large) modifier.fillMaxWidth() else modifier
+
+ Surface(
+ color = colors.background,
+ contentColor = colors.foreground,
+ shape = RoundedCornerShape(if (inlineLink) 0.dp else EnteRadius.button),
+ modifier =
+ actionModifier
+ .graphicsLayer {
+ scaleX = scale
+ scaleY = scale
+ }
+ .clickable(
+ enabled = enabled,
+ role = Role.Button,
+ interactionSource = interactionSource,
+ indication = null,
+ onClick = onClick,
+ ),
+ ) {
+ Row(
+ modifier =
+ Modifier.heightIn(min = if (inlineLink) 0.dp else 24.dp)
+ .padding(
+ horizontal = if (inlineLink) 0.dp else EnteSpacing.xl,
+ vertical =
+ if (inlineLink) {
+ 4.dp
+ } else if (density == ActionDensity.Regular) {
+ 14.dp
+ } else {
+ 12.dp
+ },
+ ),
+ horizontalArrangement = Arrangement.Center,
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Text(
+ text = label,
+ maxLines = 2,
+ overflow = TextOverflow.Ellipsis,
+ style =
+ if (density == ActionDensity.Regular) {
+ EnteTypography.bodyBold
+ } else {
+ EnteTypography.body
+ },
+ textDecoration =
+ if (variant == ActionVariant.CriticalText || variant == ActionVariant.Link) {
+ TextDecoration.Underline
+ } else {
+ null
+ },
+ )
+ }
+ }
+}
+
+private data class ActionColors(val background: Color, val foreground: Color)
+
+private fun actionColors(
+ variant: ActionVariant,
+ palette: Palette,
+ enabled: Boolean,
+ pressed: Boolean,
+): ActionColors {
+ if (!enabled) {
+ val background =
+ if (variant == ActionVariant.CriticalText || variant == ActionVariant.Link) {
+ Color.Transparent
+ } else {
+ palette.fill
+ }
+ return ActionColors(background, palette.disabledText)
+ }
+ return when (variant) {
+ ActionVariant.Primary ->
+ ActionColors(if (pressed) palette.primaryDarker else palette.primary, Color.White)
+ ActionVariant.Secondary ->
+ ActionColors(if (pressed) palette.fillDarkest else palette.fill, palette.text)
+ ActionVariant.Neutral -> ActionColors(palette.text, palette.reverseText)
+ ActionVariant.Critical ->
+ ActionColors(if (pressed) palette.dangerDarker else palette.danger, Color.White)
+ ActionVariant.CriticalText ->
+ ActionColors(Color.Transparent, if (pressed) palette.dangerDarker else palette.danger)
+ ActionVariant.Link ->
+ ActionColors(Color.Transparent, if (pressed) palette.primaryDarker else palette.primary)
+ }
+}
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
new file mode 100644
index 0000000000..dba50012da
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/Theme.kt
@@ -0,0 +1,98 @@
+package io.ente.components
+
+import androidx.compose.foundation.isSystemInDarkTheme
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.ProvidableCompositionLocal
+import androidx.compose.runtime.staticCompositionLocalOf
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import io.ente.fonts.EnteFontFamily
+
+public enum class EnteApp {
+ Photos,
+ Auth,
+ Locker,
+}
+
+@Immutable
+public class Palette
+internal constructor(
+ public val primary: Color,
+ public val primaryDarker: Color,
+ public val text: Color,
+ public val disabledText: Color,
+ public val reverseText: Color,
+ public val fill: Color,
+ public val fillDarkest: Color,
+ public val danger: Color,
+ public val dangerDarker: Color,
+)
+
+public val LocalEntePalette: ProvidableCompositionLocal<Palette> = staticCompositionLocalOf {
+ palette(EnteApp.Photos, dark = false)
+}
+
+public object EnteSpacing {
+ public val xl: Dp = 20.dp
+}
+
+public object EnteRadius {
+ public val button: Dp = 20.dp
+}
+
+public object EnteMotion {
+ public const val quick: Int = 120
+}
+
+public object EnteTypography {
+ public val display: TextStyle =
+ TextStyle(
+ fontFamily = EnteFontFamily.outfit,
+ fontSize = 24.sp,
+ fontWeight = FontWeight.SemiBold,
+ lineHeight = 32.sp,
+ )
+ public val body: TextStyle =
+ TextStyle(
+ fontFamily = EnteFontFamily.inter,
+ fontSize = 14.sp,
+ fontWeight = FontWeight.Medium,
+ lineHeight = 20.sp,
+ )
+ public val bodyBold: TextStyle = body.copy(fontWeight = FontWeight.SemiBold)
+}
+
+@Composable
+public fun EnteTheme(
+ app: EnteApp = EnteApp.Photos,
+ darkTheme: Boolean = isSystemInDarkTheme(),
+ content: @Composable () -> Unit,
+) {
+ CompositionLocalProvider(LocalEntePalette provides palette(app, darkTheme), content = content)
+}
+
+private fun palette(app: EnteApp, dark: Boolean): Palette {
+ val (primary, primaryDarker) =
+ when (app) {
+ EnteApp.Photos -> Color(0xFF08C225) to Color(0xFF057C18)
+ EnteApp.Auth -> Color(0xFF9610D6) to Color(0xFF5D0884)
+ EnteApp.Locker -> Color(0xFF1071FF) to Color(0xFF0B4CAD)
+ }
+ return Palette(
+ primary = primary,
+ primaryDarker = primaryDarker,
+ text = if (dark) Color.White else Color.Black,
+ disabledText = Color(if (dark) 0xFF414141 else 0xFFD6D6D6),
+ reverseText = if (dark) Color.Black else Color.White,
+ fill = Color(if (dark) 0xFF0A0A0A else 0xFFEAEAEA),
+ fillDarkest = Color(if (dark) 0xFF292929 else 0xFFD2D2D2),
+ danger = Color(0xFFF63A3A),
+ dangerDarker = Color(0xFFC52E2E),
+ )
+}
diff --git a/android/packages/fonts/src/main/kotlin/io/ente/fonts/EnteFontFamily.kt b/android/packages/fonts/src/main/kotlin/io/ente/fonts/EnteFontFamily.kt
index 30a2a4300e..902a2da391 100644
--- a/android/packages/fonts/src/main/kotlin/io/ente/fonts/EnteFontFamily.kt
+++ b/android/packages/fonts/src/main/kotlin/io/ente/fonts/EnteFontFamily.kt
@@ -7,6 +7,7 @@ import androidx.compose.ui.text.font.FontWeight
public object EnteFontFamily {
public val inter: FontFamily =
FontFamily(
+ Font(R.font.inter_light, FontWeight.Light),
Font(R.font.inter_regular, FontWeight.Normal),
Font(R.font.inter_medium, FontWeight.Medium),
Font(R.font.inter_semibold, FontWeight.SemiBold),
@@ -14,4 +15,6 @@ public object EnteFontFamily {
)
public val montserrat: FontFamily = FontFamily(Font(R.font.montserrat_bold, FontWeight.Bold))
+
+ public val outfit: FontFamily = FontFamily(Font(R.font.outfit_semibold, FontWeight.SemiBold))
}
diff --git a/android/packages/fonts/src/main/res/font/inter_light.ttf b/android/packages/fonts/src/main/res/font/inter_light.ttf
new file mode 100644
index 0000000000..ebaa005740
Binary files /dev/null and b/android/packages/fonts/src/main/res/font/inter_light.ttf differ
diff --git a/android/packages/fonts/src/main/res/font/outfit_semibold.ttf b/android/packages/fonts/src/main/res/font/outfit_semibold.ttf
new file mode 100644
index 0000000000..1f28bda7b8
Binary files /dev/null and b/android/packages/fonts/src/main/res/font/outfit_semibold.ttf differ
diff --git a/android/settings.gradle.kts b/android/settings.gradle.kts
index d4d56428aa..170e3e9b0d 100644
--- a/android/settings.gradle.kts
+++ b/android/settings.gradle.kts
@@ -31,6 +31,10 @@ dependencyResolutionManagement {
rootProject.name = "android"
+include(":components")
+
+project(":components").projectDir = file("packages/components")
+
include(":ensu")
project(":ensu").projectDir = file("apps/ensu")
diff --git a/apple/packages/EnteComponents/Package.swift b/apple/packages/EnteComponents/Package.swift
new file mode 100644
index 0000000000..e1c0a649e5
--- /dev/null
+++ b/apple/packages/EnteComponents/Package.swift
@@ -0,0 +1,13 @@
+// swift-tools-version: 6.0
+
+import PackageDescription
+
+let package = Package(
+ name: "EnteComponents",
+ platforms: [.iOS("15.1"), .tvOS(.v16)],
+ products: [.library(name: "EnteComponents", targets: ["EnteComponents"])],
+ dependencies: [.package(path: "../EnteFonts")],
+ targets: [
+ .target(name: "EnteComponents", dependencies: ["EnteFonts"])
+ ]
+)
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/Actions.swift b/apple/packages/EnteComponents/Sources/EnteComponents/Actions.swift
new file mode 100644
index 0000000000..9a8013fef7
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/Actions.swift
@@ -0,0 +1,107 @@
+import SwiftUI
+
+public enum ActionVariant: Sendable {
+ case primary
+ case secondary
+ case neutral
+ case critical
+ case criticalText
+ case link
+}
+
+public enum ActionDensity: Sendable {
+ case regular
+ case compact
+}
+
+public enum ActionSize: Sendable {
+ case small
+ case large
+}
+
+public struct ActionButton: View {
+ @Environment(\.entePalette) private var palette
+ private let title: String
+ private let variant: ActionVariant
+ private let size: ActionSize
+ private let density: ActionDensity
+ private let enabled: Bool
+ private let action: () -> Void
+
+ public init(
+ _ title: String,
+ variant: ActionVariant = .primary,
+ size: ActionSize = .large,
+ density: ActionDensity = .regular,
+ enabled: Bool = true,
+ action: @escaping () -> Void
+ ) {
+ self.title = title
+ self.variant = variant
+ self.size = size
+ self.density = density
+ self.enabled = enabled
+ self.action = action
+ }
+
+ public var body: some View {
+ let inlineLink = variant == .link && size == .small
+ Button(action: action) {
+ Text(title)
+ .underline(variant == .criticalText || variant == .link)
+ .lineLimit(2)
+ .font(density == .regular ? EnteTypography.bodyBold : EnteTypography.body)
+ .frame(maxWidth: size == .large ? .infinity : nil, minHeight: inlineLink ? nil : 24)
+ .padding(.horizontal, inlineLink ? 0 : EnteSpacing.xl)
+ .padding(.vertical, inlineLink ? 4 : density == .regular ? 14 : 12)
+ }
+ .buttonStyle(
+ ActionStyle(
+ variant: variant,
+ palette: palette,
+ cornerRadius: inlineLink ? 0 : EnteRadius.button
+ )
+ )
+ .disabled(!enabled)
+ }
+}
+
+private struct ActionStyle: ButtonStyle {
+ @Environment(\.isEnabled) private var enabled
+ let variant: ActionVariant
+ let palette: Palette
+ let cornerRadius: CGFloat
+
+ func makeBody(configuration: Configuration) -> some View {
+ configuration.label
+ .foregroundStyle(foreground(pressed: configuration.isPressed))
+ .background(background(pressed: configuration.isPressed))
+ .clipShape(RoundedRectangle(cornerRadius: cornerRadius, style: .continuous))
+ .scaleEffect(configuration.isPressed ? 0.98 : 1)
+ .animation(.easeOut(duration: EnteMotion.quick), value: configuration.isPressed)
+ }
+
+ private func background(pressed: Bool) -> Color {
+ guard enabled else {
+ return variant == .criticalText || variant == .link ? .clear : palette.fill
+ }
+ return switch variant {
+ case .primary: pressed ? palette.primaryDarker : palette.primary
+ case .secondary: pressed ? palette.fillDarkest : palette.fill
+ case .neutral: palette.text
+ case .critical: pressed ? palette.dangerDarker : palette.danger
+ case .criticalText, .link: .clear
+ }
+ }
+
+ private func foreground(pressed: Bool) -> Color {
+ guard enabled else { return palette.disabledText }
+ return switch variant {
+ case .primary, .critical: .white
+ case .secondary: palette.text
+ case .neutral: palette.reverseText
+ case .criticalText: pressed ? palette.dangerDarker : palette.danger
+ case .link: pressed ? palette.primaryDarker : palette.primary
+ }
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/Theme.swift b/apple/packages/EnteComponents/Sources/EnteComponents/Theme.swift
new file mode 100644
index 0000000000..df40ea56b7
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/Theme.swift
@@ -0,0 +1,102 @@
+import EnteFonts
+import SwiftUI
+
+public enum EnteApp: Sendable {
+ case photos
+ case auth
+ case locker
+}
+
+public struct Palette: Sendable {
+ public let primary: Color
+ public let primaryDarker: Color
+ public let text: Color
+ public let disabledText: Color
+ public let reverseText: Color
+ public let fill: Color
+ public let fillDarkest: Color
+ public let danger: Color
+ public let dangerDarker: Color
+
+ fileprivate static func make(app: EnteApp, dark: Bool) -> Palette {
+ let primary: Color
+ let primaryDarker: Color
+ switch app {
+ case .photos:
+ primary = Color(hex: 0x08C225)
+ primaryDarker = Color(hex: 0x057C18)
+ case .auth:
+ primary = Color(hex: 0x9610D6)
+ primaryDarker = Color(hex: 0x5D0884)
+ case .locker:
+ primary = Color(hex: 0x1071FF)
+ primaryDarker = Color(hex: 0x0B4CAD)
+ }
+ return Palette(
+ primary: primary,
+ primaryDarker: primaryDarker,
+ text: dark ? .white : .black,
+ disabledText: Color(hex: dark ? 0x414141 : 0xD6D6D6),
+ reverseText: dark ? .black : .white,
+ fill: Color(hex: dark ? 0x0A0A0A : 0xEAEAEA),
+ fillDarkest: Color(hex: dark ? 0x292929 : 0xD2D2D2),
+ danger: Color(hex: 0xF63A3A),
+ dangerDarker: Color(hex: 0xC52E2E)
+ )
+ }
+}
+
+public enum EnteSpacing {
+ public static let xl: CGFloat = 20
+}
+
+public enum EnteRadius {
+ public static let button: CGFloat = 20
+}
+
+public enum EnteMotion {
+ public static let quick = 0.12
+}
+
+public enum EnteTypography {
+ public static let display = 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 struct EnteTheme<Content: View>: View {
+ @Environment(\.colorScheme) private var colorScheme
+ private let app: EnteApp
+ private let content: Content
+
+ public init(app: EnteApp = .photos, @ViewBuilder content: () -> Content) {
+ self.app = app
+ self.content = content()
+ }
+
+ public var body: some View {
+ let palette = Palette.make(app: app, dark: colorScheme == .dark)
+ content.environment(\.entePalette, palette)
+ }
+}
+
+private struct EntePaletteKey: EnvironmentKey {
+ static let defaultValue = Palette.make(app: .photos, dark: false)
+}
+
+public extension EnvironmentValues {
+ var entePalette: Palette {
+ get { self[EntePaletteKey.self] }
+ set { self[EntePaletteKey.self] = newValue }
+ }
+}
+
+private extension Color {
+ init(hex: UInt) {
+ self.init(
+ red: Double((hex >> 16) & 0xFF) / 255,
+ green: Double((hex >> 8) & 0xFF) / 255,
+ blue: Double(hex & 0xFF) / 255
+ )
+ }
+}
diff --git a/apple/packages/EnteFonts/Package.swift b/apple/packages/EnteFonts/Package.swift
index 96e7a66507..e55d25b66d 100644
--- a/apple/packages/EnteFonts/Package.swift
+++ b/apple/packages/EnteFonts/Package.swift
@@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "EnteFonts",
- platforms: [.iOS("15.1"), .macOS(.v13), .tvOS(.v16)],
+ platforms: [.iOS("15.1"), .tvOS(.v16)],
products: [.library(name: "EnteFonts", targets: ["EnteFonts"])],
targets: [
.target(
diff --git a/apple/packages/EnteFonts/Sources/EnteFonts/EnteFont.swift b/apple/packages/EnteFonts/Sources/EnteFonts/EnteFont.swift
index c0f485d349..736759b123 100644
--- a/apple/packages/EnteFonts/Sources/EnteFonts/EnteFont.swift
+++ b/apple/packages/EnteFonts/Sources/EnteFonts/EnteFont.swift
@@ -1,5 +1,6 @@
import CoreText
import SwiftUI
+import UIKit
public enum EnteFont {
public enum InterWeight {
@@ -47,7 +48,15 @@ public enum EnteFont {
return .custom("Montserrat-Bold", fixedSize: fixedSize)
}
- private static let registration: Void = {
+ public static func outfit(
+ size: CGFloat,
+ relativeTo textStyle: Font.TextStyle = .body
+ ) -> Font {
+ _ = registration
+ return .custom("Outfit-SemiBold", size: size, relativeTo: textStyle)
+ }
+
+ fileprivate static let registration: Void = {
for url in Bundle.module.urls(forResourcesWithExtension: "ttf", subdirectory: nil) ?? [] {
var error: Unmanaged<CFError>?
let registered = CTFontManagerRegisterFontsForURL(url as CFURL, .process, &error)
@@ -59,3 +68,16 @@ public enum EnteFont {
}
}()
}
+
+public extension UIFont {
+ static func inter(
+ size: CGFloat,
+ weight: EnteFont.InterWeight = .regular,
+ relativeTo textStyle: UIFont.TextStyle = .body
+ ) -> UIFont {
+ _ = EnteFont.registration
+ let descriptor = UIFontDescriptor(name: weight.name, size: size)
+ let font = UIFont(descriptor: descriptor, size: size)
+ return UIFontMetrics(forTextStyle: textStyle).scaledFont(for: font)
+ }
+}
diff --git a/apple/packages/EnteFonts/Sources/EnteFonts/Resources/Outfit-SemiBold.ttf b/apple/packages/EnteFonts/Sources/EnteFonts/Resources/Outfit-SemiBold.ttf
new file mode 100644
index 0000000000..1f28bda7b8
Binary files /dev/null and b/apple/packages/EnteFonts/Sources/EnteFonts/Resources/Outfit-SemiBold.ttf differ