@momo-kits/native-kits 0.168.1-beta.4 → 0.168.1-beta.40-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 (185) hide show
  1. package/CLAUDE.md +15 -10
  2. package/README.md +2 -10
  3. package/build.gradle.kts +11 -0
  4. package/compose/build.gradle.kts +198 -0
  5. package/compose/build.gradle.kts.backup +198 -0
  6. package/compose/compose.podspec +47 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +20 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
  12. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  13. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1071 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +357 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +195 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +478 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +265 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +235 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +223 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +265 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +363 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +308 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +330 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +207 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +92 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +560 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +125 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +501 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +236 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +17 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +287 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +316 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +393 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +113 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +205 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +422 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +739 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +239 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +389 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +94 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +97 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +203 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +455 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +399 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +192 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +92 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +22 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +219 -0
  132. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  133. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +144 -0
  134. package/gradle/libs.versions.toml +69 -0
  135. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  136. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  137. package/gradle.properties +26 -0
  138. package/gradlew +252 -0
  139. package/gradlew.bat +94 -0
  140. package/ios/Application/ApplicationEnvironment.swift +7 -6
  141. package/ios/Application/DesignSystemKits.swift +163 -0
  142. package/ios/Application/DesignSystemKitsPayload.swift +68 -0
  143. package/ios/Badge/BadgeRibbon.swift +8 -1
  144. package/ios/Extensions/Color++.swift +2 -4
  145. package/ios/Input/Input.swift +16 -4
  146. package/ios/Input/InputPhoneNumber.swift +1 -3
  147. package/ios/Input/InputSearch.swift +1 -2
  148. package/ios/Input/InputTextArea.swift +8 -4
  149. package/ios/InputMoney/InputMoney.swift +6 -7
  150. package/ios/Layout/ModalLayout.swift +152 -0
  151. package/ios/Layout/ScreenLayout.swift +77 -18
  152. package/ios/Navigation/BottomSheet.swift +56 -53
  153. package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
  154. package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
  155. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  156. package/ios/Navigation/BottomTab/DuoBarCompression.swift +2 -3
  157. package/ios/Navigation/BottomTab/DuoTabBar.swift +64 -172
  158. package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
  159. package/ios/Navigation/Component/HeaderBackground.swift +22 -1
  160. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  161. package/ios/Navigation/Component/SnackBar.swift +4 -0
  162. package/ios/Navigation/ModalScreen.swift +20 -5
  163. package/ios/Navigation/StackScreen.swift +6 -8
  164. package/ios/Popup/PopupDisplay.swift +6 -4
  165. package/ios/Popup/PopupInput.swift +6 -4
  166. package/ios/Popup/PopupLayout.swift +17 -11
  167. package/ios/Popup/PopupNotify.swift +32 -25
  168. package/ios/Stepper/Stepper.swift +1 -2
  169. package/ios/Template/TrustBanner/TrustBanner.swift +4 -2
  170. package/ios/Typography/FontScale.swift +29 -15
  171. package/ios/Typography/Text.swift +88 -14
  172. package/ios/Typography/Typography.swift +2 -2
  173. package/ios/native-kits.podspec +1 -1
  174. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  175. package/ios-demo/README.md +120 -0
  176. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  177. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  178. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  179. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
  180. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
  181. package/package.json +1 -1
  182. package/publish.sh +2 -33
  183. package/settings.gradle.kts +64 -0
  184. package/ios/Typography/FontScaleStore.swift +0 -58
  185. package/ios/Typography/KitDesignSystem.swift +0 -17
