Skip to content

Commit

Permalink
Merge pull request #21 from Kotlin/edge-to-edge
Browse files Browse the repository at this point in the history
Enable edge-to-edge
  • Loading branch information
zsmb13 authored Sep 12, 2024
2 parents b899e54 + 93de3cc commit f954cda
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ kotlin {

android {
namespace = "com.jetbrains.kmpapp"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "com.jetbrains.kmpapp"
minSdk = 24
targetSdk = 34
targetSdk = 35
versionCode = 1
versionName = "1.0"
}
Expand Down
1 change: 1 addition & 0 deletions composeApp/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
android:theme="@android:style/Theme.Material.Light.NoActionBar">
<activity
android:exported="true"
android:windowSoftInputMode="adjustResize"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|layoutDirection|locale|mcc|navigation|smallestScreenSize|touchscreen|uiMode"
android:name=".MainActivity">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ package com.jetbrains.kmpapp
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.LaunchedEffect

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enableEdgeToEdge()
setContent {
// Remove when https://issuetracker.google.com/issues/364713509 is fixed
LaunchedEffect(isSystemInDarkTheme()) {
enableEdgeToEdge()
}
App()
}
}
}

@Preview
@Composable
fun AppAndroidPreview() {
App()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.foundation.verticalScroll
Expand Down Expand Up @@ -81,7 +84,7 @@ private fun ObjectDetails(
}
}
},
modifier = modifier,
modifier = modifier.windowInsetsPadding(WindowInsets.systemBars),
) { paddingValues ->
Column(
Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
Expand Down Expand Up @@ -65,8 +69,16 @@ private fun ObjectGrid(
) {
LazyVerticalGrid(
columns = GridCells.Adaptive(180.dp),
modifier = modifier.fillMaxSize(),
contentPadding = PaddingValues(8.dp)
// TODO simplify padding after https://issuetracker.google.com/issues/365052672 is fixed
modifier = modifier.fillMaxSize()
.padding(
WindowInsets.safeDrawing
.only(WindowInsetsSides.Start + WindowInsetsSides.End)
.asPaddingValues()
),
contentPadding = WindowInsets.safeDrawing
.only(WindowInsetsSides.Bottom + WindowInsetsSides.Top)
.asPaddingValues(),
) {
items(objects, key = { it.objectID }) { obj ->
ObjectFrame(
Expand Down
2 changes: 1 addition & 1 deletion iosApp/iosApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ struct ComposeView: UIViewControllerRepresentable {
struct ContentView: View {
var body: some View {
ComposeView()
.ignoresSafeArea(.keyboard) // Compose has own keyboard handler
.ignoresSafeArea()
}
}

0 comments on commit f954cda

Please sign in to comment.