Skip to content

Commit 5194b12

Browse files
authored
Merge pull request #31 from mori-atsushi/v0.1.0-alpha05
Prepare v0.1.0-alpha05
2 parents 181ea97 + 09db5c5 commit 5194b12

2 files changed

Lines changed: 89 additions & 16 deletions

File tree

README.md

Lines changed: 88 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
InsetsX provides a [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) utility for [Compose Multiplatform](https://www.jetbrains.com/lp/compose-multiplatform/).
99

10-
It aim to work with WindowInsets with the same interface on iOS and Android.
10+
The goal is to have a unified interface for handling WindowInsets across iOS and Android.
1111

12-
This library will be archived when the official library can handle WindowInsets.
12+
Once the official library supports WindowInsets, this library will be archived.
1313

1414
## Setup
15-
Add the dependency as follows:
15+
To use InsetsX, add the following dependency:
1616

1717
```kotlin
1818
kotlin {
@@ -28,37 +28,110 @@ kotlin {
2828
}
2929
```
3030

31+
### Android
32+
1. (option) If you are using insets for IME support, set the activity's `windowSoftInputMode` to `adjustResize` in your AndroidManifest.xml file.
33+
34+
```xml
35+
<activity
36+
android:name=".MyActivity"
37+
android:windowSoftInputMode="adjustResize">
38+
</activity>
39+
```
40+
41+
2. Call `WindowCompat.setDecorFitsSystemWindows()` with `false` in the `onCreate` method of the activity .
42+
43+
```kotlin
44+
override fun onCreate(savedInstanceState: Bundle?) {
45+
super.onCreate(savedInstanceState)
46+
47+
WindowCompat.setDecorFitsSystemWindows(window, false)
48+
}
49+
```
50+
51+
Detail: [Lay out your app within window insets](https://developer.android.com/develop/ui/views/layout/insets)
52+
53+
### iOS
54+
55+
1. (option) If you are using `WindowInsetsController`, use `WindowInsetsUIViewController` instead of `ComposeUIViewController`.
56+
57+
```kotlin
58+
fun MainUIViewController(): UIViewController {
59+
return WindowInsetsUIViewController {
60+
MyApp()
61+
}
62+
}
63+
```
64+
3165
## How to use
66+
### WindowInsets
3267
This works much like Android's WindowInsets.
3368
Please note that the package name is different.
3469

3570
```kotlin
3671
import androidx.compose.foundation.layout.windowInsetsPadding
3772
import androidx.compose.foundation.layout.WindowInsets
73+
import androidx.compose.runtime.Composable
3874
import androidx.compose.ui.Modifier
3975
import com.moriatsushi.insetsx.systemBars
4076
import com.moriatsushi.insetsx.systemBarsPadding
4177

42-
val modifier1 = Modifier
43-
.windowInsetsPadding(WindowInsets.systemBars)
78+
@Composable
79+
fun Sample() {
80+
val modifier1 = Modifier
81+
.windowInsetsPadding(WindowInsets.safeDrawing)
4482

45-
val modifier2 = Modifier
46-
.systemBarsPadding()
83+
val modifier2 = Modifier
84+
.safeDrawingPadding()
85+
}
4786
```
4887

49-
## APIs
50-
5188
API|android|ios
5289
:--|:--|:--
53-
WindowInsets.systemBars|status bar + navigation bar|SafeArea
54-
WindowInsets.navigationBars|navigation bar|bottom of SafeArea
55-
WindowInsets.statusBars|status bar|top and horizontal of SafeArea
90+
WindowInsets.safeArea|system bars + display cutouts|SafeArea
91+
WindowInsets.systemBars|status bar + navigation bar|home indicator + status bar
92+
WindowInsets.navigationBars|navigation bar|home indicator
93+
WindowInsets.statusBars|status bar|status bar
5694
WindowInsets.ime *1|software keyboard|software keyboard
5795
WindowInsets.safeDrawing *1|system bars + software keyboard|SafeArea + software keyboard
58-
Modifier.systemBarsPadding()|status bar + navigation bar|SafeArea
59-
Modifier.navigationBarsPadding()|navigation bar|bottom of SafeArea
60-
Modifier.statusBarsPadding()|status bar|top and horizontal of SafeArea
96+
(Modifier)||
97+
Modifier.safeAreaPadding()|system bars + display cutouts|SafeArea
98+
Modifier.systemBarsPadding()|status bar + navigation bar|home indicator + status bar
99+
Modifier.navigationBarsPadding()|navigation bar|home indicator
100+
Modifier.statusBarsPadding()|status bar|status bar
61101
Modifier.imePadding() *1|software keyboard|software keyboard
62102
Modifier.safeDrawingPadding() *1|system bars + software keyboard|SafeArea + software keyboard
63103

64104
*1 is experimental
105+
106+
### WindowInsetsController
107+
`WindowInsetsController` can be used to change colors of system bars.
108+
109+
```kotlin
110+
@Composable
111+
fun Sample() {
112+
val windowInsetsController = rememberWindowInsetsController()
113+
LaunchedEffect(Unit) {
114+
// The status bars icon + content will change to a light color
115+
windowInsetsController?.setStatusBarContentColor(dark = false)
116+
// The navigation bars icons will change to a light color (android only)
117+
windowInsetsController?.setNavigationBarsContentColor(dark = false)
118+
}
119+
}
120+
```
121+
122+
You can also hide WindowInsets.
123+
124+
```kotlin
125+
@Composable
126+
fun Sample() {
127+
val windowInsetsController = rememberWindowInsetsController()
128+
LaunchedEffect(Unit) {
129+
// Hide the status bars
130+
windowInsetsController?.setIsStatusBarsVisible(false)
131+
// Hide the navigation bars
132+
windowInsetsController?.setIsNavigationBarsVisible(false)
133+
// Change an options for behavior when system bars are hidden
134+
windowInsetsController?.setSystemBarsBehavior(SystemBarsBehavior.Immersive)
135+
}
136+
}
137+
```

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ org.jetbrains.compose.experimental.uikit.enabled=true
2222
SONATYPE_HOST=S01
2323
RELEASE_SIGNING_ENABLED=true
2424
GROUP=com.moriatsushi.insetsx
25-
VERSION_NAME=0.1.0-alpha04
25+
VERSION_NAME=0.1.0-alpha05
2626

2727
POM_NAME=InsetsX
2828
POM_DESCRIPTION=WindowInsets utility for compose multiplatform

0 commit comments

Comments
 (0)