@momo-kits/native-kits 0.168.1-beta.38-debug → 0.168.1-beta.39-debug

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.
Files changed (25) hide show
  1. package/CLAUDE.md +3 -2
  2. package/compose/build.gradle.kts +1 -1
  3. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  4. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +72 -81
  5. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
  6. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +8 -13
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +54 -163
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +17 -12
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +2 -0
  11. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  12. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +9 -3
  13. package/ios/Input/Input.swift +3 -1
  14. package/ios/Input/InputTextArea.swift +3 -1
  15. package/ios/Layout/ModalLayout.swift +152 -0
  16. package/ios/Layout/ScreenLayout.swift +28 -24
  17. package/ios/Navigation/BottomSheet.swift +29 -157
  18. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  19. package/ios/Navigation/ModalScreen.swift +18 -7
  20. package/ios/Popup/PopupDisplay.swift +4 -2
  21. package/ios/Popup/PopupInput.swift +4 -2
  22. package/ios/Popup/PopupLayout.swift +10 -9
  23. package/ios/Popup/PopupNotify.swift +26 -23
  24. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
  25. package/package.json +1 -1
@@ -8,7 +8,6 @@ import androidx.compose.foundation.border
8
8
  import androidx.compose.foundation.gestures.detectDragGestures
9
9
  import androidx.compose.foundation.layout.Arrangement
10
10
  import androidx.compose.foundation.layout.Box
11
- import androidx.compose.foundation.layout.BoxScope
12
11
  import androidx.compose.foundation.layout.BoxWithConstraints
13
12
  import androidx.compose.foundation.layout.Column
14
13
  import androidx.compose.foundation.layout.Row
@@ -19,7 +18,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
19
18
  import androidx.compose.foundation.layout.height
20
19
  import androidx.compose.foundation.layout.heightIn
21
20
  import androidx.compose.foundation.layout.offset
22
- import androidx.compose.foundation.layout.PaddingValues
23
21
  import androidx.compose.foundation.layout.padding
24
22
  import androidx.compose.foundation.layout.size
25
23
  import androidx.compose.foundation.layout.width
@@ -33,21 +31,17 @@ import androidx.compose.runtime.mutableStateOf
33
31
  import androidx.compose.runtime.remember
34
32
  import androidx.compose.runtime.setValue
35
33
  import androidx.compose.runtime.rememberCoroutineScope
36
- import androidx.compose.ui.AbsoluteAlignment
37
34
  import androidx.compose.ui.Alignment
38
35
  import androidx.compose.ui.Modifier
39
36
  import androidx.compose.ui.graphics.Brush
40
37
  import androidx.compose.ui.graphics.Color
41
38
  import androidx.compose.ui.input.pointer.pointerInput
42
- import androidx.compose.ui.layout.layout
43
39
  import androidx.compose.ui.platform.LocalDensity
44
- import androidx.compose.ui.unit.Dp
40
+ import androidx.compose.ui.unit.Density
45
41
  import androidx.compose.ui.unit.IntOffset
46
- import androidx.compose.ui.unit.constrainHeight
47
42
  import androidx.compose.ui.unit.dp
48
43
  import kotlinx.coroutines.launch
49
44
  import vn.momo.kits.components.Divider
50
- import vn.momo.kits.components.Icon
51
45
  import vn.momo.kits.components.Text
52
46
  import vn.momo.kits.const.AppTheme
53
47
  import vn.momo.kits.const.Colors
@@ -62,23 +56,25 @@ import vn.momo.kits.modifier.conditional
62
56
  import vn.momo.kits.modifier.noFeedbackClickable
63
57
  import vn.momo.kits.platform.BackHandler
64
58
  import vn.momo.kits.platform.getScreenHeight
65
- import vn.momo.kits.layout.DuoMetrics
66
- import vn.momo.kits.layout.SideBarEdge
67
- import vn.momo.kits.layout.SideBarLayout
59
+ import vn.momo.kits.layout.MODAL_ICON_BUTTON_SIZE
60
+ import vn.momo.kits.layout.ModalIconButton
68
61
  import vn.momo.kits.layout.getScreenLayout
