Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add section headers and thumbnail components

Neeraj Gupta7f9523195131
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/SectionHeader.kt b/android/packages/components/src/main/kotlin/io/ente/components/SectionHeader.kt
new file mode 100644
index 0000000000..146220c362
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/SectionHeader.kt
@@ -0,0 +1,61 @@
+package io.ente.components
+
+import androidx.compose.foundation.clickable
+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.size
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
+import androidx.compose.material3.Icon
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.semantics.heading
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+
+@Composable
+public fun SectionHeader(
+ title: String,
+ modifier: Modifier = Modifier,
+ enabled: Boolean = true,
+ onClick: (() -> Unit)? = null,
+) {
+ val palette = LocalEntePalette.current
+ Row(
+ modifier
+ .fillMaxWidth()
+ .heightIn(min = 48.dp)
+ .then(
+ if (onClick == null) Modifier
+ else Modifier.clickable(enabled = enabled, role = Role.Button, onClick = onClick)
+ )
+ .semantics(mergeDescendants = true) { heading() },
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Text(
+ title,
+ Modifier.weight(1f),
+ style = sectionTitleStyle,
+ color = if (enabled) palette.text else palette.disabledText,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
+ if (onClick != null) {
+ Icon(
+ Icons.AutoMirrored.Filled.KeyboardArrowRight,
+ null,
+ Modifier.size(38.dp).padding(7.dp),
+ tint = if (enabled) palette.mutedText else palette.disabledText,
+ )
+ }
+ }
+}
+
+private val sectionTitleStyle = EnteTypography.display2.copy(fontSize = 20.sp, lineHeight = 28.sp)
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/Thumbnails.kt b/android/packages/components/src/main/kotlin/io/ente/components/Thumbnails.kt
new file mode 100644
index 0000000000..0b210e5688
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/Thumbnails.kt
@@ -0,0 +1,132 @@
+package io.ente.components
+
+import androidx.compose.animation.animateColorAsState
+import androidx.compose.animation.core.tween
+import androidx.compose.foundation.background
+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.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.aspectRatio
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.LocalContentColor
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+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.clip
+import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.semantics.clearAndSetSemantics
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.dp
+
+@Composable
+public fun ThumbnailTile(
+ title: String,
+ onClick: () -> Unit,
+ modifier: Modifier = Modifier,
+ subtitle: String? = null,
+ titleLines: Int = 2,
+ enabled: Boolean = true,
+ cover: @Composable () -> Unit,
+) {
+ val palette = LocalEntePalette.current
+ Column(
+ modifier.clickable(enabled = enabled, role = Role.Button, onClick = onClick),
+ verticalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ Box(
+ Modifier.fillMaxWidth()
+ .aspectRatio(1f)
+ .clip(RoundedCornerShape(EnteRadius.button))
+ .background(palette.fill)
+ .clearAndSetSemantics {}
+ ) {
+ cover()
+ }
+ ThumbnailCaption(title, subtitle, titleLines, enabled)
+ }
+}
+
+@Composable
+public fun ThumbnailRow(
+ title: String,
+ onClick: () -> Unit,
+ modifier: Modifier = Modifier,
+ subtitle: String? = null,
+ enabled: Boolean = true,
+ trailing: @Composable (() -> Unit)? = null,
+ cover: @Composable () -> Unit,
+) {
+ val palette = LocalEntePalette.current
+ val interactionSource = remember { MutableInteractionSource() }
+ val pressed by interactionSource.collectIsPressedAsState()
+ val background by
+ animateColorAsState(
+ targetValue = if (pressed && enabled) palette.fillDarker else palette.surface,
+ animationSpec = tween(EnteMotion.quick),
+ label = "thumbnailRowBackground",
+ )
+ Row(
+ modifier
+ .fillMaxWidth()
+ .clip(RoundedCornerShape(EnteRadius.button))
+ .background(background)
+ .clickable(
+ enabled = enabled,
+ role = Role.Button,
+ interactionSource = interactionSource,
+ indication = null,
+ onClick = onClick,
+ )
+ .padding(8.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(EnteSpacing.md),
+ ) {
+ Box(
+ Modifier.size(52.dp)
+ .clip(RoundedCornerShape(EnteRadius.medium))
+ .background(palette.fill)
+ .clearAndSetSemantics {},
+ contentAlignment = Alignment.Center,
+ ) {
+ cover()
+ }
+ Box(Modifier.weight(1f)) { ThumbnailCaption(title, subtitle, 1, enabled) }
+ if (trailing != null) {
+ CompositionLocalProvider(LocalContentColor provides palette.mutedText) { trailing() }
+ }
+ }
+}
+
+@Composable
+private fun ThumbnailCaption(title: String, subtitle: String?, titleLines: Int, enabled: Boolean) {
+ val palette = LocalEntePalette.current
+ Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
+ Text(
+ title,
+ style = EnteTypography.body,
+ color = if (enabled) palette.text else palette.disabledText,
+ maxLines = titleLines,
+ overflow = TextOverflow.Ellipsis,
+ )
+ if (!subtitle.isNullOrEmpty()) {
+ Text(
+ subtitle,
+ style = EnteTypography.mini,
+ color = palette.mutedText,
+ maxLines = 2,
+ overflow = TextOverflow.Ellipsis,
+ )
+ }
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/SectionHeader.swift b/apple/packages/EnteComponents/Sources/EnteComponents/SectionHeader.swift
new file mode 100644
index 0000000000..81e807d468
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/SectionHeader.swift
@@ -0,0 +1,45 @@
+import EnteFonts
+import SwiftUI
+
+public struct SectionHeader: View {
+ @Environment(\.entePalette) private var palette
+ @Environment(\.isEnabled) private var enabled
+ private let title: String
+ private let action: (() -> Void)?
+
+ public init(_ title: String, action: (() -> Void)? = nil) {
+ self.title = title
+ self.action = action
+ }
+
+ public var body: some View {
+ Group {
+ if let action {
+ Button(action: action) { content }
+ .buttonStyle(.plain)
+ } else {
+ content
+ }
+ }
+ .accessibilityAddTraits(.isHeader)
+ }
+
+ private var content: some View {
+ HStack(spacing: 0) {
+ Text(title)
+ .font(EnteFont.outfit(size: 20, relativeTo: .title2))
+ .foregroundStyle(enabled ? palette.text : palette.disabledText)
+ .lineLimit(1)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ if action != nil {
+ Image(systemName: "chevron.forward")
+ .font(.system(size: 18))
+ .frame(width: 38, height: 38)
+ .foregroundStyle(enabled ? palette.mutedText : palette.disabledText)
+ .accessibilityHidden(true)
+ }
+ }
+ .frame(minHeight: 44)
+ .contentShape(Rectangle())
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/Thumbnails.swift b/apple/packages/EnteComponents/Sources/EnteComponents/Thumbnails.swift
new file mode 100644
index 0000000000..0264e3226a
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/Thumbnails.swift
@@ -0,0 +1,121 @@
+import SwiftUI
+
+public struct ThumbnailTile<Cover: View>: View {
+ @Environment(\.entePalette) private var palette
+ private let title: String
+ private let subtitle: String?
+ private let titleLines: Int
+ private let action: () -> Void
+ private let cover: Cover
+
+ public init(
+ _ title: String,
+ subtitle: String? = nil,
+ titleLines: Int = 2,
+ action: @escaping () -> Void,
+ @ViewBuilder cover: () -> Cover
+ ) {
+ self.title = title
+ self.subtitle = subtitle
+ self.titleLines = titleLines
+ self.action = action
+ self.cover = cover()
+ }
+
+ public var body: some View {
+ Button(action: action) {
+ VStack(alignment: .leading, spacing: 8) {
+ palette.fill
+ .aspectRatio(1, contentMode: .fit)
+ .overlay { cover }
+ .clipShape(
+ RoundedRectangle(cornerRadius: EnteRadius.button, style: .continuous)
+ )
+ .accessibilityHidden(true)
+ ThumbnailCaption(title: title, subtitle: subtitle, titleLines: titleLines)
+ }
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .contentShape(Rectangle())
+ }
+ .buttonStyle(.plain)
+ }
+}
+
+public struct ThumbnailRow<Cover: View, Trailing: View>: View {
+ @Environment(\.entePalette) private var palette
+ private let title: String
+ private let subtitle: String?
+ private let action: () -> Void
+ private let cover: Cover
+ private let trailing: Trailing
+
+ public init(
+ _ title: String,
+ subtitle: String? = nil,
+ action: @escaping () -> Void,
+ @ViewBuilder trailing: () -> Trailing = { EmptyView() },
+ @ViewBuilder cover: () -> Cover
+ ) {
+ self.title = title
+ self.subtitle = subtitle
+ self.action = action
+ self.cover = cover()
+ self.trailing = trailing()
+ }
+
+ public var body: some View {
+ Button(action: action) {
+ HStack(spacing: EnteSpacing.md) {
+ palette.fill
+ .frame(width: 52, height: 52)
+ .overlay { cover }
+ .clipShape(
+ RoundedRectangle(cornerRadius: EnteRadius.medium, style: .continuous)
+ )
+ .accessibilityHidden(true)
+ ThumbnailCaption(title: title, subtitle: subtitle, titleLines: 1)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ trailing.foregroundStyle(palette.mutedText)
+ }
+ .padding(8)
+ .contentShape(RoundedRectangle(cornerRadius: EnteRadius.button, style: .continuous))
+ }
+ .buttonStyle(ThumbnailRowStyle())
+ }
+}
+
+private struct ThumbnailRowStyle: ButtonStyle {
+ @Environment(\.entePalette) private var palette
+
+ func makeBody(configuration: Configuration) -> some View {
+ configuration.label
+ .background(
+ configuration.isPressed ? palette.fillDarker : palette.surface,
+ in: RoundedRectangle(cornerRadius: EnteRadius.button, style: .continuous)
+ )
+ .animation(.easeOut(duration: EnteMotion.quick), value: configuration.isPressed)
+ }
+}
+
+private struct ThumbnailCaption: View {
+ @Environment(\.entePalette) private var palette
+ @Environment(\.isEnabled) private var enabled
+ let title: String
+ let subtitle: String?
+ let titleLines: Int
+
+ var body: some View {
+ VStack(alignment: .leading, spacing: 2) {
+ Text(title)
+ .font(EnteTypography.body)
+ .foregroundStyle(enabled ? palette.text : palette.disabledText)
+ .lineLimit(titleLines)
+ if let subtitle, !subtitle.isEmpty {
+ Text(subtitle)
+ .font(EnteTypography.mini)
+ .foregroundStyle(palette.mutedText)
+ .lineLimit(2)
+ }
+ }
+ }
+}