@@ -32,6 +32,9 @@ public struct ScreenLayout: Equatable {
32
32
  public let width: CGFloat
33
33
  public let height: CGFloat
34
34
  public let isIPhoneDuo: Bool
35
+ /// iPhone Duo folded or not, whatever the window size (its hinge, or the outer display's one-sided strip);
36
+ /// drives popups, modal and bottom sheet.
37
+ public let isDuoDevice: Bool
35
38
  public let insets: EdgeInsets
36
39
  public let insetLeft: CGFloat
37
40
  public let insetRight: CGFloat
@@ -43,6 +46,8 @@ public struct ScreenLayout: Equatable {
43
46
  public let sideBar: SideBarLayout?
44
47
  /// iPhone Duo inner display in portrait: the header row shares the status bar band, between its clusters.
45
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?
46
51
 
47
52
  public var headerBarHeight: CGFloat { headerHeight - headerStatusBarHeight }
48
53
  }
@@ -68,8 +73,11 @@ enum DuoMetrics {
68
73
  // (x 550–643 of 669, clock digits centered on y 47); its reserved region is taller than the glyphs.
69
74
  static let innerStatusBarCenterY: CGFloat = 47
70
75
  static let innerStatusBarWidth: CGFloat = 120
71
- // Widest short side of any single-display iPhone.
72
- static let iPhoneMaxShortSide: CGFloat = 440
76
+ // Host app's iOS 26 tab bar on the inner display in portrait: a 62pt glass pill sized to its tabs,
77
+ // QR as a 62pt platter beside it, ≥ 20pt from the sides, 13pt into the home indicator inset.
78
+ static let floatingTabBarHeight: CGFloat = 62
79
+ static let floatingTabBarMargin: CGFloat = 20
80
+ static let floatingTabBarInsetOverlap: CGFloat = 13
73
81
  }
74
82
 
75
83
  enum HeaderMetrics {
@@ -104,18 +112,23 @@ extension ScreenLayout {
104
112
  size: CGSize,
105
113
  insets: EdgeInsets,
106
114
  reservedRegions: [CGRect] = ReservedRegions.current,
107
- isPhone: Bool = isPhoneIdiom
115
+ isPhone: Bool = isPhoneIdiom,
116
+ isFoldable: Bool = FoldableDevice.isFoldable(measuredIn: keyWindow),
117
+ division: CGRect? = FoldableDevice.halfFoldedHinge
108
118
  ) -> ScreenLayout {
109
119
  let width = size.width
110
120
  let height = size.height
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 }
111
124
  var (headerHeight, headerStatusBarHeight) = headerGeometry(topInset: insets.top, isPhone: isPhone)
112
125
  let isDuo = isPhone && isIPhoneDuoWindow(width: width, height: height, insets: insets)
113
126
  guard isDuo else {
114
127
  return ScreenLayout(
115
- width: width, height: height, isIPhoneDuo: false, insets: insets,
128
+ width: width, height: height, isIPhoneDuo: false, isDuoDevice: isDuoDevice, insets: insets,
116
129
  insetLeft: 0, insetRight: 0, contentWidth: width,
117
130
  headerHeight: headerHeight, headerStatusBarHeight: headerStatusBarHeight, sideBar: nil,
118
- statusBarClearance: nil
131
+ statusBarClearance: nil, hinge: hinge
119
132
  )
120
133
  }
121
134
 
@@ -171,12 +184,14 @@ extension ScreenLayout {
171
184
  )
172
185
  }
173
186
 
187
+ // the outer display reports no hinge; its one-sided strip still gives it away
174
188
  return ScreenLayout(
175
- width: width, height: height, isIPhoneDuo: true, insets: insets,
189
+ width: width, height: height, isIPhoneDuo: true,
190
+ isDuoDevice: isDuoDevice || insets.leading != insets.trailing, insets: insets,
176
191
  insetLeft: insets.leading, insetRight: insets.trailing,
177
192
  contentWidth: width - insets.leading - insets.trailing,
178
193
  headerHeight: headerHeight, headerStatusBarHeight: headerStatusBarHeight, sideBar: sideBar,
179
- statusBarClearance: statusBarClearance
194
+ statusBarClearance: statusBarClearance, hinge: hinge
180
195
  )
181
196
  }
182
197
 
@@ -249,29 +264,71 @@ extension ScreenLayout {
249
264
  public var duoTopInset: CGFloat {
250
265
  max(insets.top, height > width ? max(insets.leading, insets.trailing) * 2 : 0)
251
266
  }
267
+
252
268
  }
253
269
 