69
- import vn.momo.kits.modifier.setAutomationId
70
- import vn.momo.kits.navigation.component.HeaderType
71
- import vn.momo.kits.navigation.component.SideBarButton
72
- import vn.momo.kits.navigation.component.getHeaderColor
73
-
74
- // iPhone Duo inner display: center the sheet instead of spanning the width (RN BottomSheet).
75
- private val DUO_REGULAR_MIN_WIDTH = 600.dp
62
+ import vn.momo.kits.layout.rememberModalLayout
76
63
 
77
64
  private val INDICATOR_HEIGHT = 16.dp
78
65
  private val HEADER_ROW_HEIGHT = 56.dp
79
66
 
80
- // Side column controls line up with the header row while the sheet is short.
81
- private val SIDE_COLUMN_OFFSET = INDICATOR_HEIGHT + (HEADER_ROW_HEIGHT - DuoMetrics.controlSize) / 2
67
+ // A sheet held at its min height keeps the footer at the bottom; the room goes above it.
68
+ private object FooterAtBottom : Arrangement.Vertical {
69
+ override fun Density.arrange(totalSize: Int, sizes: IntArray, outPositions: IntArray) {
70
+ var y = 0
71
+ sizes.forEachIndexed { index, size ->
72
+ outPositions[index] = y
73
+ y += size
74
+ }
75
+ if (sizes.isNotEmpty()) outPositions[sizes.lastIndex] = maxOf(y - sizes.last(), totalSize - sizes.last())
76
+ }
77
+ }
82
78
 
83
79
  @Composable
