@momo-kits/native-kits 0.168.1-sizescale.1-debug → 0.169.1-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 (64) hide show
  1. package/CLAUDE.md +4 -3
  2. package/PUBLISH_GUIDE.md +29 -658
  3. package/compose/build.gradle.kts +2 -2
  4. package/compose/compose.podspec +1 -1
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +4 -5
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +2 -2
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +21 -15
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +76 -83
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +3 -3
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +1 -1
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +11 -14
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +3 -4
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +8 -13
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +57 -163
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +17 -12
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +5 -7
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +34 -23
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +321 -149
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +87 -261
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +3 -2
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +2 -0
  30. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +1 -2
  31. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +3 -2
  32. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  33. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +9 -3
  34. package/gradle.properties +1 -3
  35. package/ios/Input/Input.swift +3 -1
  36. package/ios/Input/InputTextArea.swift +3 -1
  37. package/ios/Layout/ModalLayout.swift +152 -0
  38. package/ios/Layout/ScreenLayout.swift +28 -24
  39. package/ios/Navigation/BottomSheet.swift +29 -156
  40. package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
  41. package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
  42. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  43. package/ios/Navigation/BottomTab/DuoTabBar.swift +62 -195
  44. package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
  45. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  46. package/ios/Navigation/ModalScreen.swift +18 -7
  47. package/ios/Navigation/StackScreen.swift +3 -1
  48. package/ios/Popup/PopupDisplay.swift +4 -2
  49. package/ios/Popup/PopupInput.swift +4 -2
  50. package/ios/Popup/PopupLayout.swift +10 -9
  51. package/ios/Popup/PopupNotify.swift +32 -25
  52. package/ios/Typography/Text.swift +2 -2
  53. package/ios/native-kits.podspec +1 -1
  54. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  55. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  56. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  57. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  58. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
  59. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
  60. package/local.properties +8 -0
  61. package/package.json +1 -1
  62. package/publish.sh +170 -513
  63. package/compose/build.gradle.kts.backup +0 -198
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitSizeScale.kt +0 -45
@@ -0,0 +1,104 @@
1
+ package vn.momo.kits.navigation.bottomtab
2
+
3
+ import androidx.compose.animation.core.CubicBezierEasing
4
+ import androidx.compose.animation.core.tween
5
+ import androidx.compose.ui.graphics.Color
6
+ import androidx.compose.ui.graphics.shadow.Shadow
7
+ import androidx.compose.ui.unit.Dp
8
+ import androidx.compose.ui.unit.DpOffset
9
+ import androidx.compose.ui.unit.dp
10
+ import vn.momo.kits.const.Radius
11
+ import vn.momo.kits.const.Spacing
12
+ import vn.momo.kits.platform.getPlatformName
13
+
14
+ // Navigation bar measurements (Figma "Specs Navigation", DS-984), mirrored from RN BottomTab/metrics.ts.
15
+ // Horizontal: floating container with items split evenly, center action in a notch.
16
+ // Vertical: iPhone Duo rail, center action under the container.
17
+ internal object TabBarMetrics {
18
+ val height = 68.dp
19
+ val margin = Spacing.S
20
+ val paddingVertical = Spacing.S
21
+ val paddingHorizontal = Spacing.M
22
+ val itemGap = Spacing.XS
23
+ val iconSize = 24.dp
24
+ val indicatorHeight = 32.dp
25
+ // active indicator behind the icon: 24 icon + XS·M padding
26
+ val indicatorPaddingHorizontal = Spacing.M
27
+ val indicatorRadius = Radius.XL
28
+ // home indicator / gesture bar area under the container
29
+ val systemIndicatorHeight = 24.dp
30
+ // unfolded foldables (short side from 600, the smallest in the spec) use 65% of the short side,
31
+ // centered; phones and folded outer displays fill the window
32
+ val foldableMinShortSide = 600.dp
33
+ const val FOLDABLE_WIDTH_RATIO = 0.65f
34
+ val ctaSlotWidth = 92.dp
35
+ val ctaSize = 48.dp
36
+ // the icon sits 10 inside the 48 button (prototype .cta: 28 icon), 12 inside the 52 rail one
37
+ val ctaIconSize = 28.dp
38
+ // the button rises 22 above the container top edge
39
+ val ctaLift = 22.dp
40
+ val ctaLabelGap = Spacing.M
41
+ val ctaLabelHeight = 18.dp
42
+ val railContainerWidth = 56.dp
43
+ val railPaddingHorizontal = Spacing.XS
44
+ val railPaddingBottom = Spacing.S
45
+ val railItemWidth = 48.dp
46
+ val railItemHeight = 62.dp
47
+ val railIndicatorHeight = 40.dp
48
+ val railIndicatorRadius = 20.dp
49
+ val railCtaGap = Spacing.L
50
+ val railCtaSize = 52.dp
51
+ val railCtaLabelGap = Spacing.XS
52
+ val railCtaWidth = 68.dp
53
+ val railCtaHeight = 70.dp
54
+ val badgeMaxWidth = 58.dp
55
+ }
56
+
57
+ // Motion of the navigation bar (MoMo Navigation Prototype): one active indicator slides to the
58
+ // selected item overshooting a little, icon and label tint cross-fade, the center action shrinks while held.
59
+ internal object TabBarMotion {
60
+ val indicator = tween<Float>(durationMillis = 550, easing = CubicBezierEasing(0.34f, 1.4f, 0.5f, 1f))
61
+ const val TINT_MILLIS = 250
62
+ const val CTA_PRESS_MILLIS = 150
63
+ const val CTA_PRESSED_SCALE = 0.92f
64
+ }
65
+
66
+ // Figma Effect/Popover on the center action button.
67
+ internal val CtaShadows = listOf(
68
+ Shadow(radius = 24.dp, spread = (-12).dp, color = Color.Black, alpha = 0.08f, offset = DpOffset(0.dp, 8.dp)),
69
+ Shadow(radius = 32.dp, spread = (-16).dp, color = Color.Black, alpha = 0.04f, offset = DpOffset(0.dp, 12.dp)),
70
+ )
71
+
72
+ // Inner light and tint of the active indicator: white 12% from below, primary 12% from above.
73
+ internal fun indicatorInnerShadows(primary: Color) = listOf(
74
+ Shadow(radius = 2.dp, color = Color.White, alpha = 0.12f, offset = DpOffset(0.dp, (-2).dp)),
75
+ Shadow(radius = 2.dp, color = primary, alpha = 0.12f, offset = DpOffset(0.dp, 1.dp)),
76
+ )
77
+
78
+ // Notch dipped into the container top edge under the center action (Figma "Backgroud" path): starts
79
+ // NOTCH_HALF_WIDTH left of the center, then cubic segments of control1, control2, end, each point as
80
+ // (dx from the center, dy below the top edge) in dp.
81
+ internal const val NOTCH_HALF_WIDTH = 50.758f
82
+ internal val NOTCH_CURVES = listOf(
83
+ listOf(-39.749f to 0f, -31.231f to 9.765f, -24.563f to 18.526f),
84
+ listOf(-18.928f to 25.93f, -10.022f to 30.709f, 0f to 30.709f),
85
+ listOf(10.022f to 30.709f, 18.928f to 25.93f, 24.563f to 18.526f),
86
+ listOf(31.231f to 9.765f, 39.749f to 0f, NOTCH_HALF_WIDTH to 0f),
87
+ )
88
+
89
+ // Width of the horizontal bar: 65% of the short side on an unfolded foldable, otherwise the window minus
90
+ // the side safe areas and margins.
91
+ internal fun horizontalBarWidth(width: Dp, height: Dp, insetLeft: Dp, insetRight: Dp): Dp {
92
+ val shortSide = minOf(width, height)
93
+ if (shortSide >= TabBarMetrics.foldableMinShortSide) return shortSide * TabBarMetrics.FOLDABLE_WIDTH_RATIO
94
+ return width - insetLeft - insetRight - TabBarMetrics.margin * 2
95
+ }
96
+
97
+ // Gap under the container: the home indicator / gesture bar area.
98
+ internal fun tabBarBottomGap(navigationBar: Dp): Dp =
99
+ (if (getPlatformName() == "iOS") minOf(navigationBar, TabBarMetrics.systemIndicatorHeight) else navigationBar)
100
+ .coerceAtLeast(Spacing.S)
101
+
102
+ // The center action needs a tab on each side: Special type takes 2 or 4 tabs.
103
+ internal fun hasCenterAction(floatingButton: BottomTabFloatingButton?, tabCount: Int): Boolean =
104
+ floatingButton != null && tabCount % 2 == 0
@@ -29,6 +29,7 @@ internal fun ComposeLottieAnimation(
29
29
  isPlaying: Boolean,
30
30
  onEvent: ((String) -> Unit)?,
31
31
  modifier: Modifier,
32
+ progress: (() -> Float)? = null,
32
33
  ) {
33
34
  val json = readJson(path)
34
35
 
@@ -55,7 +56,7 @@ internal fun ComposeLottieAnimation(
55
56
  val lottieState = animateLottieCompositionAsState(
56
57
  composition = composition,
57
58
  iterations = iterations,
58
- isPlaying = isPlaying,
59
+ isPlaying = isPlaying && progress == null,
59
60
  restartOnPlay = false,
60
61
  )
61
62
 
@@ -77,7 +78,7 @@ internal fun ComposeLottieAnimation(
77
78
  Image(
78
79
  painter = rememberLottiePainter(
79
80
  composition = composition,
80
- progress = lottieState::value,
81
+ progress = progress ?: lottieState::value,
81
82
  dynamicProperties = dynamicProperties,
82
83
  enableExpressions = false,
83
84
  expressionEngineFactory = { _, _ ->
@@ -66,7 +66,9 @@ expect fun LottieAnimation(
66
66
  isPlaying: Boolean = true,
67
67
  onEvent: ((String) -> Unit)? = null,
68
68
  modifier: Modifier = Modifier,
69
- useCompose: Boolean = false
69
+ useCompose: Boolean = false,
70
+ // drives the animation instead of playing it, so several animations stay in sync; needs useCompose
71
+ progress: (() -> Float)? = null,
70
72
  )
71
73
 
72
74
  expect fun NativePaint.setColor(
@@ -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
@@ -16,7 +16,6 @@ import platform.UIKit.UIContentSizeCategoryDidChangeNotification
16
16
  import platform.UIKit.UIFont
17
17
  import platform.UIKit.UIFontTextStyleBody
18
18
  import platform.darwin.NSObject
19
- import vn.momo.kits.const.LocalSizeScale
20
19
 
21
20
  // Compose MP iOS reads LocalDensity.fontScale once at ComposeUIViewController creation and does not
22
21
  // recompose it when UIContentSizeCategory changes (Android tracks Configuration.fontScale live). We
@@ -60,7 +59,7 @@ actual fun ProvideOsFontScale(content: @Composable () -> Unit) {
60
59
 
61
60
  val density = LocalDensity.current
62
61
  CompositionLocalProvider(
63
- LocalDensity provides Density(density.density, osFontScale.value / LocalSizeScale.current),
62
+ LocalDensity provides Density(density.density, osFontScale.value),
64
63
  ) {
65
64
  content()
66
65
  }
@@ -112,10 +112,11 @@ actual fun LottieAnimation(
112
112
  isPlaying: Boolean,
113
113
  onEvent: ((String) -> Unit)?,
114
114
  modifier: Modifier,
115
- useCompose: Boolean
115
+ useCompose: Boolean,
116
+ progress: (() -> Float)?,
116
117
  ) {
117
118
  if (useCompose) {
118
- ComposeLottieAnimation(path, tintColor, bgColor, iterations, isPlaying, onEvent, modifier)
119
+ ComposeLottieAnimation(path, tintColor, bgColor, iterations, isPlaying, onEvent, modifier, progress)
119
120
  return
120
121
  }
121
122
 
@@ -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)
package/gradle.properties CHANGED
@@ -18,9 +18,7 @@ kotlin.apple.xcodeCompatibility.nowarn=true
18
18
  name="ComposeKits"
19
19
  group=vn.momo.kits
20
20
  artifact.id=kits
21
- version=0.168.1-beta.8
21
+ version=0.169.1
22
22
 
23
23
  repo=GitLab
24
24
  url=https://gitlab.mservice.com.vn/api/v4/projects/5400/packages/maven
25
- gitlab.user=upload_packages
26
- gitlab.password=gldt-CtTSGmzz57sUL9cnjdaQ
@@ -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
  }
@@ -0,0 +1,152 @@
1
+ //
2
+ // ModalLayout.swift
3
+ // MoMoUIKits
4
+ //
5
+ // Foldable spec for Popup and BottomSheet (Figma "Modal - Foldable Guideline"). Mirrors Compose
6
+ // `layout/ModalLayout.kt` and RN; keep the three in sync.
7
+ //
8
+
9
+ import SwiftUI
10
+
11
+ /// Foldable modal spec values, in points. Public so host apps can size their own popups and sheets the same way.
12
+ public enum ModalMetrics {
13
+ public static let popupMaxWidth: CGFloat = 450
14
+ public static let popupMinWidth: CGFloat = 280
15
+ public static let popupMaxHeight: CGFloat = 600
16
+ public static let sheetMaxWidth: CGFloat = 653
17
+ public static let sheetMinWidth: CGFloat = 296
18
+ public static let sheetMinHeight: CGFloat = 230
19
+ public static let foldableMinWidth: CGFloat = 600
20
+ public static let iconButtonSize: CGFloat = 32
21
+ public static let iconSize: CGFloat = 20
22
+ public static let phoneScrimOpacity: CGFloat = 0.6
23
+ public static let foldableScrimOpacity: CGFloat = 0.2
24
+ }
25
+
26
+ public struct PopupGeometry: Equatable {
27
+ public let minWidth: CGFloat
28
+ public let maxWidth: CGFloat
29
+ /// nil: as tall as the content, phones keep their own caps
30
+ public let maxHeight: CGFloat?
31
+ public let margin: CGFloat
32
+ public let radius: CGFloat
33
+ }
34
+
35
+ public struct SheetGeometry: Equatable {
36
+ /// nil: spans the window
37
+ public let width: CGFloat?
38
+ /// nil: phones keep their own cap
39
+ public let maxHeight: CGFloat?
40
+ public let minHeight: CGFloat
41
+ public let margin: CGFloat
42
+ public let radius: CGFloat
43
+ }
44
+
45
+ /// Popup / bottom sheet geometry for a window; see `ModalLayout.resolve` and `ScreenLayout.modalLayout`.
46
+ public struct ModalLayout: Equatable {
47
+ public let isFoldable: Bool
48
+ /// Window coordinates of the area popups center in and sheets rest on the bottom of.
49
+ public let placement: CGRect
50
+ public let popup: PopupGeometry
51
+ public let sheet: SheetGeometry
52
+ public let scrimOpacity: CGFloat
53
+ }
54
+
55
+ public extension ScreenLayout {
56
+ /// Foldable = iPhone Duo or a window whose short side is at least 600 (RN parity), so phones
57
+ /// in landscape keep their look.
58
+ var modalLayout: ModalLayout {
59
+ ModalLayout.resolve(width: width, height: height, safeInsets: insets, isDuoDevice: isDuoDevice, hinge: hinge)
60
+ }
61
+ }
62
+
63
+ public extension ModalLayout {
64
+ /// Resolves popup / bottom sheet geometry from plain window metrics, for hosts without a kits screen
65
+ /// (`ScreenLayout.current.modalLayout` covers the key window).
66
+ ///
67
+ /// Points, window coordinates. `safeInsets` is the window safe area; on iPhone Duo it also carries the
68
+ /// control column. `hinge` is the vertical hinge of a half-folded iPhone Duo, nil while flat.
69
+ static func resolve(
70
+ width: CGFloat,
71
+ height: CGFloat,
72
+ safeInsets insets: EdgeInsets = EdgeInsets(),
73
+ isDuoDevice: Bool = false,
74
+ hinge: CGRect? = nil
75
+ ) -> ModalLayout {
76
+ let isFoldable = isDuoDevice || min(width, height) >= ModalMetrics.foldableMinWidth
77
+ guard isFoldable else {
78
+ let placement = CGRect(x: 0, y: 0, width: width, height: height)
79
+ return ModalLayout(
80
+ isFoldable: false,
81
+ placement: placement,
82
+ popup: popupGeometry(placementWidth: width, maxHeight: nil, margin: Spacing.XL, radius: Radius.L),
83
+ sheet: SheetGeometry(width: nil, maxHeight: nil, minHeight: 0, margin: 0, radius: Radius.M),
84
+ scrimOpacity: ModalMetrics.phoneScrimOpacity
85
+ )
86
+ }
87
+
88
+ // the safe area keeps overlays clear of the iPhone Duo control column; half folded they move to the right half
89
+ let hinge = hinge.flatMap { isDuoDevice && $0.minX > 0 && $0.maxX < width ? $0 : nil }
90
+ let left = max(insets.leading, hinge?.maxX ?? 0)
91
+ let placement = CGRect(
92
+ x: left,
93
+ y: insets.top,
94
+ width: max(width - insets.trailing - left, 0),
95
+ height: max(height - insets.top - insets.bottom, 0)
96
+ )
97
+ // outer display and half fold leave little room, so the margins tighten
98
+ let isCompact = isDuoDevice && (hinge != nil || min(width, height) < ModalMetrics.foldableMinWidth)
99
+ let sheetMargin = Spacing.M
100
+ let sheetMaxHeight = height - insets.top - sheetMargin
101
+ let sheetMinWidth = min(ModalMetrics.sheetMinWidth, placement.width)
102
+ return ModalLayout(
103
+ isFoldable: true,
104
+ placement: placement,
105
+ popup: popupGeometry(
106
+ placementWidth: placement.width,
107
+ maxHeight: min(ModalMetrics.popupMaxHeight, placement.height - Spacing.XL * 2),
108
+ margin: isCompact ? Spacing.M : Spacing.XL,
109
+ radius: Radius.XL
110
+ ),
111
+ sheet: SheetGeometry(
112
+ width: max(min(placement.width - sheetMargin * 2, ModalMetrics.sheetMaxWidth), sheetMinWidth),
113
+ maxHeight: sheetMaxHeight,
114
+ minHeight: min(ModalMetrics.sheetMinHeight, sheetMaxHeight),
115
+ margin: sheetMargin,
116
+ radius: Radius.XL
117
+ ),
118
+ scrimOpacity: ModalMetrics.foldableScrimOpacity
119
+ )
120
+ }
121
+
122
+ /// clamp(placement - 2 margin, 280, 450); the 280 floor gives way to a narrower placement.
123
+ private static func popupGeometry(placementWidth: CGFloat, maxHeight: CGFloat?, margin: CGFloat, radius: CGFloat) -> PopupGeometry {
124
+ let minWidth = min(ModalMetrics.popupMinWidth, placementWidth)
125
+ let maxWidth = min(max(placementWidth - margin * 2, minWidth), max(ModalMetrics.popupMaxWidth, minWidth))
126
+ return PopupGeometry(minWidth: minWidth, maxWidth: maxWidth, maxHeight: maxHeight, margin: margin, radius: radius)
127
+ }
128
+ }
129
+
130
+ /// Popup close and sheet header back / close: 32 circle on the surface with a border, 20 icon.
131
+ public struct ModalIconButton: View {
132
+ @Environment(\.appTheme) private var theme
133
+ let icon: String
134
+ let accessibilityId: String
135
+ let action: () -> Void
136
+
137
+ public init(icon: String, accessibilityId: String, action: @escaping () -> Void) {
138
+ self.icon = icon
139
+ self.accessibilityId = accessibilityId
140
+ self.action = action
141
+ }
142
+
143
+ public var body: some View {
144
+ Icon(source: icon, size: ModalMetrics.iconSize, color: theme.colors.text.default)
145
+ .frame(width: ModalMetrics.iconButtonSize, height: ModalMetrics.iconButtonSize)
146
+ .background(Circle().fill(theme.colors.background.surface))
147
+ .overlay(Circle().strokeBorder(theme.colors.border.default, lineWidth: 1))
148
+ .contentShape(Circle())
149
+ .onTapGesture(perform: action)
150
+ .accessibilityIdentifier(accessibilityId)
151
+ }
152
+ }
@@ -46,6 +46,8 @@ public struct ScreenLayout: Equatable {
46
46
  public let sideBar: SideBarLayout?
47
47
  /// iPhone Duo inner display in portrait: the header row shares the status bar band, between its clusters.
48
48
  public let statusBarClearance: StatusBarClearance?
49
+ /// Half-folded iPhone Duo: the hinge in window coordinates, running top to bottom; nil while flat.
50
+ public let hinge: CGRect?
49
51
 
50
52
  public var headerBarHeight: CGFloat { headerHeight - headerStatusBarHeight }
51
53
  }
@@ -76,11 +78,6 @@ enum DuoMetrics {
76
78
  static let floatingTabBarHeight: CGFloat = 62
77
79
  static let floatingTabBarMargin: CGFloat = 20
78
80
  static let floatingTabBarInsetOverlap: CGFloat = 13
79
- // Width of a system alert on the inner display, in both orientations.
80
- static let modalMaxWidth: CGFloat = 440
81
- // Fits a PopupNotify with image, scrolled description and actions at the max width (RN
82
- // Application/device.ts); taller content scrolls instead of filling the inner display.
83
- static let modalMaxHeight: CGFloat = 640
84
81
  }
85
82
 
86
83
  enum HeaderMetrics {
@@ -116,11 +113,14 @@ extension ScreenLayout {
116
113
  insets: EdgeInsets,
117
114
  reservedRegions: [CGRect] = ReservedRegions.current,
118
115
  isPhone: Bool = isPhoneIdiom,
119
- isFoldable: Bool = FoldableDevice.isFoldable(measuredIn: keyWindow)
116
+ isFoldable: Bool = FoldableDevice.isFoldable(measuredIn: keyWindow),
117
+ division: CGRect? = FoldableDevice.halfFoldedHinge
120
118
  ) -> ScreenLayout {
121
119
  let width = size.width
122
120
  let height = size.height
123
121
  let isDuoDevice = isPhone && isFoldable
122
+ // only a hinge splitting the window into left and right halves moves overlays
123
+ let hinge = division.flatMap { isPhone && $0.height > $0.width ? $0 : nil }
124
124
  var (headerHeight, headerStatusBarHeight) = headerGeometry(topInset: insets.top, isPhone: isPhone)
125
125
  let isDuo = isPhone && isIPhoneDuoWindow(width: width, height: height, insets: insets)
126
126
  guard isDuo else {
@@ -128,7 +128,7 @@ extension ScreenLayout {
128
128
  width: width, height: height, isIPhoneDuo: false, isDuoDevice: isDuoDevice, insets: insets,
129
129
  insetLeft: 0, insetRight: 0, contentWidth: width,
130
130
  headerHeight: headerHeight, headerStatusBarHeight: headerStatusBarHeight, sideBar: nil,
131
- statusBarClearance: nil
131
+ statusBarClearance: nil, hinge: hinge
132
132
  )
133
133
  }
134
134
 
@@ -191,7 +191,7 @@ extension ScreenLayout {
191
191
  insetLeft: insets.leading, insetRight: insets.trailing,
192
192
  contentWidth: width - insets.leading - insets.trailing,
193
193
  headerHeight: headerHeight, headerStatusBarHeight: headerStatusBarHeight, sideBar: sideBar,
194
- statusBarClearance: statusBarClearance
194
+ statusBarClearance: statusBarClearance, hinge: hinge
195
195
  )
196
196
  }
197
197
 
@@ -265,15 +265,6 @@ extension ScreenLayout {
265
265
  max(insets.top, height > width ? max(insets.leading, insets.trailing) * 2 : 0)
266
266
  }
267
267
 
268
- /// Room for a dialog on iPhone Duo: inside the safe area, so clear of the side toolbar strip, and
269
- /// capped so it stays a dialog on the inner display.
270
- var duoModalMaxWidth: CGFloat {
271
- min(width - insets.leading - insets.trailing - Spacing.XL * 2, DuoMetrics.modalMaxWidth)
272
- }
273
-
274
- var duoModalMaxHeight: CGFloat {
275
- min(height - insets.top - insets.bottom - Spacing.XL * 2, DuoMetrics.modalMaxHeight)
276
- }
277
268
  }
278
269
 
279
270
  /// Snapshot for call sites without `\.screenLayout`; not reactive. `windowSize` is ignored,
@@ -290,6 +281,12 @@ public func isIPhoneDuoDevice(windowSize: CGSize? = nil) -> Bool {
290
281
  enum FoldableDevice {
291
282
  // a hinge never goes away, so a positive answer is kept
292
283
  private static var isKnownFoldable = false
284
+ private static var isPartiallyOpen = false
285
+
286
+ /// The active division region while the hinge reports partially open; nil while flat.
287
+ static var halfFoldedHinge: CGRect? {
288
+ isPartiallyOpen ? ReservedRegions.division : nil
289
+ }
293
290
 
294
291
  static func isFoldable(measuredIn view: UIView?) -> Bool {
295
292
  if isKnownFoldable { return true }
@@ -306,8 +303,11 @@ enum FoldableDevice {
306
303
  #if canImport(UIKit, _version: 9127.0.85.28)
307
304
  guard #available(iOS 27.1, *) else { return }
308
305
  view.addInteraction(UIHingeInteraction { _, update in
309
- guard update.hinge != nil, !isKnownFoldable else { return }
306
+ guard let hinge = update.hinge else { return }
307
+ let partiallyOpen = hinge.status == .partiallyOpen
308
+ guard !isKnownFoldable || partiallyOpen != isPartiallyOpen else { return }
310
309
  isKnownFoldable = true
310
+ isPartiallyOpen = partiallyOpen
311
311
  NotificationCenter.default.post(name: ReservedRegions.didChange, object: nil)
312
312
  })
313
313
  #endif
@@ -318,14 +318,17 @@ enum FoldableDevice {
318
318
 
319
319
  /// System occlusion regions (iOS 27.1+) in window coordinates: the iPhone Duo camera, and the
320
320
  /// status bar cluster as it grows for a call or a Live Activity. Empty before iOS 27.1.
321
+ /// `division` is the active hinge region, there only while the device is half folded.
321
322
  enum ReservedRegions {
322
323
  // last report of a probe, so `ScreenLayout.current` includes it
323
324
  private(set) static var current: [CGRect] = []
325
+ private(set) static var division: CGRect?
324
326
  static let didChange = Notification.Name("MoMoUIKitsReservedRegionsDidChange")
325
327
 
326
- fileprivate static func publish(_ regions: [CGRect]) {
327
- guard regions != current else { return }
328
+ fileprivate static func publish(_ regions: [CGRect], division: CGRect?) {
329
+ guard regions != current || division != self.division else { return }
328
330
  current = regions
331
+ self.division = division
329
332
  NotificationCenter.default.post(name: didChange, object: nil)
330
333
  }
331
334
  }
@@ -344,12 +347,13 @@ private final class ReservedRegionsProbe: UIView {
344
347
  override func layoutSubviews() {
345
348
  super.layoutSubviews()
346
349
  // read even when not publishing, so UIKit keeps re-running this when they change
347
- let regions = occlusionRegions()
350
+ let regions = activeRegions(kind: "occlusionRegionKind")
351
+ let division = activeRegions(kind: "divisionRegionKind").first
348
352
  // every screen has a probe but the regions are window-wide: one sliding in on a push or
349
353
  // a present, or off the window, would overwrite them with a partial read
350
354
  guard spansWindow else { return }
351
355
  // layout pass: publish on the next turn instead of mutating SwiftUI state mid-update
352
- DispatchQueue.main.async { ReservedRegions.publish(regions) }
356
+ DispatchQueue.main.async { ReservedRegions.publish(regions, division: division) }
353
357
  }
354
358
 
355
359
  private var spansWindow: Bool {
@@ -364,11 +368,11 @@ private final class ReservedRegionsProbe: UIView {
364
368
  }
365
369
 
366
370
  // The API is newer than the SDKs hosts may build with, so it is reached through the runtime.
367
- private func occlusionRegions() -> [CGRect] {
371
+ private func activeRegions(kind kindName: String) -> [CGRect] {
368
372
  let regionsOfKind = NSSelectorFromString("reservedRegionsOfKind:")
369
373
  guard window != nil, responds(to: regionsOfKind),
370
374
  let kindType = NSClassFromString("UIViewReservedRegionKind") as? NSObject.Type,
371
- let kind = (kindType as AnyObject).perform(NSSelectorFromString("occlusionRegionKind"))?.takeUnretainedValue(),
375
+ let kind = (kindType as AnyObject).perform(NSSelectorFromString(kindName))?.takeUnretainedValue(),
372
376
  let regions = perform(regionsOfKind, with: kind)?.takeUnretainedValue() as? [NSObject]
373
377
  else { return [] }
374
378
  return regions.compactMap { ($0.value(forKey: "frame") as? NSValue)?.cgRectValue }