254
- /// Port of RN `device.ts` `isIPhoneDuo()`: UIScreen stays on the outer display, so this
255
- /// still matches when Split View narrows the window. Used by popups and overlays.
270
+ /// Snapshot for call sites without `\.screenLayout`; not reactive. `windowSize` is ignored,
271
+ /// kept for host call sites.
256
272
  public func isIPhoneDuoDevice(windowSize: CGSize? = nil) -> Bool {
257
273
  guard isPhoneIdiom else { return false }
258
- let screen = UIScreen.main.bounds.size
259
- let window = windowSize ?? keyWindow?.bounds.size ?? screen
260
- return max(min(screen.width, screen.height), min(window.width, window.height)) > DuoMetrics.iPhoneMaxShortSide
274
+ let insets = keyWindow?.safeAreaInsets
275
+ return FoldableDevice.isFoldable(measuredIn: keyWindow) || insets.map { $0.left != $0.right } == true
276
+ }
277
+
278
+ /// Apple's foldable check (as the host's `SideTabRailView.isFoldableDevice`): only a device with a
279
+ /// hinge reports a `.division` region, inactive while flat but still there. Screen size cannot tell
280
+ /// it apart from a large iPhone in landscape or a narrowed window.
281
+ enum FoldableDevice {
282
+ // a hinge never goes away, so a positive answer is kept
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
+ }
290
+
291
+ static func isFoldable(measuredIn view: UIView?) -> Bool {
292
+ if isKnownFoldable { return true }
293
+ // compiled out on SDKs older than iOS 27.1 (UIKit 9127.0.85.28)
294
+ #if canImport(UIKit, _version: 9127.0.85.28)
295
+ guard #available(iOS 27.1, *), let view, view.window != nil || view is UIWindow else { return false }
296
+ isKnownFoldable = !view.reservedRegions(kind: .division, options: .includeInactive).isEmpty
297
+ #endif
298
+ return isKnownFoldable
299
+ }
300
+
301
+ /// Catches the hinge when the regions were read too early (before the window had them).
302
+ static func observe(in view: UIView) {
303
+ #if canImport(UIKit, _version: 9127.0.85.28)
304
+ guard #available(iOS 27.1, *) else { return }
305
+ view.addInteraction(UIHingeInteraction { _, update in
306
+ guard let hinge = update.hinge else { return }
307
+ let partiallyOpen = hinge.status == .partiallyOpen
308
+ guard !isKnownFoldable || partiallyOpen != isPartiallyOpen else { return }
309
+ isKnownFoldable = true
310
+ isPartiallyOpen = partiallyOpen
311
+ NotificationCenter.default.post(name: ReservedRegions.didChange, object: nil)
312
+ })
313
+ #endif
314
+ }
261
315
  }
262
316
 
263
317
  // MARK: - Reserved regions
264
318
 
265
319
  /// System occlusion regions (iOS 27.1+) in window coordinates: the iPhone Duo camera, and the
