@momo-kits/native-kits 0.150.0-beta.7 → 0.150.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ package vn.momo.kits.platform
3
3
  import android.annotation.SuppressLint
4
4
  import android.content.res.Resources
5
5
  import android.graphics.BlurMaskFilter
6
+ import android.os.Build
6
7
  import androidx.compose.runtime.Composable
7
8
  import androidx.compose.ui.graphics.NativePaint
8
9
  import androidx.compose.ui.platform.LocalConfiguration
@@ -47,4 +48,6 @@ actual fun BackHandler(enabled: Boolean, onBack: () -> Unit) {
47
48
  @Composable
48
49
  actual fun getScreenHeight(): Dp {
49
50
  return getScreenDimensions().height.dp + AppStatusBar.current + AppNavigationBar.current
50
- }
51
+ }
52
+
53
+ actual fun getAndroidBuildVersion(): Int = Build.VERSION.SDK_INT
@@ -14,19 +14,16 @@ import androidx.compose.foundation.layout.aspectRatio
14
14
  import androidx.compose.foundation.layout.fillMaxSize
15
15
  import androidx.compose.foundation.layout.fillMaxWidth
16
16
  import androidx.compose.foundation.layout.ime
17
- import androidx.compose.foundation.layout.offset
17
+ import androidx.compose.foundation.layout.imePadding
18
18
  import androidx.compose.foundation.layout.padding
19
19
  import androidx.compose.foundation.layout.systemBars
20
20
  import androidx.compose.foundation.rememberScrollState
21
21
  import androidx.compose.foundation.verticalScroll
22
22
  import androidx.compose.runtime.Composable
23
23
  import androidx.compose.runtime.getValue
24
- import androidx.compose.runtime.mutableStateOf
25
- import androidx.compose.runtime.remember
26
24
  import androidx.compose.ui.Alignment
27
25
  import androidx.compose.ui.Modifier
28
26
  import androidx.compose.ui.graphics.Color
29
- import androidx.compose.ui.graphics.graphicsLayer
30
27
  import androidx.compose.ui.input.pointer.pointerInput
31
28
  import androidx.compose.ui.layout.LayoutCoordinates
32
29
  import androidx.compose.ui.layout.onGloballyPositioned
@@ -37,13 +34,12 @@ import androidx.compose.ui.unit.dp
37
34
  import androidx.compose.ui.unit.min
38
35
  import androidx.compose.ui.zIndex
39
36
  import vn.momo.kits.components.InputSearchProps
40
- import vn.momo.kits.const.AppStatusBar
41
37
  import vn.momo.kits.const.AppTheme
42
38
  import vn.momo.kits.const.Colors
43
39
  import vn.momo.kits.const.Spacing
44
40
  import vn.momo.kits.modifier.conditional
45
41
  import vn.momo.kits.modifier.shadow
46
- import vn.momo.kits.platform.getStatusBarHeight
42
+ import vn.momo.kits.platform.getAndroidBuildVersion
47
43
 
