@momo-kits/native-kits 0.168.1-beta.4 → 0.168.1-beta.40

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 (46) hide show
  1. package/CLAUDE.md +15 -10
  2. package/README.md +2 -10
  3. package/ios/Application/ApplicationEnvironment.swift +7 -6
  4. package/ios/Application/DesignSystemKits.swift +163 -0
  5. package/ios/Application/DesignSystemKitsPayload.swift +68 -0
  6. package/ios/Badge/BadgeRibbon.swift +8 -1
  7. package/ios/Extensions/Color++.swift +2 -4
  8. package/ios/Input/Input.swift +16 -4
  9. package/ios/Input/InputPhoneNumber.swift +1 -3
  10. package/ios/Input/InputSearch.swift +1 -2
  11. package/ios/Input/InputTextArea.swift +8 -4
  12. package/ios/InputMoney/InputMoney.swift +6 -7
  13. package/ios/Layout/ModalLayout.swift +152 -0
  14. package/ios/Layout/ScreenLayout.swift +77 -18
  15. package/ios/Navigation/BottomSheet.swift +56 -53
  16. package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
  17. package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
  18. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  19. package/ios/Navigation/BottomTab/DuoBarCompression.swift +2 -3
  20. package/ios/Navigation/BottomTab/DuoTabBar.swift +64 -172
  21. package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
  22. package/ios/Navigation/Component/HeaderBackground.swift +22 -1
  23. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  24. package/ios/Navigation/Component/SnackBar.swift +4 -0
  25. package/ios/Navigation/ModalScreen.swift +20 -5
  26. package/ios/Navigation/StackScreen.swift +6 -8
  27. package/ios/Popup/PopupDisplay.swift +6 -4
  28. package/ios/Popup/PopupInput.swift +6 -4
  29. package/ios/Popup/PopupLayout.swift +17 -11
  30. package/ios/Popup/PopupNotify.swift +32 -25
  31. package/ios/Stepper/Stepper.swift +1 -2
  32. package/ios/Template/TrustBanner/TrustBanner.swift +4 -2
  33. package/ios/Typography/FontScale.swift +29 -15
  34. package/ios/Typography/Text.swift +88 -14
  35. package/ios/Typography/Typography.swift +2 -2
  36. package/ios/native-kits.podspec +1 -1
  37. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  38. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  39. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  40. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  41. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
  42. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
  43. package/package.json +1 -1
  44. package/publish.sh +2 -33
  45. package/ios/Typography/FontScaleStore.swift +0 -58
  46. package/ios/Typography/KitDesignSystem.swift +0 -17
@@ -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
+ }
@@ -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
  }