Skip to content

Commit f954cda

Browse files
authored
Merge pull request #21 from Kotlin/edge-to-edge
Enable edge-to-edge
2 parents b899e54 + 93de3cc commit f954cda

File tree

6 files changed

+31
-16
lines changed

6 files changed

+31
-16
lines changed

composeApp/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ kotlin {
5959

6060
android {
6161
namespace = "com.jetbrains.kmpapp"
62-
compileSdk = 34
62+
compileSdk = 35
6363

6464
defaultConfig {
6565
applicationId = "com.jetbrains.kmpapp"
6666
minSdk = 24
67-
targetSdk = 34
67+
targetSdk = 35
6868
versionCode = 1
6969
versionName = "1.0"
7070
}

composeApp/src/androidMain/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
android:theme="@android:style/Theme.Material.Light.NoActionBar">
1414
<activity
1515
android:exported="true"
16+
android:windowSoftInputMode="adjustResize"
1617
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|layoutDirection|locale|mcc|navigation|smallestScreenSize|touchscreen|uiMode"
1718
android:name=".MainActivity">
1819
<intent-filter>

composeApp/src/androidMain/kotlin/com/jetbrains/kmpapp/MainActivity.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ package com.jetbrains.kmpapp
33
import android.os.Bundle
44
import androidx.activity.ComponentActivity
55
import androidx.activity.compose.setContent
6-
import androidx.compose.runtime.Composable
7-
import androidx.compose.ui.tooling.preview.Preview
6+
import androidx.activity.enableEdgeToEdge
7+
import androidx.compose.foundation.isSystemInDarkTheme
8+
import androidx.compose.runtime.LaunchedEffect
89

910
class MainActivity : ComponentActivity() {
1011
override fun onCreate(savedInstanceState: Bundle?) {
1112
super.onCreate(savedInstanceState)
12-
13+
enableEdgeToEdge()
1314
setContent {
15+
// Remove when https://issuetracker.google.com/issues/364713509 is fixed
16+
LaunchedEffect(isSystemInDarkTheme()) {
17+
enableEdgeToEdge()
18+
}
1419
App()
1520
}
1621
}
1722
}
18-
19-
@Preview
20-
@Composable
21-
fun AppAndroidPreview() {
22-
App()
23-
}

composeApp/src/commonMain/kotlin/com/jetbrains/kmpapp/screens/detail/DetailScreen.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import androidx.compose.animation.AnimatedContent
44
import androidx.compose.foundation.background
55
import androidx.compose.foundation.layout.Column
66
import androidx.compose.foundation.layout.Spacer
7+
import androidx.compose.foundation.layout.WindowInsets
78
import androidx.compose.foundation.layout.fillMaxSize
89
import androidx.compose.foundation.layout.fillMaxWidth
910
import androidx.compose.foundation.layout.height
1011
import androidx.compose.foundation.layout.padding
12+
import androidx.compose.foundation.layout.systemBars
13+
import androidx.compose.foundation.layout.windowInsetsPadding
1114
import androidx.compose.foundation.rememberScrollState
1215
import androidx.compose.foundation.text.selection.SelectionContainer
1316
import androidx.compose.foundation.verticalScroll
@@ -81,7 +84,7 @@ private fun ObjectDetails(
8184
}
8285
}
8386
},
84-
modifier = modifier,
87+
modifier = modifier.windowInsetsPadding(WindowInsets.systemBars),
8588
) { paddingValues ->
8689
Column(
8790
Modifier

composeApp/src/commonMain/kotlin/com/jetbrains/kmpapp/screens/list/ListScreen.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ import androidx.compose.animation.AnimatedContent
44
import androidx.compose.foundation.background
55
import androidx.compose.foundation.clickable
66
import androidx.compose.foundation.layout.Column
7-
import androidx.compose.foundation.layout.PaddingValues
87
import androidx.compose.foundation.layout.Spacer
8+
import androidx.compose.foundation.layout.WindowInsets
9+
import androidx.compose.foundation.layout.WindowInsetsSides
10+
import androidx.compose.foundation.layout.asPaddingValues
911
import androidx.compose.foundation.layout.aspectRatio
1012
import androidx.compose.foundation.layout.fillMaxSize
1113
import androidx.compose.foundation.layout.fillMaxWidth
1214
import androidx.compose.foundation.layout.height
15+
import androidx.compose.foundation.layout.only
1316
import androidx.compose.foundation.layout.padding
17+
import androidx.compose.foundation.layout.safeDrawing
1418
import androidx.compose.foundation.lazy.grid.GridCells
1519
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
1620
import androidx.compose.foundation.lazy.grid.items
@@ -65,8 +69,16 @@ private fun ObjectGrid(
6569
) {
6670
LazyVerticalGrid(
6771
columns = GridCells.Adaptive(180.dp),
68-
modifier = modifier.fillMaxSize(),
69-
contentPadding = PaddingValues(8.dp)
72+
// TODO simplify padding after https://issuetracker.google.com/issues/365052672 is fixed
73+
modifier = modifier.fillMaxSize()
74+
.padding(
75+
WindowInsets.safeDrawing
76+
.only(WindowInsetsSides.Start + WindowInsetsSides.End)
77+
.asPaddingValues()
78+
),
79+
contentPadding = WindowInsets.safeDrawing
80+
.only(WindowInsetsSides.Bottom + WindowInsetsSides.Top)
81+
.asPaddingValues(),
7082
) {
7183
items(objects, key = { it.objectID }) { obj ->
7284
ObjectFrame(

iosApp/iosApp/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ struct ComposeView: UIViewControllerRepresentable {
1313
struct ContentView: View {
1414
var body: some View {
1515
ComposeView()
16-
.ignoresSafeArea(.keyboard) // Compose has own keyboard handler
16+
.ignoresSafeArea()
1717
}
1818
}

0 commit comments

Comments
 (0)