-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Feat: Migrate About screen to Jetpack Compose with Material 3 #6791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6a79c27
74c0c89
038d8c9
14e7c0f
d0bb8e9
fe4fc33
b5a0741
35cef74
34680c2
ad4feb5
e5207d2
4f2ba74
1a4ad3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package fr.free.nrw.commons.theme | ||
|
|
||
| import androidx.compose.ui.graphics.Color | ||
|
|
||
| val PrimaryBlue = Color(0xFF0C609C) | ||
| val PrimaryBlueNight = Color(0xFF1E8CAB) | ||
| val BackgroundLight = Color(0xFFFAFAFA) | ||
| val BackgroundDark = Color(0xFF303030) | ||
| val CardBackgroundDark = Color(0xFF1E1E1E) | ||
| val CardBackgroundLight = Color(0xFFFFFFFF) | ||
| val TextWhite = Color(0xFFFFFFFF) | ||
| val TextBlack = Color(0xFF000000) | ||
| val Transparent = Color.Transparent |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package fr.free.nrw.commons.theme | ||
|
|
||
| import androidx.compose.foundation.isSystemInDarkTheme | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.material3.* | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
|
|
||
| @Composable | ||
| fun CommonsTheme(content: @Composable () -> Unit) { | ||
| val isDarkTheme = isSystemInDarkTheme() | ||
| val colorScheme = if (isDarkTheme) { | ||
| darkColorScheme( | ||
| primary = PrimaryBlueNight, | ||
| background = BackgroundDark, | ||
| onBackground = TextWhite, | ||
| surfaceVariant = CardBackgroundDark, | ||
| onSurface = TextWhite | ||
| ) | ||
| } else { | ||
| lightColorScheme( | ||
| primary = PrimaryBlue, | ||
| background = BackgroundLight, | ||
| onBackground = TextBlack, | ||
| surfaceVariant = CardBackgroundLight, | ||
| onSurface = TextBlack | ||
| ) | ||
| } | ||
|
|
||
| MaterialTheme(colorScheme = colorScheme) { | ||
| Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) { | ||
| content() | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package fr.free.nrw.commons.theme | ||
|
|
||
| import androidx.compose.ui.unit.dp | ||
|
|
||
| object Spacing { | ||
| val none = 0.dp | ||
| val extraSmall = 4.dp | ||
| val small = 8.dp | ||
| val medium = 16.dp | ||
| val large = 20.dp | ||
| val extraLarge = 24.dp | ||
| val huge = 32.dp | ||
| val gigantic = 48.dp | ||
| } | ||
|
|
||
| object Dimensions { | ||
| val logoSize = 110.dp | ||
| val socialIconBox = 52.dp | ||
| val socialIcon = 28.dp | ||
| val linkIcon = 20.dp | ||
| val cardCorner = 16.dp | ||
| val cardElevation = 2.dp | ||
| val dividerThickness = 0.5.dp | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package fr.free.nrw.commons.theme | ||
|
|
||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.text.AnnotatedString | ||
| import androidx.compose.ui.text.TextStyle | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.text.style.TextAlign | ||
| import androidx.compose.ui.text.style.TextOverflow | ||
| import androidx.compose.ui.unit.sp | ||
|
|
||
| enum class CommonsTextPreset { Headline, Title, Body, Caption } | ||
|
|
||
| @Composable | ||
| fun CommonsText( | ||
| text: String, | ||
| preset: CommonsTextPreset, | ||
| modifier: Modifier = Modifier, | ||
| color: Color = Color.Unspecified, | ||
| textAlign: TextAlign? = null, | ||
| maxLines: Int = Int.MAX_VALUE, | ||
| overflow: TextOverflow = TextOverflow.Clip, | ||
| fontWeight: FontWeight? = null | ||
| ) { | ||
| CommonsText(AnnotatedString(text), preset, modifier, color, textAlign, maxLines, overflow, fontWeight) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a recursion function call. Why can't we pass But for now I would recommned let's use the Text directly and have a separate PR that focuses on design tokens and Codex colour, as said by @RitikaPahwa4444, #6791 (comment). Feel free to have a ToDo that says that once the component is made, it takes it from there something. |
||
| } | ||
|
|
||
| @Composable | ||
| fun CommonsText( | ||
| text: AnnotatedString, | ||
| preset: CommonsTextPreset, | ||
| modifier: Modifier = Modifier, | ||
| color: Color = Color.Unspecified, | ||
| textAlign: TextAlign? = null, | ||
| maxLines: Int = Int.MAX_VALUE, | ||
| overflow: TextOverflow = TextOverflow.Clip, | ||
| fontWeight: FontWeight? = null | ||
| ) { | ||
| val style = when (preset) { | ||
| CommonsTextPreset.Headline -> TextStyle(fontSize = 24.sp, fontWeight = fontWeight ?: FontWeight.Bold) | ||
| CommonsTextPreset.Title -> TextStyle(fontSize = 20.sp, fontWeight = fontWeight ?: FontWeight.Medium) | ||
| CommonsTextPreset.Body -> TextStyle(fontSize = 16.sp, fontWeight = fontWeight ?: FontWeight.Normal) | ||
| CommonsTextPreset.Caption -> TextStyle(fontSize = 14.sp, fontWeight = fontWeight ?: FontWeight.Normal) | ||
| } | ||
| Text( | ||
| text = text, | ||
| modifier = modifier, | ||
| style = style, | ||
| color = if (color == Color.Unspecified) MaterialTheme.colorScheme.onBackground else color, | ||
| textAlign = textAlign, | ||
| maxLines = maxLines, | ||
| overflow = overflow | ||
| ) | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure what's the use of this? I am not sure this is gonna be reused somewhere?
The below makes sense, but having an object for this, I am not sure it's needed. Open for suggestions over here :-)
val cardCorner = 16.dp
val cardElevation = 2.dp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://developer.android.com/develop/ui/compose/designsystems
The documentation is really good for anyone who wants to dive deeper 🙂