48
44
  enum class HeaderType {
49
45
  DEFAULT,
@@ -82,17 +78,9 @@ fun Screen(
82
78
  val statusBarHeight = getAppStatusBarHeight()
83
79
  val keyboardController = LocalSoftwareKeyboardController.current
84
80
 
81
+ val isKeyboardVisible = isKeyboardVisible()
85
82
  val indicator = WindowInsets.systemBars.asPaddingValues().calculateBottomPadding()
86
- val bottomPadding = min(indicator, 21.dp)
87
-
88
- val keyboardHeight = WindowInsets.ime.asPaddingValues().calculateBottomPadding()
89
- val keyboardSize = when {
90
- !useAvoidKeyboard -> 0.dp
91
- keyboardHeight > 100.dp && footer == null -> keyboardHeight
92
- keyboardHeight > 100.dp && footer != null -> keyboardHeight - bottomPadding
93
- else -> 0.dp
94
- }
95
-
83
+ val bottomPadding = min(indicator, if (isKeyboardVisible) 0.dp else 21.dp)
96
84
 
97
85
  val headerHeight = if (animatedHeader !== null)
98
86
  with(LocalDensity.current) { layoutOffset.roundToPx() }
@@ -115,6 +103,9 @@ fun Screen(
115
103
  Box(
116
104
  Modifier.fillMaxSize()
117
105
  .background(backgroundColor ?: AppTheme.current.colors.background.default)
106
+ .conditional(useAvoidKeyboard && getAndroidBuildVersion() > 29) {
107
+ imePadding()
108
+ }
118
109
  ) {
119
110
 
120
111
  if (animatedHeader === null) {
@@ -154,7 +145,6 @@ fun Screen(
154
145
  Column(
155
146
  modifier = Modifier
156
147
  .conditional(scrollable) { weight(1f) }
157
- .padding(bottom = keyboardSize)
158
148
  .conditional(onContentLayout != null) {
159
149
  onGloballyPositioned(onContentLayout ?: {})
160
150
  }
@@ -178,7 +168,7 @@ fun Screen(
178
168
  }
179
169
 
180
170
  footer?.let {
181
- Footer(footer, keyboardSize, bottomPadding)
171
+ Footer(footer, bottomPadding)
182
172
  }
183
173
  }
184
174
 
@@ -194,17 +184,23 @@ fun Screen(
194
184
  text = fabProps.label,
195
185
  size = fabProps.size,
196
186
  position = fabProps.position ?: FABPosition.END,
197
- keyboardSize = keyboardSize
198
187
  )
199
188
  }
200
189
  }
201
190
  }
202
191
 
203
192
  @Composable
204
- fun Footer(footer: @Composable (() -> Unit)? = null, keyboardSize: Dp = 0.dp, bottom: Dp = 0.dp) {
193
+ internal fun isKeyboardVisible(): Boolean {
194
+ val ime = WindowInsets.ime
195
+ val density = LocalDensity.current
196
+ val bottom = ime.getBottom(density)
197
+ return bottom > 0
198
+ }
199
+
200
+ @Composable
201
+ fun Footer(footer: @Composable (() -> Unit)? = null, bottom: Dp = 0.dp) {
205
202
  Box(
206
203
  Modifier
207
- .offset(y = -keyboardSize)
208
204
  .shadow(
209
205
  color = Colors.black_20.copy(alpha = 0.05f),
210
206
  blurRadius = 24f,
@@ -10,12 +10,12 @@ import androidx.compose.foundation.layout.BoxScope
10
10
  import androidx.compose.foundation.layout.Column
11
11
  import androidx.compose.foundation.layout.Spacer
12
12
  import androidx.compose.foundation.layout.WindowInsets
13
- import androidx.compose.foundation.layout.asPaddingValues
14
13
  import androidx.compose.foundation.layout.aspectRatio
15
14
  import androidx.compose.foundation.layout.fillMaxSize
16
15
  import androidx.compose.foundation.layout.fillMaxWidth
17
16
  import androidx.compose.foundation.layout.height
18
17
  import androidx.compose.foundation.layout.ime
18
+ import androidx.compose.foundation.layout.imePadding
19
19
  import androidx.compose.foundation.layout.offset
20
20
  import androidx.compose.foundation.layout.padding
21
21
  import androidx.compose.foundation.rememberScrollState
@@ -33,7 +33,6 @@ import androidx.compose.runtime.mutableStateOf
33
33
  import androidx.compose.runtime.remember
34
34
  import androidx.compose.runtime.rememberCoroutineScope
35
35
  import androidx.compose.runtime.setValue
36
- import androidx.compose.runtime.staticCompositionLocalOf
37
36
  import androidx.compose.ui.Alignment
38
37
  import androidx.compose.ui.Modifier
39
38
  import androidx.compose.ui.graphics.Brush
@@ -60,6 +59,7 @@ import vn.momo.kits.navigation.component.HeaderBackground
60
59
  import vn.momo.kits.navigation.component.HeaderRight
61
60
  import vn.momo.kits.navigation.component.HeaderType
62
61
  import vn.momo.kits.platform.BackHandler
62
+ import vn.momo.kits.platform.getAndroidBuildVersion
63
63
 
64
64
  const val HEADER_HEIGHT = 52
65
65
 
@@ -113,23 +113,15 @@ internal fun StackScreen(
113
113
  }
114
114
  )
115
115
 
116
- val bottomPadding = min(AppNavigationBar.current, 21.dp)
117
-
118
- val keyboardHeight = WindowInsets.ime.asPaddingValues().calculateBottomPadding()
119
- val keyboardSize = when {
120
- !options.keyboardOptions.useAvoidKeyboard -> 0.dp
121
- keyboardHeight > 100.dp && options.footerComponent == null -> keyboardHeight
122
- keyboardHeight > 100.dp && options.footerComponent != null -> keyboardHeight - bottomPadding
123
- else -> 0.dp
124
- }
116
+ val isKeyboardVisible = isKeyboardVisible()
117
+ val bottomPadding = min(AppNavigationBar.current, if (isKeyboardVisible) 0.dp else 21.dp)
125
118
 
126
119
  BackHandler(true){
127
120
  navigator.pop()
128
121
  }
129
122
 
130
123
  CompositionLocalProvider(
131
- LocalNavigation provides navigation,
132
- LocalKeyboardSize provides keyboardSize
124
+ LocalNavigation provides navigation
133
125
  ) {
134
126
  Box(Modifier
135
127
  .fillMaxSize()
@@ -138,6 +130,9 @@ internal fun StackScreen(
138
130
  .conditional(options.keyboardOptions.keyboardShouldPersistTaps == true) {
139
131
  hideKeyboardOnTap()
140
132
  }
133
+ .conditional(options.keyboardOptions.useAvoidKeyboard && getAndroidBuildVersion() > 29) {
134
+ imePadding()
135
+ }
141
136
  ) {
142
137
  Box(Modifier.zIndex(1f)) {
143
138
  HeaderBackground(
@@ -166,7 +161,7 @@ internal fun StackScreen(
166
161
  )
167
162
  }
168
163
 
169
- Column(Modifier.zIndex(2f).fillMaxSize().padding(bottom = keyboardSize)) {
164
+ Column(Modifier.zIndex(2f).fillMaxSize()) {
170
165
  Spacer(Modifier.height(if (options.headerType is HeaderType.DefaultOrExtended) AppStatusBar.current + HEADER_HEIGHT.dp else 0.dp))
171
166
  Column (Modifier
172
167
  .fillMaxWidth()
@@ -188,7 +183,7 @@ internal fun StackScreen(
188
183
  Box(Modifier.zIndex(5f)){
189
184
  val fabProps = options.floatingButtonProps ?: return@Box
190
185
  val bottomPadding = fabProps.bottom ?:
191
- (keyboardSize + Spacing.M + if (options.footerComponent != null) with(LocalDensity.current){ footerHeight.toDp() } else 0.dp)
186
+ (Spacing.M + if (options.footerComponent != null) with(LocalDensity.current){ footerHeight.toDp() } else 0.dp)
192
187
 
193
188
  FloatingButton(
194
189
  scrollPosition = fabProps.scrollState?.value ?: scrollState.value,
@@ -383,4 +378,11 @@ fun BoxScope.renderPullRefreshIndicator(refreshing: Boolean, pullState: PullRefr
383
378
  )
384
379
  }
385
380
 
386
- val LocalKeyboardSize = staticCompositionLocalOf { 0.dp }
381
+
382
+ @Composable
383
+ internal fun isKeyboardVisible(): Boolean {
384
+ val ime = WindowInsets.ime
385
+ val density = LocalDensity.current
386
+ val bottom = ime.getBottom(density)
387
+ return bottom > 0
388
+ }
@@ -23,4 +23,6 @@ expect fun getStatusBarHeight(): Dp
23
23
  expect fun BackHandler(enabled: Boolean, onBack: () -> Unit)
24
24
 
25
25
  @Composable
26
- expect fun getScreenHeight(): Dp
26
+ expect fun getScreenHeight(): Dp
27
+
28
+ expect fun getAndroidBuildVersion(): Int
@@ -44,4 +44,6 @@ actual fun BackHandler(enabled: Boolean, onBack: () -> Unit) {
44
44
  @Composable
45
45
  actual fun getScreenHeight(): Dp {
46
46
  return getScreenDimensions().height.dp
47
- }
47
+ }
48
+
49
+ actual fun getAndroidBuildVersion(): Int = 999
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.150.0-beta.7",
3
+ "version": "0.150.0-beta.8",
4
4
  "private": false,
5
5
  "dependencies": {
6
6
  "@momo-platform/native-max-api": "1.0.18"