266
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.
267
322
  enum ReservedRegions {
268
323
  // last report of a probe, so `ScreenLayout.current` includes it
269
324
  private(set) static var current: [CGRect] = []
325
+ private(set) static var division: CGRect?
270
326
  static let didChange = Notification.Name("MoMoUIKitsReservedRegionsDidChange")
271
327
 
272
- fileprivate static func publish(_ regions: [CGRect]) {
273
- guard regions != current else { return }
328
+ fileprivate static func publish(_ regions: [CGRect], division: CGRect?) {
329
+ guard regions != current || division != self.division else { return }
274
330
  current = regions
331
+ self.division = division
275
332
  NotificationCenter.default.post(name: didChange, object: nil)
276
333
  }
277
334
  }
@@ -282,6 +339,7 @@ private final class ReservedRegionsProbe: UIView {
282
339
  override init(frame: CGRect) {
283
340
  super.init(frame: frame)
284
341
  isUserInteractionEnabled = false
342
+ FoldableDevice.observe(in: self)
285
343
  }
286
344
 
287
345
  required init?(coder: NSCoder) { nil }
@@ -289,12 +347,13 @@ private final class ReservedRegionsProbe: UIView {
289
347
  override func layoutSubviews() {
290
348
  super.layoutSubviews()
291
349
  // read even when not publishing, so UIKit keeps re-running this when they change
292
- let regions = occlusionRegions()
350
+ let regions = activeRegions(kind: "occlusionRegionKind")
351
+ let division = activeRegions(kind: "divisionRegionKind").first
293
352
  // every screen has a probe but the regions are window-wide: one sliding in on a push or
294
353
  // a present, or off the window, would overwrite them with a partial read
295
354
  guard spansWindow else { return }
296
355
  // layout pass: publish on the next turn instead of mutating SwiftUI state mid-update
297
- DispatchQueue.main.async { ReservedRegions.publish(regions) }
356
+ DispatchQueue.main.async { ReservedRegions.publish(regions, division: division) }
298
357
  }
299
358
 
300
359
  private var spansWindow: Bool {
@@ -309,11 +368,11 @@ private final class ReservedRegionsProbe: UIView {
309
368
  }
310
369
 
311
370
  // The API is newer than the SDKs hosts may build with, so it is reached through the runtime.
312
- private func occlusionRegions() -> [CGRect] {
371
+ private func activeRegions(kind kindName: String) -> [CGRect] {
313
372
  let regionsOfKind = NSSelectorFromString("reservedRegionsOfKind:")
314
373
  guard window != nil, responds(to: regionsOfKind),
315
374
  let kindType = NSClassFromString("UIViewReservedRegionKind") as? NSObject.Type,
316
- let kind = (kindType as AnyObject).perform(NSSelectorFromString("occlusionRegionKind"))?.takeUnretainedValue(),
375
+ let kind = (kindType as AnyObject).perform(NSSelectorFromString(kindName))?.takeUnretainedValue(),
317
376
  let regions = perform(regionsOfKind, with: kind)?.takeUnretainedValue() as? [NSObject]
318
377
  else { return [] }
319
378
  return regions.compactMap { ($0.value(forKey: "frame") as? NSValue)?.cgRectValue }
@@ -15,16 +15,25 @@ import SwiftUI
15
15
 
16
16
  /// Mirrors Compose's `sealed class BottomHeader` (Title / Custom).
17
17
  public struct BottomSheetHeader {
18
+ struct Back {
19
+ let icon: String
20
+ let action: () -> Void
21
+ }
22
+
18
23
  enum Style {
19
- case title(String)
24
+ case title(String, back: Back?)
20
25
  case custom(() -> AnyView)
21
26
  }
22
27
 
23
28
  let style: Style
24
29
 
25
- /// Mirrors `BottomHeader.Title`.
26
- public static func title(_ text: String = "Bottom Sheet Title") -> BottomSheetHeader {
27
- BottomSheetHeader(style: .title(text))
30
+ /// Mirrors `BottomHeader.Title`. `onBack` shows a back button; the sheet closes, then it runs.
31
+ public static func title(
32
+ _ text: String = "Bottom Sheet Title",
33
+ backIcon: String = "arrow-back",
34
+ onBack: (() -> Void)? = nil
35
+ ) -> BottomSheetHeader {
36
+ BottomSheetHeader(style: .title(text, back: onBack.map { Back(icon: backIcon, action: $0) }))
28
37
  }
29
38
 
30
39
  /// Mirrors `BottomHeader.Custom`.
@@ -68,38 +77,20 @@ struct BottomSheetView<Content: View>: View {
68
77
  /// Mirrors Compose's `sheetCloseOffset` (100dp drag threshold to dismiss).
69
78
  private let closeThreshold: CGFloat = 100
70
79
 
71
- /// Mirrors Compose's per-term peak (0.3f). Combined with `backgroundAlpha` the
72
- /// steady-state (fully open) scrim peaks at 0.6, matching ModalScreen's peak.
73
- private let maxDynamicAlpha: CGFloat = 0.3
74
-
75
- // UIScreen stays on the outer display on iPhone Duo, even when unfolded
76
- private var screenHeight: CGFloat { isDuo ? layout.height : UIScreen.main.bounds.height }
77
-
78
- private var isDuo: Bool { layout.isDuoDevice }
79
- // iPhone Duo inner display: center the sheet instead of spanning the width
80
- private var isDuoCentered: Bool { isDuo && layout.width >= 600 }
80
+ private let indicatorHeight: CGFloat = 16
81
+ private let headerRowHeight: CGFloat = 56
81
82
 
82
- /// Keeps the portrait width in landscape, like system sheets.
83
- private var duoCenteredWidth: CGFloat {
84
- min(
85
- min(layout.width, layout.height) - Spacing.L * 2,
86
- layout.width - max(layout.insets.leading, layout.insets.trailing, Spacing.L) * 2
87
- )
88
- }
83
+ /// Half the scrim fades in first, the other half follows the sheet; together they reach
84
+ /// `scrimOpacity` (0.6 on phones, as ModalScreen; 0.2 on foldables).
85
+ private let maxDynamicAlpha: CGFloat = 0.5
89
86
 
90
- /// Landscape side buttons span the full height, so the content is inset; in portrait the
91
- /// side status bar only covers the top corner.
92
- private var sideInsetLeading: CGFloat {
93
- isDuo && !isDuoCentered && layout.width > layout.height ? layout.insets.leading : 0
94
- }
87
+ private var modal: ModalLayout { layout.modalLayout }
88
+ private var isFoldable: Bool { modal.isFoldable }
95
89
 
96
- private var sideInsetTrailing: CGFloat {
97
- isDuo && !isDuoCentered && layout.width > layout.height ? layout.insets.trailing : 0
98
- }
90
+ // UIScreen stays on the outer display on iPhone Duo, even when unfolded
91
+ private var screenHeight: CGFloat { isFoldable ? layout.height : UIScreen.main.bounds.height }
99
92
 
100
- private var maxHeight: CGFloat {
101
- isDuo ? layout.height - max(layout.duoTopInset, Spacing.XL) : screenHeight - 90
102
- }
93
+ private var maxHeight: CGFloat { modal.sheet.maxHeight ?? screenHeight - 90 }
103
94
  private var bottomInset: CGFloat { useBottomInset ? safeAreaBottomInset() : 0 }
104
95
  /// While the keyboard is up, it already covers the home-indicator area, so it
105
96
  /// replaces (rather than adds to) the usual bottom-inset filler.
@@ -121,15 +112,15 @@ struct BottomSheetView<Content: View>: View {
121
112
  return progress * maxDynamicAlpha
122
113
  }
123
114
 
124
- /// Mirrors Compose's `alpha = backgroundAlpha + dynamicAlpha`: additive, so the
125
- /// scrim peaks at 0.6 at rest and only fades to a 0.3 floor while dragging
115
+ /// Mirrors Compose's `alpha = (backgroundAlpha + dynamicAlpha) * scrimOpacity`: additive, so the
116
+ /// scrim peaks at `scrimOpacity` at rest and only fades to half of it while dragging
126
117
  /// (backgroundAlpha holds steady until an explicit close()).
127
- private var totalScrimAlpha: CGFloat { backgroundAlpha + dynamicAlpha }
118
+ private var totalScrimAlpha: CGFloat { (backgroundAlpha + dynamicAlpha) * modal.scrimOpacity }
128
119
 
129
120
  var body: some View {
130
121
  ZStack(alignment: .bottom) {
131
- // Dimmed scrim — additive backgroundAlpha + dynamicAlpha (see above).
132
- Color.black.opacity(totalScrimAlpha)
122
+ // Dimmed scrim — additive backgroundAlpha + dynamicAlpha (see above); full screen on foldables too.
123
+ Colors.black20.opacity(totalScrimAlpha)
133
124
  .contentShape(Rectangle())
134
125
  .onTapGesture {
135
126
  if barrierDismissible { close() }
@@ -170,13 +161,11 @@ struct BottomSheetView<Content: View>: View {
170
161
  .frame(width: 40, height: 4)
171
162
  Spacer().frame(height: 4)
172
163
  headerView
173
- .frame(height: 56)
164
+ .frame(height: headerRowHeight)
174
165
  .padding(.horizontal, Spacing.M)
175
- .padding(.leading, sideInsetLeading)
176
- .padding(.trailing, sideInsetTrailing)
177
166
  }
178
167
  .frame(maxWidth: .infinity)
179
- .frame(height: 72)
168
+ .frame(height: indicatorHeight + headerRowHeight)
180
169
  .contentShape(Rectangle())
181
170
  .gesture(dragGesture, including: draggable ? .all : .subviews)
182
171
 
@@ -185,15 +174,16 @@ struct BottomSheetView<Content: View>: View {
185
174
  .frame(height: 1)
186
175
 
187
176
  content()
188
- .padding(.leading, sideInsetLeading)
189
- .padding(.trailing, sideInsetTrailing)
190
177
  // a tall sheet keeps its header (and footer) and gives the content what is left
191
178
  .layoutPriority(-1)
192
179
 
193
180
  if let footer {
181
+ // a sheet held at its min height keeps the footer at the bottom
182
+ Spacer(minLength: 0).layoutPriority(-2)
194
183
  BottomSheetFooter(content: footer)
195
184
  }
196
185
  }
186
+ .frame(minHeight: max(modal.sheet.minHeight - effectiveBottomInset, 0), alignment: .top)
197
187
  // The filler stays outside the cap, which shrinks by it instead: the sheet still ends at
198
188
  // `maxHeight`, and the iOS 15 fallback never measures the keyboard as content.
199
189
  .modifier(CapHeight(maxHeight: maxHeight - effectiveBottomInset))
@@ -201,7 +191,8 @@ struct BottomSheetView<Content: View>: View {
201
191
  (footer != nil ? theme.colors.background.surface : backgroundColor)
202
192
  .frame(height: effectiveBottomInset)
203
193
  }
204
- .frame(maxWidth: isDuoCentered ? duoCenteredWidth : .infinity)
194
+ .frame(width: modal.sheet.width)
195
+ .frame(maxWidth: modal.sheet.width == nil ? .infinity : nil)
205
196
  .clipped()
206
197
  .background(
207
198
  GeometryReader { geo in
@@ -209,27 +200,36 @@ struct BottomSheetView<Content: View>: View {
209
200
  }
210
201
  )
211
202
  .background(backgroundColor)
212
- .clipShape(RoundedCorner(radius: Radius.M, corners: [.topLeft, .topRight]))
203
+ .clipShape(RoundedCorner(radius: modal.sheet.radius, corners: [.topLeft, .topRight]))
204
+ // centered in the placement: off the iPhone Duo control column, the right half when half folded
205
+ .padding(.leading, isFoldable ? modal.placement.minX : 0)
206
+ .padding(.trailing, isFoldable ? layout.width - modal.placement.maxX : 0)
213
207
  }
214
208
 
215
209
  @ViewBuilder
216
210
  private var headerView: some View {
217
211
  switch header.style {
218
- case .title(let text):
219
- HStack(spacing: 0) {
220
- Color.clear.frame(width: 24, height: 24)
212
+ case .title(let text, let back):
213
+ HStack(spacing: Spacing.S) {
214
+ if let back {
215
+ ModalIconButton(icon: back.icon, accessibilityId: "btn_bottom_sheet_back") { goBack(back) }
216
+ } else {
217
+ Color.clear.frame(width: ModalMetrics.iconButtonSize, height: ModalMetrics.iconButtonSize)
218
+ }
221
219
  MomoText(text, typography: .headerDefaultBold, color: Colors.black17)
222
220
  .frame(maxWidth: .infinity, alignment: .center)
223
- Icon(source: "navigation_close", size: 24, color: Colors.black17)
224
- .frame(width: 24, height: 24)
225
- .contentShape(Rectangle())
226
- .onTapGesture { close() }
221
+ ModalIconButton(icon: "navigation_close", accessibilityId: "btn_bottom_sheet_close") { close() }
227
222
  }
228
223
  case .custom(let builder):
229
224
  builder()
230
225
  }
231
226
  }
232
227
 
228
+ /// RN `leftOptions.onPressIconLeft`: the sheet closes first, then the back runs.
229
+ private func goBack(_ back: BottomSheetHeader.Back) {
230
+ close(then: back.action)
231
+ }
232
+
233
233
  // MARK: - Drag handling (mirrors Compose's detectDragGestures)
234
234
 
235
235
  private var dragGesture: some Gesture {
@@ -282,7 +282,7 @@ struct BottomSheetView<Content: View>: View {
282
282
 
283
283
  /// Mirrors Compose's `closeEvent`: slide out over 200ms, then fade the scrim
284
284
  /// out over 100ms only after the slide finishes, then dismiss.
285
- private func close() {
285
+ private func close(then onClosed: (() -> Void)? = nil) {
286
286
  guard !isClosing else { return }
287
287
  isClosing = true
288
288
  withAnimation(.timingCurve(0.3, 0, 0.8, 0.15, duration: 0.2)) {
@@ -294,7 +294,10 @@ struct BottomSheetView<Content: View>: View {
294
294
  }
295
295
  }
296
296
  DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
297
+ // a newer overlay replaced this one: it stays, and this sheet's back is dropped
298
+ guard navigator.overplay?.id == overplayId else { return }
297
299
  navigator.finishOverplayDismiss(id: overplayId)
300
+ onClosed?()
298
301
  }
299
302
  }
300
303
  }
@@ -53,10 +53,9 @@ public struct BottomTab: View {
53
53
  }
54
54
 
55
55
  private var bottomInset: CGFloat { safeAreaBottomInset() }
56
- // the Duo bars overlay the content or sit in the side strip, so only the home indicator is kept clear
57
- private var reservedBottom: CGFloat {
58
- layout.isIPhoneDuo ? layout.insets.bottom : BOTTOM_TAB_BAR_HEIGHT + bottomInset + Spacing.S
59
- }
56
+ // the bars float over the content (tab screens keep clear of them through duoTabBarInsets) or sit
57
+ // in the side strip, so only the home indicator is kept clear
58
+ private var reservedBottom: CGFloat { layout.insets.bottom }
60
59
 
61
60
  private var compression: DuoBarCompression {
62
61
  DuoBarCompression.resolve(
@@ -104,18 +103,13 @@ public struct BottomTab: View {
104
103
  compression: compression
105
104
  )
106
105
  } else {
107
- // Tab bar + home-indicator filler.
108
- VStack(spacing: 0) {
109
- BottomTabBar(
110
- items: items,
111
- floatingButton: floatingButton,
112
- selectedIndex: selectedIndex,
113
- onTabSelected: selectTab
114
- )
115
- theme.colors.background.surface
116
- .frame(height: bottomInset + Spacing.S)
117
- .ignoresSafeArea(edges: .horizontal)
118
- }
106
+ BottomTabBar(
107
+ items: items,
108
+ floatingButton: floatingButton,
109
+ selectedIndex: selectedIndex,
110
+ onTabSelected: selectTab,
111
+ bottomInset: bottomInset
112
+ )
119
113
  }
120
114
  }
121
115
  .frame(maxWidth: .infinity, maxHeight: .infinity)
@@ -137,6 +131,7 @@ public struct BottomTab: View {
137
131
  }
138
132
 
139
133
  private func selectTab(_ index: Int) {
134
+ navigator.maxApi?.triggerEventVibration("light")
140
135
  let switchTab = { if index != selectedIndex { selectedIndex = index } }
141
136
  if let onTabPress { onTabPress(index, switchTab) } else { switchTab() }
142
137
  }
@@ -208,11 +203,11 @@ private struct TabHost: UIViewControllerRepresentable {
208
203
 
209
204
  private final class TabController: UIViewController {
210
205
  private final class Tab {
211
- let motion = TabMotion()
212
206
  var host: UIHostingController<AnyView>!
213
207
  }
214
208
 
215
- private static let switchDuration: TimeInterval = 0.2
209
+ /// The tab switch: the screens slide in index order over 280ms, CSS `ease`.
210
+ private static let switchDuration: TimeInterval = 0.28
216
211
 
217
212
  private var tabs: [Int: Tab] = [:]
218
213
  private var selectedIndex: Int?
@@ -226,7 +221,7 @@ private final class TabController: UIViewController {
226
221
 
227
222
  override func viewDidLayoutSubviews() {
228
223
  super.viewDidLayoutSubviews()
229
- for subview in view.subviews { subview.frame = view.bounds }
224
+ for subview in view.subviews { place(subview) }
230
225
  }
231
226
 
232
227
  func update(
@@ -243,33 +238,43 @@ private final class TabController: UIViewController {
243
238
  }
244
239
  if let selectedIndex, tabs[selectedIndex] == nil { self.selectedIndex = nil }
245
240
  // hidden tabs too, so a tab coming back already shows the latest items and environment
246
- for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex, existing) }
241
+ for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex) }
247
242
  guard (0..<count).contains(index), index != selectedIndex else { return }
248
243
 
249
- let previous = selectedIndex.flatMap { tabs[$0] }
244
+ let previousIndex = selectedIndex
245
+ let previous = previousIndex.flatMap { tabs[$0] }
250
246
  selectedIndex = index
251
247
  let selected = tabs[index] ?? makeTab(index)
248
+ // a tab selected again while it leaves carries on from where it is
249
+ let entering = selected.host.view.superview == nil
252
250
  attach(selected)
253
251
 
254
- guard let previous, view.window != nil else {
255
- selected.motion.visible = true
252
+ guard let previous, let previousIndex, view.window != nil else {
253
+ selected.host.view.transform = .identity
256
254
  previous.map(leave)
257
255
  return
258
256
  }
259
257
  previous.host.view.isUserInteractionEnabled = false
260
- // a frame at the start values first, so a tab created just now fades in too
258
+ let offset = index > previousIndex ? view.bounds.width : -view.bounds.width
259
+ if entering { selected.host.view.transform = CGAffineTransform(translationX: offset, y: 0) }
260
+ // a frame at the start values first, so a tab created just now slides in with its content
261
261
  DispatchQueue.main.async {
262
- selected.motion.visible = true
263
- previous.motion.visible = false
264
- }
265
- DispatchQueue.main.asyncAfter(deadline: .now() + Self.switchDuration) { [weak self] in
266
- self?.leave(previous)
262
+ let animator = UIViewPropertyAnimator(
263
+ duration: Self.switchDuration,
264
+ controlPoint1: CGPoint(x: 0.25, y: 0.1),
265
+ controlPoint2: CGPoint(x: 0.25, y: 1)
266
+ ) {
267
+ selected.host.view.transform = .identity
268
+ previous.host.view.transform = CGAffineTransform(translationX: -offset, y: 0)
269
+ }
270
+ animator.addCompletion { [weak self] _ in self?.leave(previous) }
271
+ animator.startAnimation()
267
272
  }
268
273
  }
269
274
 
270
275
  private func makeTab(_ index: Int) -> Tab {
271
276
  let tab = Tab()
272
- let host = UIHostingController(rootView: rootView(index, tab))
277
+ let host = UIHostingController(rootView: rootView(index))
273
278
  host.view.backgroundColor = .clear
274
279
  addChild(host)
275
280
  host.didMove(toParent: self)
@@ -278,14 +283,20 @@ private final class TabController: UIViewController {
278
283
  return tab
279
284
  }
280
285
 
281
- private func rootView(_ index: Int, _ tab: Tab) -> AnyView {
282
- AnyView(TabCard(motion: tab.motion, content: content(index)).environment(\.self, environment))
286
+ private func rootView(_ index: Int) -> AnyView {
287
+ AnyView(content(index).environment(\.self, environment))
288
+ }
289
+
290
+ /// Bounds and center, a sliding tab carries a transform that frame doesn't work with.
291
+ private func place(_ subview: UIView) {
292
+ subview.bounds = view.bounds
293
+ subview.center = CGPoint(x: view.bounds.midX, y: view.bounds.midY)
283
294
  }
284
295
 
285
296
  private func attach(_ tab: Tab) {
286
297
  let hostView: UIView = tab.host.view
287
298
  hostView.isUserInteractionEnabled = true
288
- hostView.frame = view.bounds
299
+ place(hostView)
289
300
  if hostView.superview === view {
290
301
  view.bringSubviewToFront(hostView)
291
302
  } else {
@@ -297,6 +308,7 @@ private final class TabController: UIViewController {
297
308
  private func leave(_ tab: Tab) {
298
309
  guard selectedIndex.flatMap({ tabs[$0] }) !== tab else { return }
299
310
  tab.host.view.removeFromSuperview()
311
+ tab.host.view.transform = .identity
300
312
  }
301
313
 
302
314
  private func tearDown(_ tab: Tab) {
@@ -306,27 +318,9 @@ private final class TabController: UIViewController {
306
318
  }
307
319
  }
308
320
 
309
- private final class TabMotion: ObservableObject {
310
- @Published var visible = false
311
- }
312
-
313
- /// The tab switch: 0.97 scale + fade over 200ms, both ways (Compose's tab enter / exit transitions).
314
- private struct TabCard: View {
315
- @ObservedObject var motion: TabMotion
316
- let content: AnyView
317
-
318
- var body: some View {
319
- content
320
- .opacity(motion.visible ? 1 : 0)
321
- .scaleEffect(motion.visible ? 1 : 0.97)
322
- .animation(.easeInOut(duration: 0.2), value: motion.visible)
323
- }
324
- }
325
-
326
321
  /// Bottom safe-area inset (home indicator).
327
322
  private func safeAreaBottomInset() -> CGFloat {
328
- let bottomInset = UIApplication.shared.connectedScenes
323
+ UIApplication.shared.connectedScenes
329
324
  .compactMap { ($0 as? UIWindowScene)?.keyWindow?.safeAreaInsets.bottom }
330
325
  .first ?? 0
331
- return min(bottomInset, 21)
332
326
  }