Skip to content
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

Migrate Compose sample to Material 3. #2548

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ kotlin {
implementation(projects.samples.shared)
implementation(projects.coilCompose)
implementation(compose.components.resources)
implementation(compose.material)
implementation(compose.material3)
}
resources.srcDir("../shared/src/commonMain/resources")
}
Expand Down
12 changes: 0 additions & 12 deletions samples/compose/src/androidMain/res/values/styles.xml

This file was deleted.

44 changes: 28 additions & 16 deletions samples/compose/src/commonMain/kotlin/sample/compose/App.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sample.compose

import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
Expand All @@ -10,15 +11,17 @@ import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
import androidx.compose.foundation.lazy.staggeredgrid.items
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.lightColors
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.Stable
Expand Down Expand Up @@ -74,10 +77,16 @@ fun App(
}

MaterialTheme(
colors = lightColors(
primary = Color.White,
onPrimary = Color.Black,
),
colorScheme = if (isSystemInDarkTheme()) {
remember {
darkColorScheme(
background = Color(0xFF141218),
surface = Color(0xFF121212),
)
}
} else {
remember { lightColorScheme() }
},
) {
val screen by viewModel.screen.collectAsState()
val isDetail = screen is Screen.Detail
Expand Down Expand Up @@ -110,6 +119,7 @@ fun App(
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun Toolbar(
assetType: AssetType,
Expand All @@ -119,11 +129,13 @@ private fun Toolbar(
onBackPressed: () -> Unit,
) {
TopAppBar(
title = { Text(Title) },
navigationIcon = if (backEnabled) {
{ BackIconButton(onBackPressed) }
} else {
null
title = {
Text(Title)
},
navigationIcon = {
if (backEnabled) {
BackIconButton(onBackPressed)
}
},
actions = {
IconButton(
Expand Down
12 changes: 0 additions & 12 deletions samples/compose/src/desktopMain/kotlin/sample/compose/App.jvm.kt

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions samples/compose/src/iosX64Main/kotlin/sample/compose/App.iosX64.kt

This file was deleted.

12 changes: 0 additions & 12 deletions samples/compose/src/jsMain/kotlin/sample/compose/App.js.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ package sample.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.unit.IntSize

@Stable
actual fun Modifier.testTagsAsResourceId(enable: Boolean): Modifier {
// Only supported on Android.
return this
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
actual fun containerSize(): IntSize {
return LocalWindowInfo.current.containerSize
}

@Composable
actual fun BackHandler(
enabled: Boolean,
Expand Down
12 changes: 0 additions & 12 deletions samples/compose/src/wasmJsMain/kotlin/sample/compose/App.wasmJs.kt

This file was deleted.

1 change: 1 addition & 0 deletions samples/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ kotlin {
api(projects.coilVideo)
api(libs.androidx.core)
api(libs.androidx.lifecycle.viewmodel)
api(libs.google.material)
}
}
appleMain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<item name="colorPrimaryDark">#121212</item>
<item name="colorAccent">#121212</item>

<item name="android:statusBarColor">#00000000</item>
<item name="android:statusBarColor">#121212</item>
</style>

<style name="AppTheme" parent="AppTheme.v21"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<resources>

<style name="AppTheme.v23" parent="AppTheme.v21">
<item name="colorPrimary">#FFF</item>
<item name="colorPrimaryDark">#FFF</item>
<item name="colorAccent">#CCC</item>

<item name="android:statusBarColor">#00000000</item>
<item name="android:windowLightStatusBar">true</item>
</style>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

<style name="AppTheme.v21" parent="Theme.Material3.DayNight.NoActionBar">
<item name="colorPrimary">#FFF</item>
<item name="colorPrimaryDark">#AAA</item>
<item name="colorAccent">#CCC</item>
<item name="colorPrimaryDark">#FFF</item>
<item name="colorAccent">#FFF</item>

<item name="android:statusBarColor">#FFF</item>
</style>

<style name="AppTheme" parent="AppTheme.v21"/>
Expand Down
1 change: 0 additions & 1 deletion samples/view/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ dependencies {
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.recyclerview)
implementation(libs.google.material)
}
9 changes: 0 additions & 9 deletions samples/view/src/main/res/values-night-v29/styles.xml

This file was deleted.

9 changes: 0 additions & 9 deletions samples/view/src/main/res/values-v29/styles.xml

This file was deleted.