@momo-kits/native-kits 0.168.1-beta.37-debug → 0.168.1-beta.38-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.
- package/CLAUDE.md +2 -3
- package/compose/build.gradle.kts +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +81 -72
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +13 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +163 -54
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +12 -17
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +34 -27
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +319 -167
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +93 -326
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +3 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -2
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +3 -2
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +3 -9
- package/ios/Input/Input.swift +1 -3
- package/ios/Input/InputTextArea.swift +1 -3
- package/ios/Layout/ScreenLayout.swift +24 -28
- package/ios/Navigation/BottomSheet.swift +157 -29
- package/ios/Navigation/BottomTab/BottomTab.swift +48 -67
- package/ios/Navigation/BottomTab/BottomTabBar.swift +280 -132
- package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
- package/ios/Navigation/BottomTab/DuoTabBar.swift +72 -292
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/ModalScreen.swift +7 -18
- package/ios/Navigation/StackScreen.swift +3 -1
- package/ios/Popup/PopupDisplay.swift +2 -4
- package/ios/Popup/PopupInput.swift +2 -4
- package/ios/Popup/PopupLayout.swift +9 -10
- package/ios/Popup/PopupNotify.swift +23 -26
- package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
- package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +0 -103
- package/package.json +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -187
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +0 -380
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
- package/ios/Layout/ModalLayout.swift +0 -152
- package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +0 -364
|
@@ -10,12 +10,10 @@ 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.
|
|
14
13
|
@Immutable
|
|
15
14
|
internal data class ReservedRegions(
|
|
16
15
|
val occlusion: List<ReservedRegion> = emptyList(),
|
|
17
16
|
val isFoldable: Boolean = false,
|
|
18
|
-
val division: ReservedRegion? = null,
|
|
19
17
|
)
|
|
20
18
|
|
|
21
19
|
@Composable
|
|
@@ -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
|
|
|
@@ -75,11 +75,10 @@ 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.
|
|
79
78
|
@OptIn(ExperimentalForeignApi::class)
|
|
80
|
-
private fun UIView.
|
|
79
|
+
private fun UIView.occlusionRegions(target: UIView): List<ReservedRegion> {
|
|
81
80
|
if (window == null || !respondsToSelector(regionsOfKind)) return emptyList()
|
|
82
|
-
val kind = regionKind(
|
|
81
|
+
val kind = regionKind("occlusionRegionKind") ?: return emptyList()
|
|
83
82
|
val regions = when (val result = performSelector(regionsOfKind, withObject = kind)) {
|
|
84
83
|
is List<*> -> result
|
|
85
84
|
is NSArray -> List(result.count.toInt()) { result.objectAtIndex(it.toULong()) }
|
|
@@ -110,12 +109,7 @@ private class ReservedRegionsProbe(
|
|
|
110
109
|
super.layoutSubviews()
|
|
111
110
|
// re-read until found: the window may not report the hinge on the first pass
|
|
112
111
|
if (!isKnownFoldable) isKnownFoldable = hasDivisionRegion()
|
|
113
|
-
val
|
|
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
|
-
)
|
|
112
|
+
val regions = ReservedRegions(superview?.let { occlusionRegions(it) } ?: emptyList(), isKnownFoldable)
|
|
119
113
|
if (regions != last) {
|
|
120
114
|
last = regions
|
|
121
115
|
onChange(regions)
|
package/ios/Input/Input.swift
CHANGED
|
@@ -252,9 +252,7 @@ public struct Input: View {
|
|
|
252
252
|
}
|
|
253
253
|
.padding(.horizontal, Spacing.S)
|
|
254
254
|
.background(theme.colors.background.surface)
|
|
255
|
-
|
|
256
|
-
.fixedSize(horizontal: false, vertical: true)
|
|
257
|
-
.frame(height: 0)
|
|
255
|
+
.alignmentGuide(.top) { $0[VerticalAlignment.center] }
|
|
258
256
|
.offset(x: Spacing.S)
|
|
259
257
|
}
|
|
260
258
|
}
|
|
@@ -279,9 +279,7 @@ public struct InputTextArea: View {
|
|
|
279
279
|
}
|
|
280
280
|
.padding(.horizontal, Spacing.S)
|
|
281
281
|
.background(theme.colors.background.surface)
|
|
282
|
-
|
|
283
|
-
.fixedSize(horizontal: false, vertical: true)
|
|
284
|
-
.frame(height: 0)
|
|
282
|
+
.alignmentGuide(.top) { $0[VerticalAlignment.center] }
|
|
285
283
|
.offset(x: Spacing.S)
|
|
286
284
|
}
|
|
287
285
|
}
|
|
@@ -46,8 +46,6 @@ 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?
|
|
51
49
|
|
|
52
50
|
public var headerBarHeight: CGFloat { headerHeight - headerStatusBarHeight }
|
|
53
51
|
}
|
|
@@ -78,6 +76,11 @@ enum DuoMetrics {
|
|
|
78
76
|
static let floatingTabBarHeight: CGFloat = 62
|
|
79
77
|
static let floatingTabBarMargin: CGFloat = 20
|
|
80
78
|
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
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
enum HeaderMetrics {
|
|
@@ -113,14 +116,11 @@ extension ScreenLayout {
|
|
|
113
116
|
insets: EdgeInsets,
|
|
114
117
|
reservedRegions: [CGRect] = ReservedRegions.current,
|
|
115
118
|
isPhone: Bool = isPhoneIdiom,
|
|
116
|
-
isFoldable: Bool = FoldableDevice.isFoldable(measuredIn: keyWindow)
|
|
117
|
-
division: CGRect? = FoldableDevice.halfFoldedHinge
|
|
119
|
+
isFoldable: Bool = FoldableDevice.isFoldable(measuredIn: keyWindow)
|
|
118
120
|
) -> ScreenLayout {
|
|
119
121
|
let width = size.width
|
|
120
122
|
let height = size.height
|
|
121
123
|
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
|
|
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
|
|
195
195
|
)
|
|
196
196
|
}
|
|
197
197
|
|
|
@@ -265,6 +265,15 @@ 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
|
+
}
|
|
268
277
|
}
|
|
269
278
|
|
|
270
279
|
/// Snapshot for call sites without `\.screenLayout`; not reactive. `windowSize` is ignored,
|
|
@@ -281,12 +290,6 @@ public func isIPhoneDuoDevice(windowSize: CGSize? = nil) -> Bool {
|
|
|
281
290
|
enum FoldableDevice {
|
|
282
291
|
// a hinge never goes away, so a positive answer is kept
|
|
283
292
|
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
293
|
|
|
291
294
|
static func isFoldable(measuredIn view: UIView?) -> Bool {
|
|
292
295
|
if isKnownFoldable { return true }
|
|
@@ -303,11 +306,8 @@ enum FoldableDevice {
|
|
|
303
306
|
#if canImport(UIKit, _version: 9127.0.85.28)
|
|
304
307
|
guard #available(iOS 27.1, *) else { return }
|
|
305
308
|
view.addInteraction(UIHingeInteraction { _, update in
|
|
306
|
-
guard
|
|
307
|
-
let partiallyOpen = hinge.status == .partiallyOpen
|
|
308
|
-
guard !isKnownFoldable || partiallyOpen != isPartiallyOpen else { return }
|
|
309
|
+
guard update.hinge != nil, !isKnownFoldable else { return }
|
|
309
310
|
isKnownFoldable = true
|
|
310
|
-
isPartiallyOpen = partiallyOpen
|
|
311
311
|
NotificationCenter.default.post(name: ReservedRegions.didChange, object: nil)
|
|
312
312
|
})
|
|
313
313
|
#endif
|
|
@@ -318,17 +318,14 @@ 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.
|
|
322
321
|
enum ReservedRegions {
|
|
323
322
|
// last report of a probe, so `ScreenLayout.current` includes it
|
|
324
323
|
private(set) static var current: [CGRect] = []
|
|
325
|
-
private(set) static var division: CGRect?
|
|
326
324
|
static let didChange = Notification.Name("MoMoUIKitsReservedRegionsDidChange")
|
|
327
325
|
|
|
328
|
-
fileprivate static func publish(_ regions: [CGRect]
|
|
329
|
-
guard regions != current
|
|
326
|
+
fileprivate static func publish(_ regions: [CGRect]) {
|
|
327
|
+
guard regions != current else { return }
|
|
330
328
|
current = regions
|
|
331
|
-
self.division = division
|
|
332
329
|
NotificationCenter.default.post(name: didChange, object: nil)
|
|
333
330
|
}
|
|
334
331
|
}
|
|
@@ -347,13 +344,12 @@ private final class ReservedRegionsProbe: UIView {
|
|
|
347
344
|
override func layoutSubviews() {
|
|
348
345
|
super.layoutSubviews()
|
|
349
346
|
// read even when not publishing, so UIKit keeps re-running this when they change
|
|
350
|
-
let regions =
|
|
351
|
-
let division = activeRegions(kind: "divisionRegionKind").first
|
|
347
|
+
let regions = occlusionRegions()
|
|
352
348
|
// every screen has a probe but the regions are window-wide: one sliding in on a push or
|
|
353
349
|
// a present, or off the window, would overwrite them with a partial read
|
|
354
350
|
guard spansWindow else { return }
|
|
355
351
|
// layout pass: publish on the next turn instead of mutating SwiftUI state mid-update
|
|
356
|
-
DispatchQueue.main.async { ReservedRegions.publish(regions
|
|
352
|
+
DispatchQueue.main.async { ReservedRegions.publish(regions) }
|
|
357
353
|
}
|
|
358
354
|
|
|
359
355
|
private var spansWindow: Bool {
|
|
@@ -368,11 +364,11 @@ private final class ReservedRegionsProbe: UIView {
|
|
|
368
364
|
}
|
|
369
365
|
|
|
370
366
|
// The API is newer than the SDKs hosts may build with, so it is reached through the runtime.
|
|
371
|
-
private func
|
|
367
|
+
private func occlusionRegions() -> [CGRect] {
|
|
372
368
|
let regionsOfKind = NSSelectorFromString("reservedRegionsOfKind:")
|
|
373
369
|
guard window != nil, responds(to: regionsOfKind),
|
|
374
370
|
let kindType = NSClassFromString("UIViewReservedRegionKind") as? NSObject.Type,
|
|
375
|
-
let kind = (kindType as AnyObject).perform(NSSelectorFromString(
|
|
371
|
+
let kind = (kindType as AnyObject).perform(NSSelectorFromString("occlusionRegionKind"))?.takeUnretainedValue(),
|
|
376
372
|
let regions = perform(regionsOfKind, with: kind)?.takeUnretainedValue() as? [NSObject]
|
|
377
373
|
else { return [] }
|
|
378
374
|
return regions.compactMap { ($0.value(forKey: "frame") as? NSValue)?.cgRectValue }
|
|
@@ -80,17 +80,56 @@ struct BottomSheetView<Content: View>: View {
|
|
|
80
80
|
private let indicatorHeight: CGFloat = 16
|
|
81
81
|
private let headerRowHeight: CGFloat = 56
|
|
82
82
|
|
|
83
|
-
///
|
|
84
|
-
///
|
|
85
|
-
private let maxDynamicAlpha: CGFloat = 0.
|
|
86
|
-
|
|
87
|
-
private var modal: ModalLayout { layout.modalLayout }
|
|
88
|
-
private var isFoldable: Bool { modal.isFoldable }
|
|
83
|
+
/// Mirrors Compose's per-term peak (0.3f). Combined with `backgroundAlpha` the
|
|
84
|
+
/// steady-state (fully open) scrim peaks at 0.6, matching ModalScreen's peak.
|
|
85
|
+
private let maxDynamicAlpha: CGFloat = 0.3
|
|
89
86
|
|
|
90
87
|
// UIScreen stays on the outer display on iPhone Duo, even when unfolded
|
|
91
|
-
private var screenHeight: CGFloat {
|
|
88
|
+
private var screenHeight: CGFloat { isDuo ? layout.height : UIScreen.main.bounds.height }
|
|
89
|
+
|
|
90
|
+
private var isDuo: Bool { layout.isDuoDevice }
|
|
91
|
+
// iPhone Duo inner display: center the sheet instead of spanning the width
|
|
92
|
+
// short side, as RN: the outer display stays floating in landscape (678pt wide) too
|
|
93
|
+
private var isDuoCentered: Bool { isDuo && min(layout.width, layout.height) >= 600 }
|
|
94
|
+
/// Outer display: the sheet floats Spacing.M off the side edges like system sheets, its content
|
|
95
|
+
/// stays in the safe area and its buttons move to the side bar column (HIG).
|
|
96
|
+
private var isDuoFloating: Bool { isDuo && !isDuoCentered }
|
|
97
|
+
|
|
98
|
+
private var titleBack: BottomSheetHeader.Back? {
|
|
99
|
+
if case .title(_, let back) = header.style { return back }
|
|
100
|
+
return nil
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private var sideColumn: SideBarLayout? {
|
|
104
|
+
guard isDuoFloating, case .title = header.style, let sideBar = layout.sideBar,
|
|
105
|
+
sideBar.width - Spacing.M >= DuoMetrics.controlSize + Spacing.M
|
|
106
|
+
else { return nil }
|
|
107
|
+
return sideBar
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/// Keeps the portrait width in landscape, like system sheets.
|
|
111
|
+
private var duoCenteredWidth: CGFloat {
|
|
112
|
+
min(
|
|
113
|
+
min(layout.width, layout.height) - Spacing.L * 2,
|
|
114
|
+
layout.width - max(layout.insets.leading, layout.insets.trailing, Spacing.L) * 2
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// The floating sheet spans the side safe area, its content stays clear of it.
|
|
119
|
+
private var sideInsetLeading: CGFloat {
|
|
120
|
+
isDuoFloating ? max(layout.insets.leading - Spacing.M, 0) : 0
|
|
121
|
+
}
|
|
92
122
|
|
|
93
|
-
private var
|
|
123
|
+
private var sideInsetTrailing: CGFloat {
|
|
124
|
+
isDuoFloating ? max(layout.insets.trailing - Spacing.M, 0) : 0
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private var maxHeight: CGFloat {
|
|
128
|
+
guard isDuo else { return screenHeight - 90 }
|
|
129
|
+
// stays below the side status bar: unlike RN (StatusBar.pushStackEntry) nothing restyles it, so a light
|
|
130
|
+
// clock over the sheet would vanish
|
|
131
|
+
return layout.height - max(layout.duoTopInset, Spacing.XL)
|
|
132
|
+
}
|
|
94
133
|
private var bottomInset: CGFloat { useBottomInset ? safeAreaBottomInset() : 0 }
|
|
95
134
|
/// While the keyboard is up, it already covers the home-indicator area, so it
|
|
96
135
|
/// replaces (rather than adds to) the usual bottom-inset filler.
|
|
@@ -112,15 +151,15 @@ struct BottomSheetView<Content: View>: View {
|
|
|
112
151
|
return progress * maxDynamicAlpha
|
|
113
152
|
}
|
|
114
153
|
|
|
115
|
-
/// Mirrors Compose's `alpha =
|
|
116
|
-
/// scrim peaks at
|
|
154
|
+
/// Mirrors Compose's `alpha = backgroundAlpha + dynamicAlpha`: additive, so the
|
|
155
|
+
/// scrim peaks at 0.6 at rest and only fades to a 0.3 floor while dragging
|
|
117
156
|
/// (backgroundAlpha holds steady until an explicit close()).
|
|
118
|
-
private var totalScrimAlpha: CGFloat {
|
|
157
|
+
private var totalScrimAlpha: CGFloat { backgroundAlpha + dynamicAlpha }
|
|
119
158
|
|
|
120
159
|
var body: some View {
|
|
121
160
|
ZStack(alignment: .bottom) {
|
|
122
|
-
// Dimmed scrim — additive backgroundAlpha + dynamicAlpha (see above)
|
|
123
|
-
|
|
161
|
+
// Dimmed scrim — additive backgroundAlpha + dynamicAlpha (see above).
|
|
162
|
+
Color.black.opacity(totalScrimAlpha)
|
|
124
163
|
.contentShape(Rectangle())
|
|
125
164
|
.onTapGesture {
|
|
126
165
|
if barrierDismissible { close() }
|
|
@@ -160,9 +199,12 @@ struct BottomSheetView<Content: View>: View {
|
|
|
160
199
|
.fill(Colors.black06)
|
|
161
200
|
.frame(width: 40, height: 4)
|
|
162
201
|
Spacer().frame(height: 4)
|
|
202
|
+
// the handle centers on the whole sheet, only the header row keeps clear of the strip
|
|
163
203
|
headerView
|
|
164
204
|
.frame(height: headerRowHeight)
|
|
165
205
|
.padding(.horizontal, Spacing.M)
|
|
206
|
+
.padding(.leading, sideInsetLeading)
|
|
207
|
+
.padding(.trailing, sideInsetTrailing)
|
|
166
208
|
}
|
|
167
209
|
.frame(maxWidth: .infinity)
|
|
168
210
|
.frame(height: indicatorHeight + headerRowHeight)
|
|
@@ -172,18 +214,19 @@ struct BottomSheetView<Content: View>: View {
|
|
|
172
214
|
Rectangle()
|
|
173
215
|
.fill(theme.colors.border.default)
|
|
174
216
|
.frame(height: 1)
|
|
217
|
+
.padding(.leading, sideInsetLeading)
|
|
218
|
+
.padding(.trailing, sideInsetTrailing)
|
|
175
219
|
|
|
176
220
|
content()
|
|
221
|
+
.padding(.leading, sideInsetLeading)
|
|
222
|
+
.padding(.trailing, sideInsetTrailing)
|
|
177
223
|
// a tall sheet keeps its header (and footer) and gives the content what is left
|
|
178
224
|
.layoutPriority(-1)
|
|
179
225
|
|
|
180
226
|
if let footer {
|
|
181
|
-
|
|
182
|
-
Spacer(minLength: 0).layoutPriority(-2)
|
|
183
|
-
BottomSheetFooter(content: footer)
|
|
227
|
+
BottomSheetFooter(content: footer, leadingInset: sideInsetLeading, trailingInset: sideInsetTrailing)
|
|
184
228
|
}
|
|
185
229
|
}
|
|
186
|
-
.frame(minHeight: max(modal.sheet.minHeight - effectiveBottomInset, 0), alignment: .top)
|
|
187
230
|
// The filler stays outside the cap, which shrinks by it instead: the sheet still ends at
|
|
188
231
|
// `maxHeight`, and the iOS 15 fallback never measures the keyboard as content.
|
|
189
232
|
.modifier(CapHeight(maxHeight: maxHeight - effectiveBottomInset))
|
|
@@ -191,8 +234,7 @@ struct BottomSheetView<Content: View>: View {
|
|
|
191
234
|
(footer != nil ? theme.colors.background.surface : backgroundColor)
|
|
192
235
|
.frame(height: effectiveBottomInset)
|
|
193
236
|
}
|
|
194
|
-
.frame(
|
|
195
|
-
.frame(maxWidth: modal.sheet.width == nil ? .infinity : nil)
|
|
237
|
+
.frame(maxWidth: isDuoCentered ? duoCenteredWidth : .infinity)
|
|
196
238
|
.clipped()
|
|
197
239
|
.background(
|
|
198
240
|
GeometryReader { geo in
|
|
@@ -200,31 +242,56 @@ struct BottomSheetView<Content: View>: View {
|
|
|
200
242
|
}
|
|
201
243
|
)
|
|
202
244
|
.background(backgroundColor)
|
|
203
|
-
.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
245
|
+
.overlay {
|
|
246
|
+
if let sideColumn {
|
|
247
|
+
BottomSheetSideColumn(
|
|
248
|
+
sideBar: sideColumn,
|
|
249
|
+
windowHeight: layout.height,
|
|
250
|
+
topOffset: indicatorHeight + (headerRowHeight - DuoMetrics.controlSize) / 2,
|
|
251
|
+
back: titleBack,
|
|
252
|
+
onBack: goBack,
|
|
253
|
+
onClose: { close() }
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
.clipShape(RoundedCorner(radius: isDuo ? Radius.XL : Radius.M, corners: [.topLeft, .topRight]))
|
|
258
|
+
.padding(.horizontal, isDuoFloating ? Spacing.M : 0)
|
|
207
259
|
}
|
|
208
260
|
|
|
209
261
|
@ViewBuilder
|
|
210
262
|
private var headerView: some View {
|
|
211
263
|
switch header.style {
|
|
212
264
|
case .title(let text, let back):
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
265
|
+
// the side column holds back and close, the row keeps only the title
|
|
266
|
+
let showsButtons = sideColumn == nil
|
|
267
|
+
HStack(spacing: 0) {
|
|
268
|
+
if showsButtons {
|
|
269
|
+
if let back {
|
|
270
|
+
headerButton(icon: back.icon, accessibilityId: "btn_bottom_sheet_back") { goBack(back) }
|
|
271
|
+
} else {
|
|
272
|
+
Color.clear.frame(width: 24, height: 24)
|
|
273
|
+
}
|
|
218
274
|
}
|
|
219
275
|
MomoText(text, typography: .headerDefaultBold, color: Colors.black17)
|
|
220
276
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
221
|
-
|
|
277
|
+
.padding(.horizontal, showsButtons ? 0 : Spacing.M)
|
|
278
|
+
if showsButtons {
|
|
279
|
+
headerButton(icon: "navigation_close", accessibilityId: "btn_bottom_sheet_close") { close() }
|
|
280
|
+
}
|
|
222
281
|
}
|
|
223
282
|
case .custom(let builder):
|
|
224
283
|
builder()
|
|
225
284
|
}
|
|
226
285
|
}
|
|
227
286
|
|
|
287
|
+
private func headerButton(icon: String, accessibilityId: String, action: @escaping () -> Void) -> some View {
|
|
288
|
+
Icon(source: icon, size: 24, color: Colors.black17)
|
|
289
|
+
.frame(width: 24, height: 24)
|
|
290
|
+
.contentShape(Rectangle())
|
|
291
|
+
.onTapGesture(perform: action)
|
|
292
|
+
.accessibilityIdentifier(accessibilityId)
|
|
293
|
+
}
|
|
294
|
+
|
|
228
295
|
/// RN `leftOptions.onPressIconLeft`: the sheet closes first, then the back runs.
|
|
229
296
|
private func goBack(_ back: BottomSheetHeader.Back) {
|
|
230
297
|
close(then: back.action)
|
|
@@ -302,6 +369,63 @@ struct BottomSheetView<Content: View>: View {
|
|
|
302
369
|
}
|
|
303
370
|
}
|
|
304
371
|
|
|
372
|
+
/// iPhone Duo outer display: back and close sit on the part of the sheet under the side safe area,
|
|
373
|
+
/// 12pt from the strip's inner edge like the screen side bar. They follow the header row while the
|
|
374
|
+
/// sheet is short and stay below the status bar cluster while it is tall.
|
|
375
|
+
private struct BottomSheetSideColumn: View {
|
|
376
|
+
let sideBar: SideBarLayout
|
|
377
|
+
let windowHeight: CGFloat
|
|
378
|
+
/// Lines the controls up with the header row.
|
|
379
|
+
let topOffset: CGFloat
|
|
380
|
+
let back: BottomSheetHeader.Back?
|
|
381
|
+
let onBack: (BottomSheetHeader.Back) -> Void
|
|
382
|
+
let onClose: () -> Void
|
|
383
|
+
|
|
384
|
+
@Environment(\.appTheme) private var theme
|
|
385
|
+
|
|
386
|
+
private var isRight: Bool { sideBar.edge == .right }
|
|
387
|
+
|
|
388
|
+
private var columnHeight: CGFloat {
|
|
389
|
+
let count: CGFloat = back != nil ? 2 : 1
|
|
390
|
+
return count * DuoMetrics.controlSize + (count - 1) * Spacing.M
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
private var headerColor: HeaderColor {
|
|
394
|
+
getHeaderColor(isAnimated: false, isSurface: true, opacity: 1, tintColor: nil, defaultColor: theme.colors.text.default)
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
var body: some View {
|
|
398
|
+
GeometryReader { proxy in
|
|
399
|
+
let sheetHeight = proxy.size.height
|
|
400
|
+
// the sheet rests on the window bottom; its slide is an offset outside this layout
|
|
401
|
+
let sheetTop = windowHeight - sheetHeight
|
|
402
|
+
// clear of a camera at the bottom end of the strip when it can
|
|
403
|
+
let lowest = sheetHeight - sideBar.bottom - columnHeight
|
|
404
|
+
let top = max(min(max(sideBar.top - sheetTop, topOffset), lowest), 0)
|
|
405
|
+
VStack(alignment: isRight ? .leading : .trailing, spacing: Spacing.M) {
|
|
406
|
+
if let back {
|
|
407
|
+
SideBarButton(
|
|
408
|
+
icon: back.icon,
|
|
409
|
+
headerColor: headerColor,
|
|
410
|
+
accessibilityId: "btn_bottom_sheet_back",
|
|
411
|
+
action: { onBack(back) }
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
SideBarButton(
|
|
415
|
+
icon: "navigation_close",
|
|
416
|
+
headerColor: headerColor,
|
|
417
|
+
accessibilityId: "btn_bottom_sheet_close",
|
|
418
|
+
action: onClose
|
|
419
|
+
)
|
|
420
|
+
}
|
|
421
|
+
.padding(isRight ? .leading : .trailing, Spacing.M)
|
|
422
|
+
.frame(width: sideBar.width - Spacing.M, alignment: isRight ? .leading : .trailing)
|
|
423
|
+
.padding(.top, top)
|
|
424
|
+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: isRight ? .topTrailing : .topLeading)
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
305
429
|
/// Compose's `heightIn(max:)`. `.frame(maxHeight:)` grows to the cap whenever the proposal is
|
|
306
430
|
/// larger, leaving a gap above the header; this sizes the sheet to its content and only caps it
|
|
307
431
|
/// when taller.
|
|
@@ -374,12 +498,16 @@ private struct CapHeightLayout: Layout {
|
|
|
374
498
|
/// Mirrors Compose's `BottomSheetFooter`: a surface band with a soft shadow cast on the content.
|
|
375
499
|
private struct BottomSheetFooter: View {
|
|
376
500
|
let content: () -> AnyView
|
|
501
|
+
var leadingInset: CGFloat = 0
|
|
502
|
+
var trailingInset: CGFloat = 0
|
|
377
503
|
|
|
378
504
|
@Environment(\.appTheme) private var theme
|
|
379
505
|
|
|
380
506
|
var body: some View {
|
|
381
507
|
content()
|
|
382
508
|
.frame(maxWidth: .infinity)
|
|
509
|
+
.padding(.leading, leadingInset)
|
|
510
|
+
.padding(.trailing, trailingInset)
|
|
383
511
|
.padding(.vertical, Spacing.S)
|
|
384
512
|
.background(theme.colors.background.surface)
|
|
385
513
|
.overlay(alignment: .top) {
|