@momo-kits/native-kits 0.168.1-sizescale.1-debug → 0.169.1-debug
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +4 -3
- package/PUBLISH_GUIDE.md +29 -658
- package/compose/build.gradle.kts +2 -2
- package/compose/compose.podspec +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +4 -5
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +2 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +21 -15
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +76 -83
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +3 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +11 -14
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +3 -4
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +8 -13
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +57 -163
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +17 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +5 -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 -23
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +321 -149
- 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 +87 -261
- 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/ReduceMotion.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +2 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +1 -2
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +3 -2
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +9 -3
- package/gradle.properties +1 -3
- package/ios/Input/Input.swift +3 -1
- package/ios/Input/InputTextArea.swift +3 -1
- package/ios/Layout/ModalLayout.swift +152 -0
- package/ios/Layout/ScreenLayout.swift +28 -24
- package/ios/Navigation/BottomSheet.swift +29 -156
- package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
- package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
- package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
- package/ios/Navigation/BottomTab/DuoTabBar.swift +62 -195
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/ModalScreen.swift +18 -7
- package/ios/Navigation/StackScreen.swift +3 -1
- package/ios/Popup/PopupDisplay.swift +4 -2
- package/ios/Popup/PopupInput.swift +4 -2
- package/ios/Popup/PopupLayout.swift +10 -9
- package/ios/Popup/PopupNotify.swift +32 -25
- package/ios/Typography/Text.swift +2 -2
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- 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 +103 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
- package/local.properties +8 -0
- package/package.json +1 -1
- package/publish.sh +170 -513
- package/compose/build.gradle.kts.backup +0 -198
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitSizeScale.kt +0 -45
|
@@ -80,56 +80,17 @@ 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.
|
|
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
|
|
86
86
|
|
|
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
|
-
}
|
|
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
|
-
}
|
|
87
|
+
private var modal: ModalLayout { layout.modalLayout }
|
|
88
|
+
private var isFoldable: Bool { modal.isFoldable }
|
|
122
89
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
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 }
|
|
126
92
|
|
|
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
|
-
}
|
|
93
|
+
private var maxHeight: CGFloat { modal.sheet.maxHeight ?? screenHeight - 90 }
|
|
133
94
|
private var bottomInset: CGFloat { useBottomInset ? safeAreaBottomInset() : 0 }
|
|
134
95
|
/// While the keyboard is up, it already covers the home-indicator area, so it
|
|
135
96
|
/// replaces (rather than adds to) the usual bottom-inset filler.
|
|
@@ -151,15 +112,15 @@ struct BottomSheetView<Content: View>: View {
|
|
|
151
112
|
return progress * maxDynamicAlpha
|
|
152
113
|
}
|
|
153
114
|
|
|
154
|
-
/// Mirrors Compose's `alpha = backgroundAlpha + dynamicAlpha`: additive, so the
|
|
155
|
-
/// scrim peaks at
|
|
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
|
|
156
117
|
/// (backgroundAlpha holds steady until an explicit close()).
|
|
157
|
-
private var totalScrimAlpha: CGFloat { backgroundAlpha + dynamicAlpha }
|
|
118
|
+
private var totalScrimAlpha: CGFloat { (backgroundAlpha + dynamicAlpha) * modal.scrimOpacity }
|
|
158
119
|
|
|
159
120
|
var body: some View {
|
|
160
121
|
ZStack(alignment: .bottom) {
|
|
161
|
-
// Dimmed scrim — additive backgroundAlpha + dynamicAlpha (see above).
|
|
162
|
-
|
|
122
|
+
// Dimmed scrim — additive backgroundAlpha + dynamicAlpha (see above); full screen on foldables too.
|
|
123
|
+
Colors.black20.opacity(totalScrimAlpha)
|
|
163
124
|
.contentShape(Rectangle())
|
|
164
125
|
.onTapGesture {
|
|
165
126
|
if barrierDismissible { close() }
|
|
@@ -203,8 +164,6 @@ struct BottomSheetView<Content: View>: View {
|
|
|
203
164
|
.frame(height: headerRowHeight)
|
|
204
165
|
.padding(.horizontal, Spacing.M)
|
|
205
166
|
}
|
|
206
|
-
.padding(.leading, sideInsetLeading)
|
|
207
|
-
.padding(.trailing, sideInsetTrailing)
|
|
208
167
|
.frame(maxWidth: .infinity)
|
|
209
168
|
.frame(height: indicatorHeight + headerRowHeight)
|
|
210
169
|
.contentShape(Rectangle())
|
|
@@ -213,19 +172,18 @@ struct BottomSheetView<Content: View>: View {
|
|
|
213
172
|
Rectangle()
|
|
214
173
|
.fill(theme.colors.border.default)
|
|
215
174
|
.frame(height: 1)
|
|
216
|
-
.padding(.leading, sideInsetLeading)
|
|
217
|
-
.padding(.trailing, sideInsetTrailing)
|
|
218
175
|
|
|
219
176
|
content()
|
|
220
|
-
.padding(.leading, sideInsetLeading)
|
|
221
|
-
.padding(.trailing, sideInsetTrailing)
|
|
222
177
|
// a tall sheet keeps its header (and footer) and gives the content what is left
|
|
223
178
|
.layoutPriority(-1)
|
|
224
179
|
|
|
225
180
|
if let footer {
|
|
226
|
-
|
|
181
|
+
// a sheet held at its min height keeps the footer at the bottom
|
|
182
|
+
Spacer(minLength: 0).layoutPriority(-2)
|
|
183
|
+
BottomSheetFooter(content: footer)
|
|
227
184
|
}
|
|
228
185
|
}
|
|
186
|
+
.frame(minHeight: max(modal.sheet.minHeight - effectiveBottomInset, 0), alignment: .top)
|
|
229
187
|
// The filler stays outside the cap, which shrinks by it instead: the sheet still ends at
|
|
230
188
|
// `maxHeight`, and the iOS 15 fallback never measures the keyboard as content.
|
|
231
189
|
.modifier(CapHeight(maxHeight: maxHeight - effectiveBottomInset))
|
|
@@ -233,7 +191,8 @@ struct BottomSheetView<Content: View>: View {
|
|
|
233
191
|
(footer != nil ? theme.colors.background.surface : backgroundColor)
|
|
234
192
|
.frame(height: effectiveBottomInset)
|
|
235
193
|
}
|
|
236
|
-
.frame(
|
|
194
|
+
.frame(width: modal.sheet.width)
|
|
195
|
+
.frame(maxWidth: modal.sheet.width == nil ? .infinity : nil)
|
|
237
196
|
.clipped()
|
|
238
197
|
.background(
|
|
239
198
|
GeometryReader { geo in
|
|
@@ -241,56 +200,31 @@ struct BottomSheetView<Content: View>: View {
|
|
|
241
200
|
}
|
|
242
201
|
)
|
|
243
202
|
.background(backgroundColor)
|
|
244
|
-
.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
windowHeight: layout.height,
|
|
249
|
-
topOffset: indicatorHeight + (headerRowHeight - DuoMetrics.controlSize) / 2,
|
|
250
|
-
back: titleBack,
|
|
251
|
-
onBack: goBack,
|
|
252
|
-
onClose: { close() }
|
|
253
|
-
)
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
.clipShape(RoundedCorner(radius: isDuo ? Radius.XL : Radius.M, corners: [.topLeft, .topRight]))
|
|
257
|
-
.padding(.horizontal, isDuoFloating ? Spacing.M : 0)
|
|
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)
|
|
258
207
|
}
|
|
259
208
|
|
|
260
209
|
@ViewBuilder
|
|
261
210
|
private var headerView: some View {
|
|
262
211
|
switch header.style {
|
|
263
212
|
case .title(let text, let back):
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
headerButton(icon: back.icon, accessibilityId: "btn_bottom_sheet_back") { goBack(back) }
|
|
270
|
-
} else {
|
|
271
|
-
Color.clear.frame(width: 24, height: 24)
|
|
272
|
-
}
|
|
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)
|
|
273
218
|
}
|
|
274
219
|
MomoText(text, typography: .headerDefaultBold, color: Colors.black17)
|
|
275
220
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
276
|
-
|
|
277
|
-
if showsButtons {
|
|
278
|
-
headerButton(icon: "navigation_close", accessibilityId: "btn_bottom_sheet_close") { close() }
|
|
279
|
-
}
|
|
221
|
+
ModalIconButton(icon: "navigation_close", accessibilityId: "btn_bottom_sheet_close") { close() }
|
|
280
222
|
}
|
|
281
223
|
case .custom(let builder):
|
|
282
224
|
builder()
|
|
283
225
|
}
|
|
284
226
|
}
|
|
285
227
|
|
|
286
|
-
private func headerButton(icon: String, accessibilityId: String, action: @escaping () -> Void) -> some View {
|
|
287
|
-
Icon(source: icon, size: 24, color: Colors.black17)
|
|
288
|
-
.frame(width: 24, height: 24)
|
|
289
|
-
.contentShape(Rectangle())
|
|
290
|
-
.onTapGesture(perform: action)
|
|
291
|
-
.accessibilityIdentifier(accessibilityId)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
228
|
/// RN `leftOptions.onPressIconLeft`: the sheet closes first, then the back runs.
|
|
295
229
|
private func goBack(_ back: BottomSheetHeader.Back) {
|
|
296
230
|
close(then: back.action)
|
|
@@ -368,63 +302,6 @@ struct BottomSheetView<Content: View>: View {
|
|
|
368
302
|
}
|
|
369
303
|
}
|
|
370
304
|
|
|
371
|
-
/// iPhone Duo outer display: back and close sit on the part of the sheet under the side safe area,
|
|
372
|
-
/// 12pt from the strip's inner edge like the screen side bar. They follow the header row while the
|
|
373
|
-
/// sheet is short and stay below the status bar cluster while it is tall.
|
|
374
|
-
private struct BottomSheetSideColumn: View {
|
|
375
|
-
let sideBar: SideBarLayout
|
|
376
|
-
let windowHeight: CGFloat
|
|
377
|
-
/// Lines the controls up with the header row.
|
|
378
|
-
let topOffset: CGFloat
|
|
379
|
-
let back: BottomSheetHeader.Back?
|
|
380
|
-
let onBack: (BottomSheetHeader.Back) -> Void
|
|
381
|
-
let onClose: () -> Void
|
|
382
|
-
|
|
383
|
-
@Environment(\.appTheme) private var theme
|
|
384
|
-
|
|
385
|
-
private var isRight: Bool { sideBar.edge == .right }
|
|
386
|
-
|
|
387
|
-
private var columnHeight: CGFloat {
|
|
388
|
-
let count: CGFloat = back != nil ? 2 : 1
|
|
389
|
-
return count * DuoMetrics.controlSize + (count - 1) * Spacing.M
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
private var headerColor: HeaderColor {
|
|
393
|
-
getHeaderColor(isAnimated: false, isSurface: true, opacity: 1, tintColor: nil, defaultColor: theme.colors.text.default)
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
var body: some View {
|
|
397
|
-
GeometryReader { proxy in
|
|
398
|
-
let sheetHeight = proxy.size.height
|
|
399
|
-
// the sheet rests on the window bottom; its slide is an offset outside this layout
|
|
400
|
-
let sheetTop = windowHeight - sheetHeight
|
|
401
|
-
// clear of a camera at the bottom end of the strip when it can
|
|
402
|
-
let lowest = sheetHeight - sideBar.bottom - columnHeight
|
|
403
|
-
let top = max(min(max(sideBar.top - sheetTop, topOffset), lowest), 0)
|
|
404
|
-
VStack(alignment: isRight ? .leading : .trailing, spacing: Spacing.M) {
|
|
405
|
-
if let back {
|
|
406
|
-
SideBarButton(
|
|
407
|
-
icon: back.icon,
|
|
408
|
-
headerColor: headerColor,
|
|
409
|
-
accessibilityId: "btn_bottom_sheet_back",
|
|
410
|
-
action: { onBack(back) }
|
|
411
|
-
)
|
|
412
|
-
}
|
|
413
|
-
SideBarButton(
|
|
414
|
-
icon: "navigation_close",
|
|
415
|
-
headerColor: headerColor,
|
|
416
|
-
accessibilityId: "btn_bottom_sheet_close",
|
|
417
|
-
action: onClose
|
|
418
|
-
)
|
|
419
|
-
}
|
|
420
|
-
.padding(isRight ? .leading : .trailing, Spacing.M)
|
|
421
|
-
.frame(width: sideBar.width - Spacing.M, alignment: isRight ? .leading : .trailing)
|
|
422
|
-
.padding(.top, top)
|
|
423
|
-
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: isRight ? .topTrailing : .topLeading)
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
305
|
/// Compose's `heightIn(max:)`. `.frame(maxHeight:)` grows to the cap whenever the proposal is
|
|
429
306
|
/// larger, leaving a gap above the header; this sizes the sheet to its content and only caps it
|
|
430
307
|
/// when taller.
|
|
@@ -497,16 +374,12 @@ private struct CapHeightLayout: Layout {
|
|
|
497
374
|
/// Mirrors Compose's `BottomSheetFooter`: a surface band with a soft shadow cast on the content.
|
|
498
375
|
private struct BottomSheetFooter: View {
|
|
499
376
|
let content: () -> AnyView
|
|
500
|
-
var leadingInset: CGFloat = 0
|
|
501
|
-
var trailingInset: CGFloat = 0
|
|
502
377
|
|
|
503
378
|
@Environment(\.appTheme) private var theme
|
|
504
379
|
|
|
505
380
|
var body: some View {
|
|
506
381
|
content()
|
|
507
382
|
.frame(maxWidth: .infinity)
|
|
508
|
-
.padding(.leading, leadingInset)
|
|
509
|
-
.padding(.trailing, trailingInset)
|
|
510
383
|
.padding(.vertical, Spacing.S)
|
|
511
384
|
.background(theme.colors.background.surface)
|
|
512
385
|
.overlay(alignment: .top) {
|
|
@@ -53,10 +53,9 @@ public struct BottomTab: View {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
private var bottomInset: CGFloat { safeAreaBottomInset() }
|
|
56
|
-
// the
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
56
|
+
// the bars float over the content (tab screens keep clear of them through duoTabBarInsets) or sit
|
|
57
|
+
// in the side strip, so only the home indicator is kept clear
|
|
58
|
+
private var reservedBottom: CGFloat { layout.insets.bottom }
|
|
60
59
|
|
|
61
60
|
private var compression: DuoBarCompression {
|
|
62
61
|
DuoBarCompression.resolve(
|
|
@@ -104,18 +103,13 @@ public struct BottomTab: View {
|
|
|
104
103
|
compression: compression
|
|
105
104
|
)
|
|
106
105
|
} else {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
)
|
|
115
|
-
theme.colors.background.surface
|
|
116
|
-
.frame(height: bottomInset + Spacing.S)
|
|
117
|
-
.ignoresSafeArea(edges: .horizontal)
|
|
118
|
-
}
|
|
106
|
+
BottomTabBar(
|
|
107
|
+
items: items,
|
|
108
|
+
floatingButton: floatingButton,
|
|
109
|
+
selectedIndex: selectedIndex,
|
|
110
|
+
onTabSelected: selectTab,
|
|
111
|
+
bottomInset: bottomInset
|
|
112
|
+
)
|
|
119
113
|
}
|
|
120
114
|
}
|
|
121
115
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
@@ -137,6 +131,7 @@ public struct BottomTab: View {
|
|
|
137
131
|
}
|
|
138
132
|
|
|
139
133
|
private func selectTab(_ index: Int) {
|
|
134
|
+
navigator.maxApi?.triggerEventVibration("light")
|
|
140
135
|
let switchTab = { if index != selectedIndex { selectedIndex = index } }
|
|
141
136
|
if let onTabPress { onTabPress(index, switchTab) } else { switchTab() }
|
|
142
137
|
}
|
|
@@ -208,11 +203,11 @@ private struct TabHost: UIViewControllerRepresentable {
|
|
|
208
203
|
|
|
209
204
|
private final class TabController: UIViewController {
|
|
210
205
|
private final class Tab {
|
|
211
|
-
let motion = TabMotion()
|
|
212
206
|
var host: UIHostingController<AnyView>!
|
|
213
207
|
}
|
|
214
208
|
|
|
215
|
-
|
|
209
|
+
/// The tab switch: the screens slide in index order over 280ms, CSS `ease`.
|
|
210
|
+
private static let switchDuration: TimeInterval = 0.28
|
|
216
211
|
|
|
217
212
|
private var tabs: [Int: Tab] = [:]
|
|
218
213
|
private var selectedIndex: Int?
|
|
@@ -226,7 +221,7 @@ private final class TabController: UIViewController {
|
|
|
226
221
|
|
|
227
222
|
override func viewDidLayoutSubviews() {
|
|
228
223
|
super.viewDidLayoutSubviews()
|
|
229
|
-
for subview in view.subviews { subview
|
|
224
|
+
for subview in view.subviews { place(subview) }
|
|
230
225
|
}
|
|
231
226
|
|
|
232
227
|
func update(
|
|
@@ -243,33 +238,43 @@ private final class TabController: UIViewController {
|
|
|
243
238
|
}
|
|
244
239
|
if let selectedIndex, tabs[selectedIndex] == nil { self.selectedIndex = nil }
|
|
245
240
|
// hidden tabs too, so a tab coming back already shows the latest items and environment
|
|
246
|
-
for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex
|
|
241
|
+
for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex) }
|
|
247
242
|
guard (0..<count).contains(index), index != selectedIndex else { return }
|
|
248
243
|
|
|
249
|
-
let
|
|
244
|
+
let previousIndex = selectedIndex
|
|
245
|
+
let previous = previousIndex.flatMap { tabs[$0] }
|
|
250
246
|
selectedIndex = index
|
|
251
247
|
let selected = tabs[index] ?? makeTab(index)
|
|
248
|
+
// a tab selected again while it leaves carries on from where it is
|
|
249
|
+
let entering = selected.host.view.superview == nil
|
|
252
250
|
attach(selected)
|
|
253
251
|
|
|
254
|
-
guard let previous, view.window != nil else {
|
|
255
|
-
selected.
|
|
252
|
+
guard let previous, let previousIndex, view.window != nil else {
|
|
253
|
+
selected.host.view.transform = .identity
|
|
256
254
|
previous.map(leave)
|
|
257
255
|
return
|
|
258
256
|
}
|
|
259
257
|
previous.host.view.isUserInteractionEnabled = false
|
|
260
|
-
|
|
258
|
+
let offset = index > previousIndex ? view.bounds.width : -view.bounds.width
|
|
259
|
+
if entering { selected.host.view.transform = CGAffineTransform(translationX: offset, y: 0) }
|
|
260
|
+
// a frame at the start values first, so a tab created just now slides in with its content
|
|
261
261
|
DispatchQueue.main.async {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
262
|
+
let animator = UIViewPropertyAnimator(
|
|
263
|
+
duration: Self.switchDuration,
|
|
264
|
+
controlPoint1: CGPoint(x: 0.25, y: 0.1),
|
|
265
|
+
controlPoint2: CGPoint(x: 0.25, y: 1)
|
|
266
|
+
) {
|
|
267
|
+
selected.host.view.transform = .identity
|
|
268
|
+
previous.host.view.transform = CGAffineTransform(translationX: -offset, y: 0)
|
|
269
|
+
}
|
|
270
|
+
animator.addCompletion { [weak self] _ in self?.leave(previous) }
|
|
271
|
+
animator.startAnimation()
|
|
267
272
|
}
|
|
268
273
|
}
|
|
269
274
|
|
|
270
275
|
private func makeTab(_ index: Int) -> Tab {
|
|
271
276
|
let tab = Tab()
|
|
272
|
-
let host = UIHostingController(rootView: rootView(index
|
|
277
|
+
let host = UIHostingController(rootView: rootView(index))
|
|
273
278
|
host.view.backgroundColor = .clear
|
|
274
279
|
addChild(host)
|
|
275
280
|
host.didMove(toParent: self)
|
|
@@ -278,14 +283,20 @@ private final class TabController: UIViewController {
|
|
|
278
283
|
return tab
|
|
279
284
|
}
|
|
280
285
|
|
|
281
|
-
private func rootView(_ index: Int
|
|
282
|
-
AnyView(
|
|
286
|
+
private func rootView(_ index: Int) -> AnyView {
|
|
287
|
+
AnyView(content(index).environment(\.self, environment))
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/// Bounds and center, a sliding tab carries a transform that frame doesn't work with.
|
|
291
|
+
private func place(_ subview: UIView) {
|
|
292
|
+
subview.bounds = view.bounds
|
|
293
|
+
subview.center = CGPoint(x: view.bounds.midX, y: view.bounds.midY)
|
|
283
294
|
}
|
|
284
295
|
|
|
285
296
|
private func attach(_ tab: Tab) {
|
|
286
297
|
let hostView: UIView = tab.host.view
|
|
287
298
|
hostView.isUserInteractionEnabled = true
|
|
288
|
-
hostView
|
|
299
|
+
place(hostView)
|
|
289
300
|
if hostView.superview === view {
|
|
290
301
|
view.bringSubviewToFront(hostView)
|
|
291
302
|
} else {
|
|
@@ -297,6 +308,7 @@ private final class TabController: UIViewController {
|
|
|
297
308
|
private func leave(_ tab: Tab) {
|
|
298
309
|
guard selectedIndex.flatMap({ tabs[$0] }) !== tab else { return }
|
|
299
310
|
tab.host.view.removeFromSuperview()
|
|
311
|
+
tab.host.view.transform = .identity
|
|
300
312
|
}
|
|
301
313
|
|
|
302
314
|
private func tearDown(_ tab: Tab) {
|
|
@@ -306,27 +318,9 @@ private final class TabController: UIViewController {
|
|
|
306
318
|
}
|
|
307
319
|
}
|
|
308
320
|
|
|
309
|
-
private final class TabMotion: ObservableObject {
|
|
310
|
-
@Published var visible = false
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/// The tab switch: 0.97 scale + fade over 200ms, both ways (Compose's tab enter / exit transitions).
|
|
314
|
-
private struct TabCard: View {
|
|
315
|
-
@ObservedObject var motion: TabMotion
|
|
316
|
-
let content: AnyView
|
|
317
|
-
|
|
318
|
-
var body: some View {
|
|
319
|
-
content
|
|
320
|
-
.opacity(motion.visible ? 1 : 0)
|
|
321
|
-
.scaleEffect(motion.visible ? 1 : 0.97)
|
|
322
|
-
.animation(.easeInOut(duration: 0.2), value: motion.visible)
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
321
|
/// Bottom safe-area inset (home indicator).
|
|
327
322
|
private func safeAreaBottomInset() -> CGFloat {
|
|
328
|
-
|
|
323
|
+
UIApplication.shared.connectedScenes
|
|
329
324
|
.compactMap { ($0 as? UIWindowScene)?.keyWindow?.safeAreaInsets.bottom }
|
|
330
325
|
.first ?? 0
|
|
331
|
-
return min(bottomInset, 21)
|
|
332
326
|
}
|