@momo-kits/native-kits 0.168.1-beta.33 → 0.168.1-beta.34
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 -2
- package/ios/Layout/ModalLayout.swift +125 -0
- package/ios/Layout/ScreenLayout.swift +28 -24
- package/ios/Navigation/BottomSheet.swift +40 -153
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/ModalScreen.swift +18 -7
- package/ios/Popup/PopupLayout.swift +9 -8
- package/ios/Popup/PopupNotify.swift +36 -23
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +0 -90
- package/package.json +1 -1
package/CLAUDE.md
CHANGED
|
@@ -81,8 +81,8 @@ Publishing is automated (`publish.sh` + GitLab CI on `[ci build]` / `main`). Do
|
|
|
81
81
|
- Bar compression (`bottomtab/DuoBarCompression.kt`, HIG "Vertical controls"): when toolbar + rail don't fit in the strip, one is compressed — the toolkit into a `navigation_menu` button, the rail into one button showing the current tab — and tapping it swaps them; `BottomTab(compressionBehavior)` picks which starts compressed. If neither fits beside the other compressed, both rest compressed and a tap opens one for a moment. Side bar columns report their full height (0 when the screen puts nothing there) so the decision follows each screen's toolkit.
|
|
82
82
|
- Glass header: on Duo with a side bar, Default/Extended headers without search and with a `ScrollState` let content scroll under the bar (`usesDuoGlassHeader`); the bar fades in a translucent surface + hairline over 16pt (Compose has no backdrop blur — RN's fallback look), the gradient leaves with the content.
|
|
83
83
|
- Quick return header: glass headers and Animated headers (with a `ScrollState`) on the Duo side bar layout slide out with the content and back in on a reverse scroll; a half-shown header settles in or out once the scroll stops. The side bar is drawn apart from the header, so it stays put.
|
|
84
|
-
- Overlays on
|
|
85
|
-
- Bottom sheet on Duo:
|
|
84
|
+
- Overlays on foldables (`layout/ModalLayout.kt` / `ios/Layout/ModalLayout.swift`, Figma "Modal - Foldable Guideline", constants shared with RN): foldable = `isIPhoneDuoDevice` or a window short side ≥ 600, so phones (landscape too) keep their look. The resolver returns the placement (safe area, so left of the Duo control column; right of an active vertical division when a Duo is half folded — Swift also needs `UIHingeInteraction` `.partiallyOpen`; Android half fold stays flat), popup geometry (width clamp(placement − 2·margin, 280, 450), margin 24 or 12 on the Duo outer display / half fold, max height min(600, placement − 48), radius 24; only the PopupNotify description scrolls) and sheet geometry (width min(placement − 24, 653) ≥ 296, bottom anchored, max height window − top inset − 12, min height 230, radius 24 top). Scrim is black 20% over the whole window on foldables (0.6 on phones). Close / back are 32pt icon buttons with a 20pt icon, 12pt from the edges. Snackbars keep clear of the strip.
|
|
85
|
+
- Bottom sheet on Duo: stays in the placement, never on or under the side strip; back / close stay in the header row (no side column). `BottomHeader.Title(onBack)` / `.title(onBack:)` closes the sheet, then runs (RN `leftOptions.onPressIconLeft`).
|
|
86
86
|
- Font scale deliberately uses the short side (`min(w, h)`), unlike RN which reads the window width — landscape must not inflate every font.
|
|
87
87
|
- Font scale measures the **window**, never `UIScreen.main`: on iPhone Duo the main screen stays on one display while the window follows the one in use. Compose iOS `getScreenDimensions()` reads `LocalWindowInfo.containerSize` (recomposes on fold/unfold); SwiftUI `DesignSystemKits` KVO-observes each `UIWindowScene.effectiveGeometry` and republishes `windowShortSide`.
|
|
88
88
|
- `StackScreen` pads content/footer/search/FAB by the side insets and provides an inset-consumed layout to its content; a bottom-tab root stays full width (tab bar + each tab's StackScreen handle insets). Grid columns use `contentWidth`.
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
enum ModalMetrics {
|
|
12
|
+
static let popupMaxWidth: CGFloat = 450
|
|
13
|
+
static let popupMinWidth: CGFloat = 280
|
|
14
|
+
static let popupMaxHeight: CGFloat = 600
|
|
15
|
+
static let sheetMaxWidth: CGFloat = 653
|
|
16
|
+
static let sheetMinWidth: CGFloat = 296
|
|
17
|
+
static let sheetMinHeight: CGFloat = 230
|
|
18
|
+
static let foldableMinWidth: CGFloat = 600
|
|
19
|
+
static let iconButtonSize: CGFloat = 32
|
|
20
|
+
static let iconSize: CGFloat = 20
|
|
21
|
+
static let phoneScrimOpacity: CGFloat = 0.6
|
|
22
|
+
static let foldableScrimOpacity: CGFloat = 0.2
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
struct PopupGeometry: Equatable {
|
|
26
|
+
let minWidth: CGFloat
|
|
27
|
+
let maxWidth: CGFloat
|
|
28
|
+
/// nil: as tall as the content, phones keep their own caps
|
|
29
|
+
let maxHeight: CGFloat?
|
|
30
|
+
let margin: CGFloat
|
|
31
|
+
let radius: CGFloat
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
struct SheetGeometry: Equatable {
|
|
35
|
+
/// nil: spans the window
|
|
36
|
+
let width: CGFloat?
|
|
37
|
+
/// nil: phones keep their own cap
|
|
38
|
+
let maxHeight: CGFloat?
|
|
39
|
+
let minHeight: CGFloat
|
|
40
|
+
let margin: CGFloat
|
|
41
|
+
let radius: CGFloat
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
struct ModalLayout: Equatable {
|
|
45
|
+
let isFoldable: Bool
|
|
46
|
+
/// Window coordinates of the area popups center in and sheets rest on the bottom of.
|
|
47
|
+
let placement: CGRect
|
|
48
|
+
let popup: PopupGeometry
|
|
49
|
+
let sheet: SheetGeometry
|
|
50
|
+
let scrimOpacity: CGFloat
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
extension ScreenLayout {
|
|
54
|
+
/// Foldable = iPhone Duo or a window whose short side is at least 600 (RN parity), so phones
|
|
55
|
+
/// in landscape keep their look.
|
|
56
|
+
var modalLayout: ModalLayout {
|
|
57
|
+
let isFoldable = isDuoDevice || min(width, height) >= ModalMetrics.foldableMinWidth
|
|
58
|
+
guard isFoldable else {
|
|
59
|
+
let placement = CGRect(x: 0, y: 0, width: width, height: height)
|
|
60
|
+
return ModalLayout(
|
|
61
|
+
isFoldable: false,
|
|
62
|
+
placement: placement,
|
|
63
|
+
popup: Self.popupGeometry(placementWidth: width, maxHeight: nil, margin: Spacing.XL, radius: Radius.L),
|
|
64
|
+
sheet: SheetGeometry(width: nil, maxHeight: nil, minHeight: 0, margin: 0, radius: Radius.M),
|
|
65
|
+
scrimOpacity: ModalMetrics.phoneScrimOpacity
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// the safe area keeps overlays clear of the iPhone Duo control column; half folded they move to the right half
|
|
70
|
+
let hinge = self.hinge.flatMap { isDuoDevice && $0.minX > 0 && $0.maxX < width ? $0 : nil }
|
|
71
|
+
let left = max(insets.leading, hinge?.maxX ?? 0)
|
|
72
|
+
let placement = CGRect(
|
|
73
|
+
x: left,
|
|
74
|
+
y: insets.top,
|
|
75
|
+
width: max(width - insets.trailing - left, 0),
|
|
76
|
+
height: max(height - insets.top - insets.bottom, 0)
|
|
77
|
+
)
|
|
78
|
+
// outer display and half fold leave little room, so the margins tighten
|
|
79
|
+
let isCompact = isDuoDevice && (hinge != nil || min(width, height) < ModalMetrics.foldableMinWidth)
|
|
80
|
+
let sheetMargin = Spacing.M
|
|
81
|
+
let sheetMaxHeight = height - insets.top - sheetMargin
|
|
82
|
+
let sheetMinWidth = min(ModalMetrics.sheetMinWidth, placement.width)
|
|
83
|
+
return ModalLayout(
|
|
84
|
+
isFoldable: true,
|
|
85
|
+
placement: placement,
|
|
86
|
+
popup: Self.popupGeometry(
|
|
87
|
+
placementWidth: placement.width,
|
|
88
|
+
maxHeight: min(ModalMetrics.popupMaxHeight, placement.height - Spacing.XL * 2),
|
|
89
|
+
margin: isCompact ? Spacing.M : Spacing.XL,
|
|
90
|
+
radius: Radius.XL
|
|
91
|
+
),
|
|
92
|
+
sheet: SheetGeometry(
|
|
93
|
+
width: max(min(placement.width - sheetMargin * 2, ModalMetrics.sheetMaxWidth), sheetMinWidth),
|
|
94
|
+
maxHeight: sheetMaxHeight,
|
|
95
|
+
minHeight: min(ModalMetrics.sheetMinHeight, sheetMaxHeight),
|
|
96
|
+
margin: sheetMargin,
|
|
97
|
+
radius: Radius.XL
|
|
98
|
+
),
|
|
99
|
+
scrimOpacity: ModalMetrics.foldableScrimOpacity
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// clamp(placement - 2 margin, 280, 450); the 280 floor gives way to a narrower placement.
|
|
104
|
+
private static func popupGeometry(placementWidth: CGFloat, maxHeight: CGFloat?, margin: CGFloat, radius: CGFloat) -> PopupGeometry {
|
|
105
|
+
let minWidth = min(ModalMetrics.popupMinWidth, placementWidth)
|
|
106
|
+
let maxWidth = min(max(placementWidth - margin * 2, minWidth), max(ModalMetrics.popupMaxWidth, minWidth))
|
|
107
|
+
return PopupGeometry(minWidth: minWidth, maxWidth: maxWidth, maxHeight: maxHeight, margin: margin, radius: radius)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// Popup / sheet close and back on foldables: 32 icon button, 20 icon.
|
|
112
|
+
struct ModalIconButton: View {
|
|
113
|
+
@Environment(\.appTheme) private var theme
|
|
114
|
+
let icon: String
|
|
115
|
+
let accessibilityId: String
|
|
116
|
+
let action: () -> Void
|
|
117
|
+
|
|
118
|
+
var body: some View {
|
|
119
|
+
Icon(source: icon, size: ModalMetrics.iconSize, color: theme.colors.text.default)
|
|
120
|
+
.frame(width: ModalMetrics.iconButtonSize, height: ModalMetrics.iconButtonSize)
|
|
121
|
+
.contentShape(Rectangle())
|
|
122
|
+
.onTapGesture(perform: action)
|
|
123
|
+
.accessibilityIdentifier(accessibilityId)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -46,6 +46,8 @@ public struct ScreenLayout: Equatable {
|
|
|
46
46
|
public let sideBar: SideBarLayout?
|
|
47
47
|
/// iPhone Duo inner display in portrait: the header row shares the status bar band, between its clusters.
|
|
48
48
|
public let statusBarClearance: StatusBarClearance?
|
|
49
|
+
/// Half-folded iPhone Duo: the hinge in window coordinates, running top to bottom; nil while flat.
|
|
50
|
+
public let hinge: CGRect?
|
|
49
51
|
|
|
50
52
|
public var headerBarHeight: CGFloat { headerHeight - headerStatusBarHeight }
|
|
51
53
|
}
|
|
@@ -76,11 +78,6 @@ enum DuoMetrics {
|
|
|
76
78
|
static let floatingTabBarHeight: CGFloat = 62
|
|
77
79
|
static let floatingTabBarMargin: CGFloat = 20
|
|
78
80
|
static let floatingTabBarInsetOverlap: CGFloat = 13
|
|
79
|
-
// Width of a system alert on the inner display, in both orientations.
|
|
80
|
-
static let modalMaxWidth: CGFloat = 440
|
|
81
|
-
// Fits a PopupNotify with image, scrolled description and actions at the max width (RN
|
|
82
|
-
// Application/device.ts); taller content scrolls instead of filling the inner display.
|
|
83
|
-
static let modalMaxHeight: CGFloat = 640
|
|
84
81
|
}
|
|
85
82
|
|
|
86
83
|
enum HeaderMetrics {
|
|
@@ -116,11 +113,14 @@ extension ScreenLayout {
|
|
|
116
113
|
insets: EdgeInsets,
|
|
117
114
|
reservedRegions: [CGRect] = ReservedRegions.current,
|
|
118
115
|
isPhone: Bool = isPhoneIdiom,
|
|
119
|
-
isFoldable: Bool = FoldableDevice.isFoldable(measuredIn: keyWindow)
|
|
116
|
+
isFoldable: Bool = FoldableDevice.isFoldable(measuredIn: keyWindow),
|
|
117
|
+
division: CGRect? = FoldableDevice.halfFoldedHinge
|
|
120
118
|
) -> ScreenLayout {
|
|
121
119
|
let width = size.width
|
|
122
120
|
let height = size.height
|
|
123
121
|
let isDuoDevice = isPhone && isFoldable
|
|
122
|
+
// only a hinge splitting the window into left and right halves moves overlays
|
|
123
|
+
let hinge = division.flatMap { isPhone && $0.height > $0.width ? $0 : nil }
|
|
124
124
|
var (headerHeight, headerStatusBarHeight) = headerGeometry(topInset: insets.top, isPhone: isPhone)
|
|
125
125
|
let isDuo = isPhone && isIPhoneDuoWindow(width: width, height: height, insets: insets)
|
|
126
126
|
guard isDuo else {
|
|
@@ -128,7 +128,7 @@ extension ScreenLayout {
|
|
|
128
128
|
width: width, height: height, isIPhoneDuo: false, isDuoDevice: isDuoDevice, insets: insets,
|
|
129
129
|
insetLeft: 0, insetRight: 0, contentWidth: width,
|
|
130
130
|
headerHeight: headerHeight, headerStatusBarHeight: headerStatusBarHeight, sideBar: nil,
|
|
131
|
-
statusBarClearance: nil
|
|
131
|
+
statusBarClearance: nil, hinge: hinge
|
|
132
132
|
)
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -191,7 +191,7 @@ extension ScreenLayout {
|
|
|
191
191
|
insetLeft: insets.leading, insetRight: insets.trailing,
|
|
192
192
|
contentWidth: width - insets.leading - insets.trailing,
|
|
193
193
|
headerHeight: headerHeight, headerStatusBarHeight: headerStatusBarHeight, sideBar: sideBar,
|
|
194
|
-
statusBarClearance: statusBarClearance
|
|
194
|
+
statusBarClearance: statusBarClearance, hinge: hinge
|
|
195
195
|
)
|
|
196
196
|
}
|
|
197
197
|
|
|
@@ -265,15 +265,6 @@ extension ScreenLayout {
|
|
|
265
265
|
max(insets.top, height > width ? max(insets.leading, insets.trailing) * 2 : 0)
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
/// Room for a dialog on iPhone Duo: inside the safe area, so clear of the side toolbar strip, and
|
|
269
|
-
/// capped so it stays a dialog on the inner display.
|
|
270
|
-
var duoModalMaxWidth: CGFloat {
|
|
271
|
-
min(width - insets.leading - insets.trailing - Spacing.XL * 2, DuoMetrics.modalMaxWidth)
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
var duoModalMaxHeight: CGFloat {
|
|
275
|
-
min(height - insets.top - insets.bottom - Spacing.XL * 2, DuoMetrics.modalMaxHeight)
|
|
276
|
-
}
|
|
277
268
|
}
|
|
278
269
|
|
|
279
270
|
/// Snapshot for call sites without `\.screenLayout`; not reactive. `windowSize` is ignored,
|
|
@@ -290,6 +281,12 @@ public func isIPhoneDuoDevice(windowSize: CGSize? = nil) -> Bool {
|
|
|
290
281
|
enum FoldableDevice {
|
|
291
282
|
// a hinge never goes away, so a positive answer is kept
|
|
292
283
|
private static var isKnownFoldable = false
|
|
284
|
+
private static var isPartiallyOpen = false
|
|
285
|
+
|
|
286
|
+
/// The active division region while the hinge reports partially open; nil while flat.
|
|
287
|
+
static var halfFoldedHinge: CGRect? {
|
|
288
|
+
isPartiallyOpen ? ReservedRegions.division : nil
|
|
289
|
+
}
|
|
293
290
|
|
|
294
291
|
static func isFoldable(measuredIn view: UIView?) -> Bool {
|
|
295
292
|
if isKnownFoldable { return true }
|
|
@@ -306,8 +303,11 @@ enum FoldableDevice {
|
|
|
306
303
|
#if canImport(UIKit, _version: 9127.0.85.28)
|
|
307
304
|
guard #available(iOS 27.1, *) else { return }
|
|
308
305
|
view.addInteraction(UIHingeInteraction { _, update in
|
|
309
|
-
guard update.hinge
|
|
306
|
+
guard let hinge = update.hinge else { return }
|
|
307
|
+
let partiallyOpen = hinge.status == .partiallyOpen
|
|
308
|
+
guard !isKnownFoldable || partiallyOpen != isPartiallyOpen else { return }
|
|
310
309
|
isKnownFoldable = true
|
|
310
|
+
isPartiallyOpen = partiallyOpen
|
|
311
311
|
NotificationCenter.default.post(name: ReservedRegions.didChange, object: nil)
|
|
312
312
|
})
|
|
313
313
|
#endif
|
|
@@ -318,14 +318,17 @@ enum FoldableDevice {
|
|
|
318
318
|
|
|
319
319
|
/// System occlusion regions (iOS 27.1+) in window coordinates: the iPhone Duo camera, and the
|
|
320
320
|
/// status bar cluster as it grows for a call or a Live Activity. Empty before iOS 27.1.
|
|
321
|
+
/// `division` is the active hinge region, there only while the device is half folded.
|
|
321
322
|
enum ReservedRegions {
|
|
322
323
|
// last report of a probe, so `ScreenLayout.current` includes it
|
|
323
324
|
private(set) static var current: [CGRect] = []
|
|
325
|
+
private(set) static var division: CGRect?
|
|
324
326
|
static let didChange = Notification.Name("MoMoUIKitsReservedRegionsDidChange")
|
|
325
327
|
|
|
326
|
-
fileprivate static func publish(_ regions: [CGRect]) {
|
|
327
|
-
guard regions != current else { return }
|
|
328
|
+
fileprivate static func publish(_ regions: [CGRect], division: CGRect?) {
|
|
329
|
+
guard regions != current || division != self.division else { return }
|
|
328
330
|
current = regions
|
|
331
|
+
self.division = division
|
|
329
332
|
NotificationCenter.default.post(name: didChange, object: nil)
|
|
330
333
|
}
|
|
331
334
|
}
|
|
@@ -344,12 +347,13 @@ private final class ReservedRegionsProbe: UIView {
|
|
|
344
347
|
override func layoutSubviews() {
|
|
345
348
|
super.layoutSubviews()
|
|
346
349
|
// read even when not publishing, so UIKit keeps re-running this when they change
|
|
347
|
-
let regions =
|
|
350
|
+
let regions = activeRegions(kind: "occlusionRegionKind")
|
|
351
|
+
let division = activeRegions(kind: "divisionRegionKind").first
|
|
348
352
|
// every screen has a probe but the regions are window-wide: one sliding in on a push or
|
|
349
353
|
// a present, or off the window, would overwrite them with a partial read
|
|
350
354
|
guard spansWindow else { return }
|
|
351
355
|
// layout pass: publish on the next turn instead of mutating SwiftUI state mid-update
|
|
352
|
-
DispatchQueue.main.async { ReservedRegions.publish(regions) }
|
|
356
|
+
DispatchQueue.main.async { ReservedRegions.publish(regions, division: division) }
|
|
353
357
|
}
|
|
354
358
|
|
|
355
359
|
private var spansWindow: Bool {
|
|
@@ -364,11 +368,11 @@ private final class ReservedRegionsProbe: UIView {
|
|
|
364
368
|
}
|
|
365
369
|
|
|
366
370
|
// The API is newer than the SDKs hosts may build with, so it is reached through the runtime.
|
|
367
|
-
private func
|
|
371
|
+
private func activeRegions(kind kindName: String) -> [CGRect] {
|
|
368
372
|
let regionsOfKind = NSSelectorFromString("reservedRegionsOfKind:")
|
|
369
373
|
guard window != nil, responds(to: regionsOfKind),
|
|
370
374
|
let kindType = NSClassFromString("UIViewReservedRegionKind") as? NSObject.Type,
|
|
371
|
-
let kind = (kindType as AnyObject).perform(NSSelectorFromString(
|
|
375
|
+
let kind = (kindType as AnyObject).perform(NSSelectorFromString(kindName))?.takeUnretainedValue(),
|
|
372
376
|
let regions = perform(regionsOfKind, with: kind)?.takeUnretainedValue() as? [NSObject]
|
|
373
377
|
else { return [] }
|
|
374
378
|
return regions.compactMap { ($0.value(forKey: "frame") as? NSValue)?.cgRectValue }
|
|
@@ -79,57 +79,19 @@ struct BottomSheetView<Content: View>: View {
|
|
|
79
79
|
|
|
80
80
|
private let indicatorHeight: CGFloat = 16
|
|
81
81
|
private let headerRowHeight: CGFloat = 56
|
|
82
|
+
private let headerButtonSize: CGFloat = 24
|
|
82
83
|
|
|
83
|
-
///
|
|
84
|
-
///
|
|
85
|
-
private let maxDynamicAlpha: CGFloat = 0.
|
|
84
|
+
/// Half the scrim fades in first, the other half follows the sheet; together they reach
|
|
85
|
+
/// `scrimOpacity` (0.6 on phones, as ModalScreen; 0.2 on foldables).
|
|
86
|
+
private let maxDynamicAlpha: CGFloat = 0.5
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
private var
|
|
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
|
-
}
|
|
88
|
+
private var modal: ModalLayout { layout.modalLayout }
|
|
89
|
+
private var isFoldable: Bool { modal.isFoldable }
|
|
117
90
|
|
|
118
|
-
|
|
119
|
-
private var
|
|
120
|
-
isDuoFloating ? max(layout.insets.leading - Spacing.M, 0) : 0
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private var sideInsetTrailing: CGFloat {
|
|
124
|
-
isDuoFloating ? max(layout.insets.trailing - Spacing.M, 0) : 0
|
|
125
|
-
}
|
|
91
|
+
// UIScreen stays on the outer display on iPhone Duo, even when unfolded
|
|
92
|
+
private var screenHeight: CGFloat { isFoldable ? layout.height : UIScreen.main.bounds.height }
|
|
126
93
|
|
|
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
|
+
private var maxHeight: CGFloat { modal.sheet.maxHeight ?? screenHeight - 90 }
|
|
133
95
|
private var bottomInset: CGFloat { useBottomInset ? safeAreaBottomInset() : 0 }
|
|
134
96
|
/// While the keyboard is up, it already covers the home-indicator area, so it
|
|
135
97
|
/// replaces (rather than adds to) the usual bottom-inset filler.
|
|
@@ -151,15 +113,15 @@ struct BottomSheetView<Content: View>: View {
|
|
|
151
113
|
return progress * maxDynamicAlpha
|
|
152
114
|
}
|
|
153
115
|
|
|
154
|
-
/// Mirrors Compose's `alpha = backgroundAlpha + dynamicAlpha`: additive, so the
|
|
155
|
-
/// scrim peaks at
|
|
116
|
+
/// Mirrors Compose's `alpha = (backgroundAlpha + dynamicAlpha) * scrimOpacity`: additive, so the
|
|
117
|
+
/// scrim peaks at `scrimOpacity` at rest and only fades to half of it while dragging
|
|
156
118
|
/// (backgroundAlpha holds steady until an explicit close()).
|
|
157
|
-
private var totalScrimAlpha: CGFloat { backgroundAlpha + dynamicAlpha }
|
|
119
|
+
private var totalScrimAlpha: CGFloat { (backgroundAlpha + dynamicAlpha) * modal.scrimOpacity }
|
|
158
120
|
|
|
159
121
|
var body: some View {
|
|
160
122
|
ZStack(alignment: .bottom) {
|
|
161
|
-
// Dimmed scrim — additive backgroundAlpha + dynamicAlpha (see above).
|
|
162
|
-
|
|
123
|
+
// Dimmed scrim — additive backgroundAlpha + dynamicAlpha (see above); full screen on foldables too.
|
|
124
|
+
Colors.black20.opacity(totalScrimAlpha)
|
|
163
125
|
.contentShape(Rectangle())
|
|
164
126
|
.onTapGesture {
|
|
165
127
|
if barrierDismissible { close() }
|
|
@@ -199,12 +161,9 @@ struct BottomSheetView<Content: View>: View {
|
|
|
199
161
|
.fill(Colors.black06)
|
|
200
162
|
.frame(width: 40, height: 4)
|
|
201
163
|
Spacer().frame(height: 4)
|
|
202
|
-
// the handle centers on the whole sheet, only the header row keeps clear of the strip
|
|
203
164
|
headerView
|
|
204
165
|
.frame(height: headerRowHeight)
|
|
205
166
|
.padding(.horizontal, Spacing.M)
|
|
206
|
-
.padding(.leading, sideInsetLeading)
|
|
207
|
-
.padding(.trailing, sideInsetTrailing)
|
|
208
167
|
}
|
|
209
168
|
.frame(maxWidth: .infinity)
|
|
210
169
|
.frame(height: indicatorHeight + headerRowHeight)
|
|
@@ -214,19 +173,18 @@ struct BottomSheetView<Content: View>: View {
|
|
|
214
173
|
Rectangle()
|
|
215
174
|
.fill(theme.colors.border.default)
|
|
216
175
|
.frame(height: 1)
|
|
217
|
-
.padding(.leading, sideInsetLeading)
|
|
218
|
-
.padding(.trailing, sideInsetTrailing)
|
|
219
176
|
|
|
220
177
|
content()
|
|
221
|
-
.padding(.leading, sideInsetLeading)
|
|
222
|
-
.padding(.trailing, sideInsetTrailing)
|
|
223
178
|
// a tall sheet keeps its header (and footer) and gives the content what is left
|
|
224
179
|
.layoutPriority(-1)
|
|
225
180
|
|
|
226
181
|
if let footer {
|
|
227
|
-
|
|
182
|
+
// a sheet held at its min height keeps the footer at the bottom
|
|
183
|
+
Spacer(minLength: 0).layoutPriority(-2)
|
|
184
|
+
BottomSheetFooter(content: footer)
|
|
228
185
|
}
|
|
229
186
|
}
|
|
187
|
+
.frame(minHeight: max(modal.sheet.minHeight - effectiveBottomInset, 0), alignment: .top)
|
|
230
188
|
// The filler stays outside the cap, which shrinks by it instead: the sheet still ends at
|
|
231
189
|
// `maxHeight`, and the iOS 15 fallback never measures the keyboard as content.
|
|
232
190
|
.modifier(CapHeight(maxHeight: maxHeight - effectiveBottomInset))
|
|
@@ -234,7 +192,8 @@ struct BottomSheetView<Content: View>: View {
|
|
|
234
192
|
(footer != nil ? theme.colors.background.surface : backgroundColor)
|
|
235
193
|
.frame(height: effectiveBottomInset)
|
|
236
194
|
}
|
|
237
|
-
.frame(
|
|
195
|
+
.frame(width: modal.sheet.width)
|
|
196
|
+
.frame(maxWidth: modal.sheet.width == nil ? .infinity : nil)
|
|
238
197
|
.clipped()
|
|
239
198
|
.background(
|
|
240
199
|
GeometryReader { geo in
|
|
@@ -242,54 +201,43 @@ struct BottomSheetView<Content: View>: View {
|
|
|
242
201
|
}
|
|
243
202
|
)
|
|
244
203
|
.background(backgroundColor)
|
|
245
|
-
.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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)
|
|
204
|
+
.clipShape(RoundedCorner(radius: modal.sheet.radius, corners: [.topLeft, .topRight]))
|
|
205
|
+
// centered in the placement: off the iPhone Duo control column, the right half when half folded
|
|
206
|
+
.padding(.leading, isFoldable ? modal.placement.minX : 0)
|
|
207
|
+
.padding(.trailing, isFoldable ? layout.width - modal.placement.maxX : 0)
|
|
259
208
|
}
|
|
260
209
|
|
|
261
210
|
@ViewBuilder
|
|
262
211
|
private var headerView: some View {
|
|
263
212
|
switch header.style {
|
|
264
213
|
case .title(let text, let back):
|
|
265
|
-
// the side column holds back and close, the row keeps only the title
|
|
266
|
-
let showsButtons = sideColumn == nil
|
|
267
214
|
HStack(spacing: 0) {
|
|
268
|
-
if
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
215
|
+
if let back {
|
|
216
|
+
headerButton(icon: back.icon, accessibilityId: "btn_bottom_sheet_back") { goBack(back) }
|
|
217
|
+
} else {
|
|
218
|
+
let size = isFoldable ? ModalMetrics.iconButtonSize : headerButtonSize
|
|
219
|
+
Color.clear.frame(width: size, height: size)
|
|
274
220
|
}
|
|
275
221
|
MomoText(text, typography: .headerDefaultBold, color: Colors.black17)
|
|
276
222
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
277
|
-
|
|
278
|
-
if showsButtons {
|
|
279
|
-
headerButton(icon: "navigation_close", accessibilityId: "btn_bottom_sheet_close") { close() }
|
|
280
|
-
}
|
|
223
|
+
headerButton(icon: "navigation_close", accessibilityId: "btn_bottom_sheet_close") { close() }
|
|
281
224
|
}
|
|
282
225
|
case .custom(let builder):
|
|
283
226
|
builder()
|
|
284
227
|
}
|
|
285
228
|
}
|
|
286
229
|
|
|
230
|
+
@ViewBuilder
|
|
287
231
|
private func headerButton(icon: String, accessibilityId: String, action: @escaping () -> Void) -> some View {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
232
|
+
if isFoldable {
|
|
233
|
+
ModalIconButton(icon: icon, accessibilityId: accessibilityId, action: action)
|
|
234
|
+
} else {
|
|
235
|
+
Icon(source: icon, size: headerButtonSize, color: Colors.black17)
|
|
236
|
+
.frame(width: headerButtonSize, height: headerButtonSize)
|
|
237
|
+
.contentShape(Rectangle())
|
|
238
|
+
.onTapGesture(perform: action)
|
|
239
|
+
.accessibilityIdentifier(accessibilityId)
|
|
240
|
+
}
|
|
293
241
|
}
|
|
294
242
|
|
|
295
243
|
/// RN `leftOptions.onPressIconLeft`: the sheet closes first, then the back runs.
|
|
@@ -369,63 +317,6 @@ struct BottomSheetView<Content: View>: View {
|
|
|
369
317
|
}
|
|
370
318
|
}
|
|
371
319
|
|
|
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
|
-
|
|
429
320
|
/// Compose's `heightIn(max:)`. `.frame(maxHeight:)` grows to the cap whenever the proposal is
|
|
430
321
|
/// larger, leaving a gap above the header; this sizes the sheet to its content and only caps it
|
|
431
322
|
/// when taller.
|
|
@@ -498,16 +389,12 @@ private struct CapHeightLayout: Layout {
|
|
|
498
389
|
/// Mirrors Compose's `BottomSheetFooter`: a surface band with a soft shadow cast on the content.
|
|
499
390
|
private struct BottomSheetFooter: View {
|
|
500
391
|
let content: () -> AnyView
|
|
501
|
-
var leadingInset: CGFloat = 0
|
|
502
|
-
var trailingInset: CGFloat = 0
|
|
503
392
|
|
|
504
393
|
@Environment(\.appTheme) private var theme
|
|
505
394
|
|
|
506
395
|
var body: some View {
|
|
507
396
|
content()
|
|
508
397
|
.frame(maxWidth: .infinity)
|
|
509
|
-
.padding(.leading, leadingInset)
|
|
510
|
-
.padding(.trailing, trailingInset)
|
|
511
398
|
.padding(.vertical, Spacing.S)
|
|
512
399
|
.background(theme.colors.background.surface)
|
|
513
400
|
.overlay(alignment: .top) {
|
|
@@ -359,7 +359,7 @@ struct Toolkit: View {
|
|
|
359
359
|
}
|
|
360
360
|
toolButton(icon: headerRight.closeIcon, accessibilityId: "btn_navigation_close", action: onPressClose)
|
|
361
361
|
}
|
|
362
|
-
.frame(width:
|
|
362
|
+
.frame(width: 65, height: 28)
|
|
363
363
|
.background(headerColor.backgroundButton)
|
|
364
364
|
.cornerRadius(14)
|
|
365
365
|
.overlay(RoundedRectangle(cornerRadius: 14).stroke(headerColor.borderColor, lineWidth: 0.2))
|
|
@@ -24,9 +24,11 @@ struct ModalScreen<Content: View>: View {
|
|
|
24
24
|
@State private var didAppear = false
|
|
25
25
|
|
|
26
26
|
var body: some View {
|
|
27
|
+
let modal = layout.modalLayout
|
|
28
|
+
let placement = modal.placement
|
|
27
29
|
ZStack {
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
+
// full screen on foldables too, over the iPhone Duo control column
|
|
31
|
+
Colors.black20.opacity(modal.scrimOpacity * scrimOpacity)
|
|
30
32
|
.ignoresSafeArea()
|
|
31
33
|
.contentShape(Rectangle())
|
|
32
34
|
.onTapGesture {
|
|
@@ -34,15 +36,24 @@ struct ModalScreen<Content: View>: View {
|
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
content()
|
|
37
|
-
//
|
|
39
|
+
// foldables: capped by the spec; nil leaves the size alone
|
|
38
40
|
.frame(
|
|
39
|
-
maxWidth:
|
|
40
|
-
maxHeight:
|
|
41
|
+
maxWidth: modal.isFoldable ? modal.popup.maxWidth : nil,
|
|
42
|
+
maxHeight: modal.isFoldable ? (modal.popup.maxHeight ?? placement.height) : nil
|
|
41
43
|
)
|
|
42
44
|
.scaleEffect(contentScale)
|
|
43
45
|
.opacity(contentOpacity)
|
|
44
|
-
//
|
|
45
|
-
.padding(
|
|
46
|
+
// center in the placement: the safe area, or the right half of a half-folded iPhone Duo
|
|
47
|
+
.padding(
|
|
48
|
+
modal.isFoldable
|
|
49
|
+
? EdgeInsets(
|
|
50
|
+
top: placement.minY,
|
|
51
|
+
leading: placement.minX,
|
|
52
|
+
bottom: layout.height - placement.maxY,
|
|
53
|
+
trailing: layout.width - placement.maxX
|
|
54
|
+
)
|
|
55
|
+
: EdgeInsets()
|
|
56
|
+
)
|
|
46
57
|
}
|
|
47
58
|
// Full screen like RN's Modal, so asymmetric landscape insets don't shift the content sideways.
|
|
48
59
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
@@ -2,25 +2,26 @@ import SDWebImageSwiftUI
|
|
|
2
2
|
import SwiftUI
|
|
3
3
|
|
|
4
4
|
extension ScreenLayout {
|
|
5
|
-
/// Card width
|
|
5
|
+
/// Card width on foldables (`modalLayout`, Compose `popupMaxWidth`); unbounded on phones,
|
|
6
6
|
/// where the popup's own padding sets the width.
|
|
7
7
|
var popupMaxWidth: CGFloat {
|
|
8
|
-
|
|
8
|
+
let modal = modalLayout
|
|
9
|
+
return modal.isFoldable ? modal.popup.maxWidth : .infinity
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
/// The
|
|
12
|
+
/// The placement already keeps foldable popups off the edges, so their own side padding goes.
|
|
12
13
|
func popupHorizontalPadding(_ padding: CGFloat) -> CGFloat {
|
|
13
|
-
|
|
14
|
+
modalLayout.isFoldable ? 0 : padding
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
/// Tallest a popup gets on
|
|
17
|
+
/// Tallest a popup gets on foldables; nil on phones.
|
|
17
18
|
var popupMaxHeight: CGFloat? {
|
|
18
|
-
|
|
19
|
+
modalLayout.popup.maxHeight
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
/// Rounder on iPhone Duo, closer to its system alerts.
|
|
22
22
|
func popupRadius(_ regular: CGFloat = Radius.L) -> CGFloat {
|
|
23
|
-
|
|
23
|
+
let modal = modalLayout
|
|
24
|
+
return modal.isFoldable ? modal.popup.radius : regular
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -55,7 +55,8 @@ public struct PopupNotify: View {
|
|
|
55
55
|
public let props: PopupNotifyProps
|
|
56
56
|
|
|
57
57
|
@State private var descriptionHeight: CGFloat = 0
|
|
58
|
-
@State private var
|
|
58
|
+
@State private var descriptionFrameHeight: CGFloat = 0
|
|
59
|
+
@State private var cardHeight: CGFloat = 0
|
|
59
60
|
@State private var oneLineHeight: CGFloat = 0
|
|
60
61
|
@State private var twoLinesHeight: CGFloat = 0
|
|
61
62
|
|
|
@@ -63,10 +64,17 @@ public struct PopupNotify: View {
|
|
|
63
64
|
localize.translate("errorCode")
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
// ~8.5 lines as laid out (Compose measures the real lines); nominal line height until measured
|
|
67
|
+
// ~8.5 lines as laid out (Compose measures the real lines); nominal line height until measured.
|
|
68
|
+
// With a max height (foldables) only the description gives way: image, title and actions stay.
|
|
67
69
|
private var maxDescriptionHeight: CGFloat {
|
|
68
|
-
popupLinesHeight(8.5, oneLine: oneLineHeight, twoLines: twoLinesHeight)
|
|
70
|
+
let lines = popupLinesHeight(8.5, oneLine: oneLineHeight, twoLines: twoLinesHeight)
|
|
69
71
|
?? fontScale(TypographyStyle.bodyDefaultRegular.lineHeight) * 8.5
|
|
72
|
+
guard let maxHeight = layout.modalLayout.popup.maxHeight else { return lines }
|
|
73
|
+
return max(min(lines, maxHeight - (cardHeight - descriptionFrameHeight)), 0)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private var isCloseInside: Bool {
|
|
77
|
+
layout.modalLayout.isFoldable && props.isShowCloseIcon
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
private var shouldUseColumnButtons: Bool {
|
|
@@ -87,33 +95,35 @@ public struct PopupNotify: View {
|
|
|
87
95
|
}
|
|
88
96
|
|
|
89
97
|
public var body: some View {
|
|
98
|
+
let modal = layout.modalLayout
|
|
90
99
|
ZStack(alignment: .topTrailing) {
|
|
91
100
|
VStack(spacing: 0) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
VStack(spacing: 0) {
|
|
95
|
-
if !props.image.isEmpty {
|
|
96
|
-
PopupHeaderImage(url: props.image)
|
|
97
|
-
}
|
|
98
|
-
textContent
|
|
99
|
-
}
|
|
101
|
+
if !props.image.isEmpty {
|
|
102
|
+
PopupHeaderImage(url: props.image)
|
|
100
103
|
}
|
|
104
|
+
textContent
|
|
101
105
|
|
|
102
106
|
actionButtons
|
|
103
107
|
.padding(.horizontal, Spacing.XL)
|
|
104
108
|
.padding(.bottom, Spacing.XL)
|
|
105
|
-
.popupReadHeight($actionsHeight)
|
|
106
109
|
}
|
|
107
110
|
.background(theme.colors.background.surface)
|
|
108
|
-
.clipShape(RoundedRectangle(cornerRadius:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
.clipShape(RoundedRectangle(cornerRadius: modal.popup.radius))
|
|
112
|
+
.popupReadHeight($cardHeight)
|
|
113
|
+
|
|
114
|
+
if isCloseInside {
|
|
115
|
+
ModalIconButton(icon: "navigation_close", accessibilityId: "ic_popup_close", action: props.onIconClose)
|
|
116
|
+
.padding(.top, Spacing.M)
|
|
117
|
+
.padding(.trailing, Spacing.M)
|
|
118
|
+
} else if props.isShowCloseIcon {
|
|
119
|
+
// phones: straddles the card's top right corner
|
|
111
120
|
PopupCloseButton(action: props.onIconClose)
|
|
112
121
|
.offset(x: 11, y: -11)
|
|
113
122
|
}
|
|
114
123
|
}
|
|
115
|
-
.frame(maxWidth:
|
|
116
|
-
|
|
124
|
+
.frame(minWidth: modal.popup.minWidth, maxWidth: modal.popup.maxWidth)
|
|
125
|
+
// phones keep room around the card for the close badge on its corner
|
|
126
|
+
.padding(.horizontal, modal.isFoldable ? 0 : Spacing.M)
|
|
117
127
|
.accessibilityElement(children: .contain)
|
|
118
128
|
.accessibilityIdentifier("popup_notify")
|
|
119
129
|
}
|
|
@@ -126,6 +136,7 @@ public struct PopupNotify: View {
|
|
|
126
136
|
maxLines: 2,
|
|
127
137
|
accessibilityId: "title_popup_permission"
|
|
128
138
|
)
|
|
139
|
+
.padding(.trailing, isCloseInside && props.image.isEmpty ? ModalMetrics.iconButtonSize + Spacing.M - Spacing.XL : 0)
|
|
129
140
|
.padding(.bottom, Spacing.S)
|
|
130
141
|
|
|
131
142
|
descriptionContent
|
|
@@ -145,16 +156,18 @@ public struct PopupNotify: View {
|
|
|
145
156
|
.measureLineHeights(typography: .bodyDefaultRegular, oneLine: $oneLineHeight, twoLines: $twoLinesHeight)
|
|
146
157
|
}
|
|
147
158
|
|
|
148
|
-
@ViewBuilder
|
|
149
159
|
private var descriptionContent: some View {
|
|
150
|
-
|
|
151
|
-
|
|
160
|
+
Group {
|
|
161
|
+
if descriptionHeight > maxDescriptionHeight {
|
|
162
|
+
ScrollView(.vertical, showsIndicators: false) {
|
|
163
|
+
descriptionText
|
|
164
|
+
}
|
|
165
|
+
.frame(height: maxDescriptionHeight)
|
|
166
|
+
} else {
|
|
152
167
|
descriptionText
|
|
153
168
|
}
|
|
154
|
-
.frame(height: maxDescriptionHeight)
|
|
155
|
-
} else {
|
|
156
|
-
descriptionText
|
|
157
169
|
}
|
|
170
|
+
.popupReadHeight($descriptionFrameHeight)
|
|
158
171
|
}
|
|
159
172
|
|
|
160
173
|
private var descriptionText: some View {
|
|
@@ -202,13 +202,6 @@ private struct NavigationDemoContent: View {
|
|
|
202
202
|
)
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
row("Header Types") {
|
|
206
|
-
navigator.push(
|
|
207
|
-
{ HeaderTypesScreen() },
|
|
208
|
-
options: NavigationOptions(title: "Header Types")
|
|
209
|
-
)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
205
|
row("Bottom Tabs") {
|
|
213
206
|
navigator.push(
|
|
214
207
|
{ BottomTabDemoContent() },
|
|
@@ -260,89 +253,6 @@ private struct UpdateOptionsScreen: View {
|
|
|
260
253
|
}
|
|
261
254
|
}
|
|
262
255
|
|
|
263
|
-
/// Header options switched at runtime (Compose `HeaderTypeUsage`).
|
|
264
|
-
@available(iOS 16.0, *)
|
|
265
|
-
private struct HeaderTypesScreen: View {
|
|
266
|
-
private enum Kind: String, CaseIterable {
|
|
267
|
-
case none = "None", `default` = "Default", extended = "Extended", transparent = "Transparent"
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
@EnvironmentObject private var navigation: Navigation
|
|
271
|
-
@State private var kind: AnyHashable = Kind.default
|
|
272
|
-
@State private var titlePosition: AnyHashable = TitlePosition.left
|
|
273
|
-
@State private var showBack = true
|
|
274
|
-
@State private var showHeaderRight = true
|
|
275
|
-
@State private var isAnimated = false
|
|
276
|
-
@State private var isHeader = false
|
|
277
|
-
@State private var isFullScreenContent = false
|
|
278
|
-
@State private var searchText = ""
|
|
279
|
-
|
|
280
|
-
var body: some View {
|
|
281
|
-
VStack(alignment: .leading, spacing: Spacing.M) {
|
|
282
|
-
ForEach(Kind.allCases, id: \.self) { item in
|
|
283
|
-
Radio(value: item, groupValue: $kind, onChange: applyHeader, label: item.rawValue)
|
|
284
|
-
}
|
|
285
|
-
Divider()
|
|
286
|
-
MomoText("Title Position")
|
|
287
|
-
ForEach([TitlePosition.left, TitlePosition.center], id: \.self) { position in
|
|
288
|
-
Radio(value: position, groupValue: $titlePosition, onChange: {
|
|
289
|
-
navigation.setOptions { $0.titlePosition = position }
|
|
290
|
-
}, label: position == .left ? "LEFT" : "CENTER")
|
|
291
|
-
}
|
|
292
|
-
Divider()
|
|
293
|
-
Checkbox($showBack, onChange: { checked in
|
|
294
|
-
navigation.setOptions { $0.hiddenBack = !checked }
|
|
295
|
-
}, title: "Show Back")
|
|
296
|
-
Checkbox($showHeaderRight, onChange: { checked in
|
|
297
|
-
navigation.setOptions {
|
|
298
|
-
$0.headerRightData = checked ? HeaderRightData() : nil
|
|
299
|
-
$0.headerRight = nil
|
|
300
|
-
}
|
|
301
|
-
}, title: "Show Header Right")
|
|
302
|
-
Divider()
|
|
303
|
-
Checkbox($isAnimated, onChange: { checked in
|
|
304
|
-
if checked { isHeader = false }
|
|
305
|
-
applyHeader()
|
|
306
|
-
}, title: "Search Animated")
|
|
307
|
-
Checkbox($isHeader, onChange: { checked in
|
|
308
|
-
if checked { isAnimated = false }
|
|
309
|
-
applyHeader()
|
|
310
|
-
}, title: "Search Header")
|
|
311
|
-
if kind == AnyHashable(Kind.transparent) {
|
|
312
|
-
Checkbox($isFullScreenContent, onChange: { _ in applyHeader() }, title: "Is Full Screen Content")
|
|
313
|
-
}
|
|
314
|
-
Color.clear.frame(height: 1600)
|
|
315
|
-
}
|
|
316
|
-
.padding(Spacing.M)
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
private func applyHeader() {
|
|
320
|
-
let selected = kind.base as? Kind ?? .default
|
|
321
|
-
var search: InputSearchProps?
|
|
322
|
-
if isAnimated {
|
|
323
|
-
search = InputSearchProps(text: $searchText, placeholder: "Search input")
|
|
324
|
-
} else if isHeader {
|
|
325
|
-
search = InputSearchProps(text: $searchText, buttonText: "Huỷ", showButtonText: true, placeholder: "Search input")
|
|
326
|
-
}
|
|
327
|
-
navigation.setOptions {
|
|
328
|
-
switch selected {
|
|
329
|
-
case .none:
|
|
330
|
-
$0.headerType = .none
|
|
331
|
-
case .default, .extended:
|
|
332
|
-
$0.headerType = selected == .default ? .default : .extended
|
|
333
|
-
$0.useAnimated = isAnimated
|
|
334
|
-
$0.inputSearchProps = search
|
|
335
|
-
case .transparent:
|
|
336
|
-
$0.headerType = .default
|
|
337
|
-
$0.useAnimated = false
|
|
338
|
-
$0.inputSearchProps = nil
|
|
339
|
-
}
|
|
340
|
-
$0.headerTransparent = selected == .transparent
|
|
341
|
-
$0.fullScreenContent = selected == .transparent && isFullScreenContent
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
256
|
@available(iOS 16.0, *)
|
|
347
257
|
private struct DemoLeafScreen: View {
|
|
348
258
|
@EnvironmentObject private var navigator: Navigator
|