Skip to content

Commit 5e46816

Browse files
committed
migrate demo app to material3
1 parent a37da12 commit 5e46816

7 files changed

Lines changed: 37 additions & 34 deletions

File tree

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies {
3434
implementation(libs.androidx.appcompat)
3535
implementation(libs.material)
3636
implementation(libs.androidx.compose.ui)
37-
implementation(libs.androidx.compose.material)
37+
implementation(libs.androidx.compose.material3)
3838
implementation(libs.androidx.lifecycle.runtime.ktx)
3939
implementation(libs.androidx.activity.compose)
4040

app/src/main/java/de/markusressel/kodeeditor/demo/ComposeMainActivity.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import androidx.compose.foundation.BorderStroke
88
import androidx.compose.foundation.background
99
import androidx.compose.foundation.border
1010
import androidx.compose.foundation.layout.*
11-
import androidx.compose.material.Button
12-
import androidx.compose.material.MaterialTheme
13-
import androidx.compose.material.Text
11+
import androidx.compose.material3.Button
12+
import androidx.compose.material3.LocalTextStyle
13+
import androidx.compose.material3.MaterialTheme
14+
import androidx.compose.material3.Text
1415
import androidx.compose.runtime.*
1516
import androidx.compose.runtime.saveable.rememberSaveable
1617
import androidx.compose.ui.Alignment
1718
import androidx.compose.ui.Modifier
18-
import androidx.compose.ui.text.TextStyle
19+
import androidx.compose.ui.text.font.FontFamily
1920
import androidx.compose.ui.text.input.TextFieldValue
2021
import androidx.compose.ui.tooling.preview.Preview
2122
import androidx.compose.ui.unit.dp
22-
import androidx.compose.ui.unit.sp
2323
import de.markusressel.kodeeditor.demo.ui.theme.KodeEditorTheme
2424
import de.markusressel.kodeeditor.library.compose.KodeEditor
2525
import de.markusressel.kodeeditor.library.compose.KodeEditorDefaults
@@ -36,7 +36,7 @@ class ComposeMainActivity : ComponentActivity() {
3636
}
3737

3838
Column(
39-
modifier = Modifier.background(MaterialTheme.colors.background),
39+
modifier = Modifier.background(MaterialTheme.colorScheme.background),
4040
) {
4141
KodeEditorConfigurationMenu(
4242
currentFontSize = currentFontSize,
@@ -53,13 +53,14 @@ class ComposeMainActivity : ComponentActivity() {
5353
KodeEditor(
5454
modifier = Modifier
5555
.fillMaxSize()
56-
.border(BorderStroke(1.dp, MaterialTheme.colors.primary)),
56+
.border(BorderStroke(1.dp, MaterialTheme.colorScheme.primary)),
5757
languageRuleBook = MarkdownRuleBook(),
5858
colorScheme = DarkBackgroundColorSchemeWithSpanStyle(),
5959
text = text,
6060
onValueChange = { text = it },
61-
textStyle = TextStyle(fontSize = currentFontSize.sp).copy(
62-
color = MaterialTheme.colors.onSurface,
61+
textStyle = LocalTextStyle.current.copy(
62+
color = MaterialTheme.colorScheme.onSurface,
63+
fontFamily = FontFamily.Monospace,
6364
),
6465
colors = KodeEditorDefaults.editorColors()
6566
)
@@ -84,13 +85,13 @@ class ComposeMainActivity : ComponentActivity() {
8485
Text(
8586
modifier = Modifier.weight(1f),
8687
text = "Font Size: $currentFontSize",
87-
color = MaterialTheme.colors.onSurface,
88+
color = MaterialTheme.colorScheme.onSurface,
8889
)
8990

9091
Button(onClick = onIncreaseFontSize) {
9192
Text(
9293
text = "+",
93-
color = MaterialTheme.colors.onPrimary,
94+
color = MaterialTheme.colorScheme.onPrimary,
9495
)
9596
}
9697

@@ -99,7 +100,7 @@ class ComposeMainActivity : ComponentActivity() {
99100
Button(onClick = onDecreaseFontSize) {
100101
Text(
101102
text = "-",
102-
color = MaterialTheme.colors.onPrimary,
103+
color = MaterialTheme.colorScheme.onPrimary,
103104
)
104105
}
105106
}

app/src/main/java/de/markusressel/kodeeditor/demo/ui/theme/Shape.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package de.markusressel.kodeeditor.demo.ui.theme
22

33
import androidx.compose.foundation.shape.RoundedCornerShape
4-
import androidx.compose.material.Shapes
4+
import androidx.compose.material3.Shapes
55
import androidx.compose.ui.unit.dp
66

77
val Shapes = Shapes(
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
package de.markusressel.kodeeditor.demo.ui.theme
22

33
import androidx.compose.foundation.isSystemInDarkTheme
4-
import androidx.compose.material.MaterialTheme
5-
import androidx.compose.material.darkColors
6-
import androidx.compose.material.lightColors
4+
import androidx.compose.material3.MaterialTheme
5+
import androidx.compose.material3.darkColorScheme
6+
import androidx.compose.material3.lightColorScheme
77
import androidx.compose.runtime.Composable
88

9-
private val DarkColorPalette = darkColors(
10-
primary = Purple200,
11-
primaryVariant = Purple700,
12-
secondary = Teal200
9+
private val DarkColorPalette = darkColorScheme(
10+
primary = Purple200,
11+
primaryContainer = Purple700,
12+
secondary = Teal200
1313
)
1414

15-
private val LightColorPalette = lightColors(
16-
primary = Purple500,
17-
primaryVariant = Purple700,
18-
secondary = Teal200
15+
private val LightColorPalette = lightColorScheme(
16+
primary = Purple500,
17+
primaryContainer = Purple700,
18+
secondary = Teal200
1919

20-
/* Other default colors to override
20+
/* Other default colors to override
2121
background = Color.White,
2222
surface = Color.White,
2323
onPrimary = Color.White,
@@ -36,9 +36,9 @@ fun KodeEditorTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Compos
3636
}
3737

3838
MaterialTheme(
39-
colors = colors,
40-
typography = Typography,
41-
shapes = Shapes,
42-
content = content
39+
colorScheme = colors,
40+
// typography = Typography,
41+
// shapes = Shapes,
42+
content = content
4343
)
4444
}

app/src/main/java/de/markusressel/kodeeditor/demo/ui/theme/Type.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package de.markusressel.kodeeditor.demo.ui.theme
22

3-
import androidx.compose.material.Typography
3+
import androidx.compose.material3.Typography
44
import androidx.compose.ui.text.TextStyle
55
import androidx.compose.ui.text.font.FontFamily
66
import androidx.compose.ui.text.font.FontWeight
77
import androidx.compose.ui.unit.sp
88

99
// Set of Material typography styles to start with
1010
val Typography = Typography(
11-
body1 = TextStyle(
11+
bodyMedium = TextStyle(
1212
fontFamily = FontFamily.Default,
1313
fontWeight = FontWeight.Normal,
1414
fontSize = 16.sp

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[versions]
22
activityCompose = "1.10.1"
3+
androidComposeMaterial3 = "1.3.2"
34
androidDesugarJdkLibs = "2.1.5"
45
androidGradlePlugin = "8.12.2"
56
androidxAnnotation = "1.9.1"
@@ -36,6 +37,7 @@ androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", versi
3637
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui", version.ref = "androidxComposeUi" }
3738
androidx-compose-ui-text = { group = "androidx.compose.ui", name = "ui-text", version.ref = "androidxComposeUiText" }
3839
androidx-compose-material = { group = "androidx.compose.material", name = "material", version.ref = "androidxComposeUiText" }
40+
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "androidComposeMaterial3" }
3941
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
4042
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
4143

library/src/main/java/de/markusressel/kodeeditor/library/compose/KodeEditor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ fun KodeEditor(
5656
readOnly: Boolean = enabled.not(),
5757
) {
5858
var offset by remember { mutableStateOf(Offset.Zero) }
59-
var zoom by remember { mutableStateOf(1f) }
59+
var zoom by remember { mutableFloatStateOf(1f) }
6060

6161
Box(modifier = Modifier
6262
.clipToBounds()
6363
.then(modifier)
6464
) {
6565
var lineNumberWidth by remember {
66-
mutableStateOf(0)
66+
mutableIntStateOf(0)
6767
}
6868
LineNumbers(
6969
modifier = Modifier

0 commit comments

Comments
 (0)