84
80
  internal fun BottomSheet(
@@ -92,30 +88,19 @@ internal fun BottomSheet(
92
88
  onDismiss: (() -> Unit)?
93
89
  ) {
94
90
  val layout = getScreenLayout()
95
- val isDuo = layout.isIPhoneDuoDevice
96
- val isDuoCentered = isDuo && minOf(layout.width, layout.height) >= DUO_REGULAR_MIN_WIDTH
97
- val isDuoFloating = isDuo && !isDuoCentered
91
+ val modal = rememberModalLayout()
92
+ val isFoldable = modal.isFoldable
93
+ val sheet = modal.sheet
98
94
  val title = header as? BottomHeader.Title
99
- val sideColumn = layout.sideBar?.takeIf {
100
- isDuoFloating && title != null && it.width - Spacing.M >= DuoMetrics.controlSize + Spacing.M
101
- }
102
- // the floating sheet spans the side safe area, its content stays clear of it
103
- val sidePadding = if (isDuoFloating) {
104
- PaddingValues.Absolute(
105
- left = (layout.insetLeft - Spacing.M).coerceAtLeast(0.dp),
106
- right = (layout.insetRight - Spacing.M).coerceAtLeast(0.dp),
107
- )
108
- } else {
109
- PaddingValues()
110
- }
111
95
  // the screen is the outer display on iPhone Duo, even when unfolded
112
- val screenHeightDp = if (isDuo) layout.height else getScreenHeight()
96
+ val screenHeightDp = if (isFoldable) layout.height else getScreenHeight()
113
97
  val screenHeightPx = with(LocalDensity.current) { screenHeightDp.toPx() }
114
98
  val sheetOffset = remember { Animatable(screenHeightPx) }
115
99
 
100
+ // half the scrim fades in first, the other half follows the sheet
116
101
  val backgroundAlpha = remember { Animatable(0f) }
117
- val dynamicAlpha = ((1f - (sheetOffset.value / screenHeightPx)).coerceIn(0f, 1f)) * 0.3f
118
- val alpha = backgroundAlpha.value + dynamicAlpha
102
+ val dynamicAlpha = ((1f - (sheetOffset.value / screenHeightPx)).coerceIn(0f, 1f)) * 0.5f
103
+ val alpha = (backgroundAlpha.value + dynamicAlpha) * modal.scrimOpacity
119
104
 
120
105
  val sheetCloseOffset = with(LocalDensity.current) { 100.dp.toPx() }
121
106
 
@@ -140,7 +125,7 @@ internal fun BottomSheet(
140
125
 
141
126
  suspend fun openEvent(){
142
127
  backgroundAlpha.animateTo(
143
- targetValue = 0.3f,
128
+ targetValue = 0.5f,
144
129
  animationSpec = tween(
145
130
  durationMillis = 100,
146
131
  easing = CubicBezierEasing(0.05f, 0.7f, 0.1f, 1f)
@@ -202,40 +187,28 @@ internal fun BottomSheet(
202
187
  BoxWithConstraints(
203
188
  modifier = Modifier
204
189
  .fillMaxSize()
205
- .background(Color.Black.copy(alpha = alpha))
190
+ // full screen on foldables too, over the iPhone Duo control column
191
+ .background(Colors.black_20.copy(alpha = alpha))
206
192
  .noFeedbackClickable {
207
193
  if(barrierDismissible) closeEvent()
208
194
  }
195
+ // centered in the placement: off the iPhone Duo control column, the right half when half folded
196
+ .conditional(isFoldable) {
197
+ absolutePadding(left = modal.placement.left, right = layout.width - modal.placement.right)
198
+ }
209
199
  ) {
210
200
  val parentHeight = with(LocalDensity.current) { constraints.maxHeight.toDp() }
211
- val maxHeight = if (isDuo) {
212
- parentHeight - maxOf(layout.duoTopInset, Spacing.XL)
213
- } else {
214
- parentHeight - 90.dp
215
- }
216
- val radius = if (isDuo) Radius.XL else Radius.M
201
+ val maxHeight = sheet.maxHeight ?: (parentHeight - 90.dp)
217
202
 
218
203
  Box(
219
204
  modifier = Modifier
220
205
  .align(Alignment.BottomCenter)
221
206
  .offset { IntOffset(x = 0, y = sheetOffset.value.toInt()) }
222
- .then(
223
- when {
224
- // keeps the portrait width in landscape, like system sheets
225
- isDuoCentered -> Modifier.width(
226
- minOf(
227
- minOf(layout.width, layout.height) - Spacing.L * 2,
228
- layout.width - maxOf(layout.insetLeft, layout.insetRight, Spacing.L) * 2,
229
- )
230
- )
231
- isDuoFloating -> Modifier.fillMaxWidth().padding(horizontal = Spacing.M)
232
- else -> Modifier.fillMaxWidth()
233
- }
234
- )
207
+ .then(if (sheet.width != null) Modifier.width(sheet.width) else Modifier.fillMaxWidth())
235
208
  .heightIn(max = maxHeight)
236
209
  .background(
237
210
  color = if (isSurface) AppTheme.current.colors.background.surface else AppTheme.current.colors.background.default,
238
- shape = RoundedCornerShape(topStart = radius, topEnd = radius)
211
+ shape = RoundedCornerShape(topStart = sheet.radius, topEnd = sheet.radius)
239
212
  )
240
213
  .conditional(IsShowBaseLineDebug) {
241
214
  border(1.dp, Colors.blue_03)
@@ -246,7 +219,10 @@ internal fun BottomSheet(
246
219
  val bottomInset = if (useBottomInset) {
247
220
  (AppNavigationBar.current - keyboardSizeState().value).coerceAtLeast(0.dp)
248
221
  } else 0.dp
249
- Column(Modifier.padding(bottom = bottomInset)) {
222
+ Column(
223
+ modifier = Modifier.heightIn(min = sheet.minHeight).padding(bottom = bottomInset),
224
+ verticalArrangement = if (footerComponent != null) FooterAtBottom else Arrangement.Top,
225
+ ) {
250
226
  Box(
251
227
  modifier = Modifier
252
228
  .height(INDICATOR_HEIGHT + HEADER_ROW_HEIGHT)
@@ -276,7 +252,6 @@ internal fun BottomSheet(
276
252
  }
277
253
  }
278
254
  ) {
279
- // the indicator centers on the whole sheet, only the header row keeps clear of the strip
280
255
  Column(
281
256
  modifier = Modifier
282
257
  .fillMaxSize()
@@ -295,15 +270,13 @@ internal fun BottomSheet(
295
270
  )
296
271
  Spacer(Modifier.height(4.dp))
297
272
  Box(
298
- Modifier.padding(sidePadding).fillMaxWidth().height(HEADER_ROW_HEIGHT),
273
+ Modifier.fillMaxWidth().height(HEADER_ROW_HEIGHT),
299
274
  contentAlignment = Alignment.Center
300
275
  ) {
301
276
  when (header) {
302
277
  is BottomHeader.Title -> BottomSheetTitle(
303
278
  text = header.data,
304
279
  backIcon = header.backIcon,
305
- // the side column holds back and close, the row keeps only the title
306
- showButtons = sideColumn == null,
307
280
  onBack = onBack,
308
281
  onClose = { closeEvent() },
309
282
  )
@@ -314,32 +287,21 @@ internal fun BottomSheet(
314
287
  }
315
288
  }
316
289
  }
317
- Box(Modifier.padding(sidePadding)) {
318
- Divider()
319
- }
290
+ Divider()
320
291
  if (footerComponent != null) {
321
- Box(Modifier.weight(1f, fill = false).padding(sidePadding)) {
292
+ Box(Modifier.weight(1f, fill = false)) {
322
293
  content()
323
294
  }
324
- BottomSheetFooter(footerComponent, sidePadding)
325
- } else if (isDuo) {
295
+ BottomSheetFooter(footerComponent)
296
+ } else if (isFoldable) {
326
297
  // content shrinks so a tall sheet keeps its header
327
- Box(Modifier.weight(1f, fill = false).padding(sidePadding)) {
298
+ Box(Modifier.weight(1f, fill = false)) {
328
299
  content()
329
300
  }
330
301
  } else {
331
302
  content()
332
303
  }
333
304
  }
334
- if (sideColumn != null && title != null) {
335
- BottomSheetSideColumn(
336
- sideBar = sideColumn,
337
- parentHeight = parentHeight,
338
- backIcon = title.backIcon,
339
- onBack = onBack,
340
- onClose = { closeEvent() },
341
- )
342
- }
343
305
  }
344
306
  }
345
307
  }
@@ -348,23 +310,23 @@ internal fun BottomSheet(
348
310
  private fun BottomSheetTitle(
349
311
  text: String,
350
312
  backIcon: String,
351
- showButtons: Boolean,
352
313
  onBack: (() -> Unit)?,
353
314
  onClose: () -> Unit,
354
315
  ) {
355
- Row(modifier = Modifier.fillMaxSize(), verticalAlignment = Alignment.CenterVertically) {
356
- if (showButtons) {
357
- if (onBack != null) {
358
- BottomSheetHeaderButton(icon = backIcon, automationId = "btn_bottom_sheet_back", onClick = onBack)
359
- } else {
360
- Box(Modifier.size(24.dp))
361
- }
316
+ Row(
317
+ modifier = Modifier.fillMaxSize(),
318
+ horizontalArrangement = Arrangement.spacedBy(Spacing.S),
319
+ verticalAlignment = Alignment.CenterVertically,
320
+ ) {
321
+ if (onBack != null) {
322
+ ModalIconButton(icon = backIcon, automationId = "btn_bottom_sheet_back", onClick = onBack)
323
+ } else {
324
+ Box(Modifier.size(MODAL_ICON_BUTTON_SIZE))
362
325
  }
363
326
  Box(
364
327
  Modifier
365
328
  .fillMaxHeight()
366
- .weight(1f)
367
- .conditional(!showButtons) { padding(horizontal = Spacing.M) },
329
+ .weight(1f),
368
330
  contentAlignment = Alignment.Center
369
331
  ) {
370
332
  Text(
@@ -373,82 +335,12 @@ private fun BottomSheetTitle(
373
335
  style = Typography.headerDefaultBold
374
336
  )
375
337
  }
376
- if (showButtons) {
377
- BottomSheetHeaderButton(icon = "navigation_close", automationId = "btn_bottom_sheet_close", onClick = onClose)
378
- }
379
- }
380
- }
381
-
382
- @Composable
383
- private fun BottomSheetHeaderButton(icon: String, automationId: String, onClick: () -> Unit) {
384
- Box(
385
- Modifier
386
- .size(24.dp)
387
- .noFeedbackClickable(onClick = onClick)
388
- .setAutomationId(automationId),
389
- contentAlignment = Alignment.Center
390
- ) {
391
- Icon(source = icon)
392
- }
393
- }
394
-
395
- // iPhone Duo outer display: back and close sit on the part of the sheet under the side safe area,
396
- // 12pt from the strip's inner edge like the screen side bar. They follow the header row while the
397
- // sheet is short and stay below the status bar cluster while it is tall.
398
- @Composable
399
- private fun BoxScope.BottomSheetSideColumn(
400
- sideBar: SideBarLayout,
401
- parentHeight: Dp,
402
- backIcon: String,
403
- onBack: (() -> Unit)?,
404
- onClose: () -> Unit,
405
- ) {
406
- val isRight = sideBar.edge == SideBarEdge.RIGHT
407
- val headerColor = getHeaderColor(HeaderType.None, 1f, null, AppTheme.current.colors.text.default)
408
-
409
- Box(Modifier.matchParentSize()) {
410
- Column(
411
- modifier = Modifier
412
- .align(if (isRight) AbsoluteAlignment.TopRight else AbsoluteAlignment.TopLeft)
413
- .width(sideBar.width - Spacing.M)
414
- .layout { measurable, constraints ->
415
- val placeable = measurable.measure(constraints.copy(minHeight = 0))
416
- val sheetHeight = constraints.maxHeight
417
- // the sheet rests on the bottom of the overlay, which starts at the window top
418
- val sheetTop = parentHeight.roundToPx() - sheetHeight
419
- // clear of a camera at the bottom end of the strip when it can
420
- val lowest = sheetHeight - sideBar.bottom.roundToPx() - placeable.height
421
- val y = maxOf(sideBar.top.roundToPx() - sheetTop, SIDE_COLUMN_OFFSET.roundToPx())
422
- .coerceAtMost(lowest)
423
- .coerceAtLeast(0)
424
- layout(placeable.width, constraints.constrainHeight(y + placeable.height)) {
425
- placeable.place(0, y)
426
- }
427
- }
428
- .absolutePadding(left = if (isRight) Spacing.M else 0.dp, right = if (isRight) 0.dp else Spacing.M),
429
- horizontalAlignment = if (isRight) AbsoluteAlignment.Left else AbsoluteAlignment.Right,
430
- verticalArrangement = Arrangement.spacedBy(Spacing.M),
431
- ) {
432
- if (onBack != null) {
433
- SideBarButton(
434
- icon = backIcon,
435
- headerColor = headerColor,
436
- automationId = "btn_bottom_sheet_back",
437
- onClick = onBack,
438
- )
439
- }
440
- SideBarButton(
441
- icon = "navigation_close",
442
- headerColor = headerColor,
443
- automationId = "btn_bottom_sheet_close",
444
- onClick = onClose,
445
- )
446
- }
338
+ ModalIconButton(icon = "navigation_close", automationId = "btn_bottom_sheet_close", onClick = onClose)
447
339
  }
448
340
  }
449
341
 
450
342
  @Composable
451
- private fun BottomSheetFooter(footerComponent: @Composable () -> Unit, sidePadding: PaddingValues) {
343
+ private fun BottomSheetFooter(footerComponent: @Composable () -> Unit) {
452
344
  val shadowBrush = remember {
453
345
  Brush.verticalGradient(
454
346
  colors = listOf(Color.Transparent, Color.Black.copy(alpha = 0.05f))
@@ -463,7 +355,6 @@ private fun BottomSheetFooter(footerComponent: @Composable () -> Unit, sidePaddi
463
355
  .conditional(IsShowBaseLineDebug) {
464
356
  border(1.dp, Colors.blue_03)
465
357
  }
466
- .padding(sidePadding)
467
358
  .padding(vertical = Spacing.S)
468
359
  ) {
469
360
  footerComponent()
@@ -17,8 +17,8 @@ import androidx.compose.ui.Alignment
17
17
  import androidx.compose.ui.Modifier
18
18
  import androidx.compose.ui.draw.alpha
19
19
  import androidx.compose.ui.draw.scale
20
- import androidx.compose.ui.graphics.Color
21
20
  import androidx.compose.ui.unit.dp
21
+ import androidx.compose.ui.unit.height
22
22
  import kotlinx.coroutines.launch
23
23
  import vn.momo.kits.application.LocalContext
24
24
  import vn.momo.kits.application.IsShowBaseLineDebug
@@ -27,9 +27,8 @@ import vn.momo.kits.modifier.conditional
27
27
  import vn.momo.kits.modifier.noFeedbackClickable
28
28
  import vn.momo.kits.navigation.tracking.ScreenTracker
29
29
  import vn.momo.kits.platform.BackHandler
30
- import vn.momo.kits.layout.duoModalMaxHeight
31
- import vn.momo.kits.layout.duoModalMaxWidth
32
30
  import vn.momo.kits.layout.getScreenLayout
31
+ import vn.momo.kits.layout.rememberModalLayout
33
32
 
34
33
  @Composable
35
34
  internal fun ModalScreen(
@@ -106,21 +105,24 @@ internal fun ModalScreen(
106
105
  }
107
106
 
108
107
  val layout = getScreenLayout()
108
+ val modal = rememberModalLayout()
109
+ val placement = modal.placement
109
110
 
110
111
  Box(
111
112
  modifier = Modifier
112
113
  .fillMaxSize()
113
- .background(Color.Black.copy(alpha = 0.6f * alpha.value))
114
+ // full screen on foldables too, over the iPhone Duo control column
115
+ .background(Colors.black_20.copy(alpha = modal.scrimOpacity * alpha.value))
114
116
  .noFeedbackClickable {
115
117
  if(barrierDismissible) closeEvent()
116
118
  }
117
- // center in the safe area, clear of the side toolbar strip and the home indicator
118
- .conditional(layout.isIPhoneDuoDevice) {
119
+ // center in the placement: the safe area, or the right half of a half-folded iPhone Duo
120
+ .conditional(modal.isFoldable) {
119
121
  absolutePadding(
120
- left = layout.insetLeft,
121
- top = layout.insetTop,
122
- right = layout.insetRight,
123
- bottom = layout.insetBottom,
122
+ left = placement.left,
123
+ top = placement.top,
124
+ right = layout.width - placement.right,
125
+ bottom = layout.height - placement.bottom,
124
126
  )
125
127
  },
126
128
  contentAlignment = Alignment.Center
@@ -129,8 +131,11 @@ internal fun ModalScreen(
129
131
  modifier = Modifier
130
132
  .scale(scale.value)
131
133
  .alpha(alpha.value)
132
- .conditional(layout.isIPhoneDuoDevice) {
133
- sizeIn(maxWidth = layout.duoModalMaxWidth, maxHeight = layout.duoModalMaxHeight)
134
+ .conditional(modal.isFoldable) {
135
+ sizeIn(
136
+ maxWidth = modal.popup.maxWidth,
137
+ maxHeight = modal.popup.maxHeight ?: placement.height,
138
+ )
134
139
  }
135
140
  .wrapContentSize()
136
141
  .conditional(IsShowBaseLineDebug) {
@@ -0,0 +1,7 @@
1
+ package vn.momo.kits.platform
2
+
3
+ import androidx.compose.runtime.Composable
4
+
5
+ // OS "Reduce Motion" (iOS) / animations off (Android), live.
6
+ @Composable
7
+ expect fun rememberReduceMotion(): Boolean
@@ -10,10 +10,12 @@ internal data class ReservedRegion(val x: Dp, val y: Dp, val width: Dp, val heig
10
10
  // occlusion: regions the system occludes (iOS 27.1+), in the coordinates of the Compose root view:
11
11
  // the iPhone Duo camera, and the status bar cluster as it grows for a call or a Live Activity.
12
12
  // isFoldable: the device reports a `.division` (hinge) region, Apple's foldable check.
13
+ // division: that region while active, i.e. the hinge of a half-folded device; null while flat.
13
14
  @Immutable
14
15
  internal data class ReservedRegions(
15
16
  val occlusion: List<ReservedRegion> = emptyList(),
16
17
  val isFoldable: Boolean = false,
18
+ val division: ReservedRegion? = null,
17
19
  )
18
20
 
19
21
  @Composable
@@ -0,0 +1,48 @@
1
+ package vn.momo.kits.platform
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import androidx.compose.runtime.DisposableEffect
5
+ import androidx.compose.runtime.mutableStateOf
6
+ import androidx.compose.runtime.remember
7
+ import kotlinx.cinterop.ExperimentalForeignApi
8
+ import kotlinx.cinterop.ObjCAction
9
+ import platform.Foundation.NSNotification
10
+ import platform.Foundation.NSNotificationCenter
11
+ import platform.Foundation.NSSelectorFromString
12
+ import platform.UIKit.UIAccessibilityIsReduceMotionEnabled
13
+ import platform.UIKit.UIAccessibilityReduceMotionStatusDidChangeNotification
14
+ import platform.darwin.NSObject
15
+
16
+ @OptIn(ExperimentalForeignApi::class)
17
+ @Composable
18
+ actual fun rememberReduceMotion(): Boolean {
19
+ val reduceMotion = remember { mutableStateOf(UIAccessibilityIsReduceMotionEnabled()) }
20
+
21
+ val listener = remember {
22
+ object : NSObject() {
23
+ @Suppress("unused")
24
+ @ObjCAction
25
+ fun reduceMotionChanged(arg: NSNotification) {
26
+ reduceMotion.value = UIAccessibilityIsReduceMotionEnabled()
27
+ }
28
+ }
29
+ }
30
+
31
+ DisposableEffect(Unit) {
32
+ NSNotificationCenter.defaultCenter.addObserver(
33
+ observer = listener,
34
+ selector = NSSelectorFromString(listener::reduceMotionChanged.name + ":"),
35
+ name = UIAccessibilityReduceMotionStatusDidChangeNotification,
36
+ `object` = null,
37
+ )
38
+ onDispose {
39
+ NSNotificationCenter.defaultCenter.removeObserver(
40
+ observer = listener,
41
+ name = UIAccessibilityReduceMotionStatusDidChangeNotification,
42
+ `object` = null,
43
+ )
44
+ }
45
+ }
46
+
47
+ return reduceMotion.value
48
+ }
@@ -75,10 +75,11 @@ private fun UIView.hasDivisionRegion(): Boolean {
75
75
  return (regions?.count ?: 0uL) > 0uL
76
76
  }
77
77
 
78
+ // Active regions only: a division region is active while the device is half folded.
78
79
  @OptIn(ExperimentalForeignApi::class)
79
- private fun UIView.occlusionRegions(target: UIView): List<ReservedRegion> {
80
+ private fun UIView.activeRegions(kindName: String, target: UIView): List<ReservedRegion> {
80
81
  if (window == null || !respondsToSelector(regionsOfKind)) return emptyList()
81
- val kind = regionKind("occlusionRegionKind") ?: return emptyList()
82
+ val kind = regionKind(kindName) ?: return emptyList()
82
83
  val regions = when (val result = performSelector(regionsOfKind, withObject = kind)) {
83
84
  is List<*> -> result
84
85
  is NSArray -> List(result.count.toInt()) { result.objectAtIndex(it.toULong()) }
@@ -109,7 +110,12 @@ private class ReservedRegionsProbe(
109
110
  super.layoutSubviews()
110
111
  // re-read until found: the window may not report the hinge on the first pass
111
112
  if (!isKnownFoldable) isKnownFoldable = hasDivisionRegion()
112
- val regions = ReservedRegions(superview?.let { occlusionRegions(it) } ?: emptyList(), isKnownFoldable)
113
+ val host = superview
114
+ val regions = ReservedRegions(
115
+ occlusion = host?.let { activeRegions("occlusionRegionKind", it) } ?: emptyList(),
116
+ isFoldable = isKnownFoldable,
117
+ division = host?.takeIf { isKnownFoldable }?.let { activeRegions("divisionRegionKind", it).firstOrNull() },
118
+ )
113
119
  if (regions != last) {
114
120
  last = regions
115
121
  onChange(regions)
@@ -252,7 +252,9 @@ public struct Input: View {
252
252
  }
253
253
  .padding(.horizontal, Spacing.S)
254
254
  .background(theme.colors.background.surface)
255
- .alignmentGuide(.top) { $0[VerticalAlignment.center] }
255
+ // A zero-height frame on the top edge centers the label on the border, re-laid out with font scale.
256
+ .fixedSize(horizontal: false, vertical: true)
257
+ .frame(height: 0)
256
258
  .offset(x: Spacing.S)
257
259
  }
258
260
  }
@@ -279,7 +279,9 @@ public struct InputTextArea: View {
279
279
  }
280
280
  .padding(.horizontal, Spacing.S)
281
281
  .background(theme.colors.background.surface)
282
- .alignmentGuide(.top) { $0[VerticalAlignment.center] }
282
+ // A zero-height frame on the top edge centers the label on the border, re-laid out with font scale.
283
+ .fixedSize(horizontal: false, vertical: true)
284
+ .frame(height: 0)
283
285
  .offset(x: Spacing.S)
284
286
  }
285
287
  }