@momo-kits/native-kits 0.168.1-beta.37 → 0.168.1-beta.38
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/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/ios/Layout/ModalLayout.swift +0 -152
- package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +0 -364
|
@@ -16,7 +16,6 @@ public struct BottomTab: View {
|
|
|
16
16
|
private let compressionBehavior: DuoBarCompressionBehavior
|
|
17
17
|
private let onTabPress: ((_ index: Int, _ switchTab: @escaping () -> Void) -> Void)?
|
|
18
18
|
private let backToInitialTab: Bool
|
|
19
|
-
private let onTabLongPress: ((_ index: Int) -> Void)?
|
|
20
19
|
|
|
21
20
|
@EnvironmentObject private var navigator: Navigator
|
|
22
21
|
/// The screen hosting the tabs (Compose's `LocalNavigation` in BottomTab).
|
|
@@ -35,32 +34,28 @@ public struct BottomTab: View {
|
|
|
35
34
|
/// starts compressed; tapping the compressed one swaps them.
|
|
36
35
|
/// `onTabPress` gets every tab press with the switch to perform, e.g. after a login gate.
|
|
37
36
|
/// `backToInitialTab`: back off another tab returns to the initial one before leaving the screen.
|
|
38
|
-
/// `onTabLongPress`: RN `tabLongPress`; on iPhone Duo the held tab is still selected on release.
|
|
39
37
|
public init(
|
|
40
38
|
items: [BottomTabItem],
|
|
41
39
|
floatingButton: BottomTabFloatingButton? = nil,
|
|
42
40
|
compressionBehavior: DuoBarCompressionBehavior = .toolbar,
|
|
43
41
|
initialRouteName: String? = nil,
|
|
44
42
|
onTabPress: ((_ index: Int, _ switchTab: @escaping () -> Void) -> Void)? = nil,
|
|
45
|
-
backToInitialTab: Bool = true
|
|
46
|
-
onTabLongPress: ((_ index: Int) -> Void)? = nil
|
|
43
|
+
backToInitialTab: Bool = true
|
|
47
44
|
) {
|
|
48
45
|
self.items = items
|
|
49
46
|
self.floatingButton = floatingButton
|
|
50
47
|
self.compressionBehavior = compressionBehavior
|
|
51
48
|
self.onTabPress = onTabPress
|
|
52
49
|
self.backToInitialTab = backToInitialTab
|
|
53
|
-
self.onTabLongPress = onTabLongPress
|
|
54
50
|
let start = items.firstIndex { $0.name == initialRouteName } ?? 0
|
|
55
51
|
_startIndex = State(initialValue: start)
|
|
56
52
|
_selectedIndex = State(initialValue: start)
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
private var bottomInset: CGFloat { safeAreaBottomInset() }
|
|
60
|
-
// the
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
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 }
|
|
64
59
|
|
|
65
60
|
private var compression: DuoBarCompression {
|
|
66
61
|
DuoBarCompression.resolve(
|
|
@@ -105,30 +100,16 @@ public struct BottomTab: View {
|
|
|
105
100
|
floatingButton: floatingButton,
|
|
106
101
|
selectedIndex: selectedIndex,
|
|
107
102
|
onTabSelected: selectTab,
|
|
108
|
-
compression: compression
|
|
109
|
-
onTabLongPress: onTabLongPress,
|
|
110
|
-
onTick: { [maxApi = navigator.maxApi] in
|
|
111
|
-
if let maxApi {
|
|
112
|
-
maxApi.triggerEventVibration("light")
|
|
113
|
-
} else {
|
|
114
|
-
UIImpactFeedbackGenerator(style: .light).impactOccurred()
|
|
115
|
-
}
|
|
116
|
-
}
|
|
103
|
+
compression: compression
|
|
117
104
|
)
|
|
118
105
|
} else {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
onTabLongPress: onTabLongPress
|
|
127
|
-
)
|
|
128
|
-
theme.colors.background.surface
|
|
129
|
-
.frame(height: bottomInset + Spacing.S)
|
|
130
|
-
.ignoresSafeArea(edges: .horizontal)
|
|
131
|
-
}
|
|
106
|
+
BottomTabBar(
|
|
107
|
+
items: items,
|
|
108
|
+
floatingButton: floatingButton,
|
|
109
|
+
selectedIndex: selectedIndex,
|
|
110
|
+
onTabSelected: selectTab,
|
|
111
|
+
bottomInset: bottomInset
|
|
112
|
+
)
|
|
132
113
|
}
|
|
133
114
|
}
|
|
134
115
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
@@ -150,6 +131,7 @@ public struct BottomTab: View {
|
|
|
150
131
|
}
|
|
151
132
|
|
|
152
133
|
private func selectTab(_ index: Int) {
|
|
134
|
+
navigator.maxApi?.triggerEventVibration("light")
|
|
153
135
|
let switchTab = { if index != selectedIndex { selectedIndex = index } }
|
|
154
136
|
if let onTabPress { onTabPress(index, switchTab) } else { switchTab() }
|
|
155
137
|
}
|
|
@@ -221,11 +203,11 @@ private struct TabHost: UIViewControllerRepresentable {
|
|
|
221
203
|
|
|
222
204
|
private final class TabController: UIViewController {
|
|
223
205
|
private final class Tab {
|
|
224
|
-
let motion = TabMotion()
|
|
225
206
|
var host: UIHostingController<AnyView>!
|
|
226
207
|
}
|
|
227
208
|
|
|
228
|
-
|
|
209
|
+
/// The tab switch: the screens slide in index order over 280ms, CSS `ease`.
|
|
210
|
+
private static let switchDuration: TimeInterval = 0.28
|
|
229
211
|
|
|
230
212
|
private var tabs: [Int: Tab] = [:]
|
|
231
213
|
private var selectedIndex: Int?
|
|
@@ -239,7 +221,7 @@ private final class TabController: UIViewController {
|
|
|
239
221
|
|
|
240
222
|
override func viewDidLayoutSubviews() {
|
|
241
223
|
super.viewDidLayoutSubviews()
|
|
242
|
-
for subview in view.subviews { subview
|
|
224
|
+
for subview in view.subviews { place(subview) }
|
|
243
225
|
}
|
|
244
226
|
|
|
245
227
|
func update(
|
|
@@ -256,33 +238,43 @@ private final class TabController: UIViewController {
|
|
|
256
238
|
}
|
|
257
239
|
if let selectedIndex, tabs[selectedIndex] == nil { self.selectedIndex = nil }
|
|
258
240
|
// hidden tabs too, so a tab coming back already shows the latest items and environment
|
|
259
|
-
for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex
|
|
241
|
+
for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex) }
|
|
260
242
|
guard (0..<count).contains(index), index != selectedIndex else { return }
|
|
261
243
|
|
|
262
|
-
let
|
|
244
|
+
let previousIndex = selectedIndex
|
|
245
|
+
let previous = previousIndex.flatMap { tabs[$0] }
|
|
263
246
|
selectedIndex = index
|
|
264
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
|
|
265
250
|
attach(selected)
|
|
266
251
|
|
|
267
|
-
guard let previous, view.window != nil else {
|
|
268
|
-
selected.
|
|
252
|
+
guard let previous, let previousIndex, view.window != nil else {
|
|
253
|
+
selected.host.view.transform = .identity
|
|
269
254
|
previous.map(leave)
|
|
270
255
|
return
|
|
271
256
|
}
|
|
272
257
|
previous.host.view.isUserInteractionEnabled = false
|
|
273
|
-
|
|
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
|
|
274
261
|
DispatchQueue.main.async {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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()
|
|
280
272
|
}
|
|
281
273
|
}
|
|
282
274
|
|
|
283
275
|
private func makeTab(_ index: Int) -> Tab {
|
|
284
276
|
let tab = Tab()
|
|
285
|
-
let host = UIHostingController(rootView: rootView(index
|
|
277
|
+
let host = UIHostingController(rootView: rootView(index))
|
|
286
278
|
host.view.backgroundColor = .clear
|
|
287
279
|
addChild(host)
|
|
288
280
|
host.didMove(toParent: self)
|
|
@@ -291,14 +283,20 @@ private final class TabController: UIViewController {
|
|
|
291
283
|
return tab
|
|
292
284
|
}
|
|
293
285
|
|
|
294
|
-
private func rootView(_ index: Int
|
|
295
|
-
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)
|
|
296
294
|
}
|
|
297
295
|
|
|
298
296
|
private func attach(_ tab: Tab) {
|
|
299
297
|
let hostView: UIView = tab.host.view
|
|
300
298
|
hostView.isUserInteractionEnabled = true
|
|
301
|
-
hostView
|
|
299
|
+
place(hostView)
|
|
302
300
|
if hostView.superview === view {
|
|
303
301
|
view.bringSubviewToFront(hostView)
|
|
304
302
|
} else {
|
|
@@ -310,6 +308,7 @@ private final class TabController: UIViewController {
|
|
|
310
308
|
private func leave(_ tab: Tab) {
|
|
311
309
|
guard selectedIndex.flatMap({ tabs[$0] }) !== tab else { return }
|
|
312
310
|
tab.host.view.removeFromSuperview()
|
|
311
|
+
tab.host.view.transform = .identity
|
|
313
312
|
}
|
|
314
313
|
|
|
315
314
|
private func tearDown(_ tab: Tab) {
|
|
@@ -319,27 +318,9 @@ private final class TabController: UIViewController {
|
|
|
319
318
|
}
|
|
320
319
|
}
|
|
321
320
|
|
|
322
|
-
private final class TabMotion: ObservableObject {
|
|
323
|
-
@Published var visible = false
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/// The tab switch: 0.97 scale + fade over 200ms, both ways (Compose's tab enter / exit transitions).
|
|
327
|
-
private struct TabCard: View {
|
|
328
|
-
@ObservedObject var motion: TabMotion
|
|
329
|
-
let content: AnyView
|
|
330
|
-
|
|
331
|
-
var body: some View {
|
|
332
|
-
content
|
|
333
|
-
.opacity(motion.visible ? 1 : 0)
|
|
334
|
-
.scaleEffect(motion.visible ? 1 : 0.97)
|
|
335
|
-
.animation(.easeInOut(duration: 0.2), value: motion.visible)
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
321
|
/// Bottom safe-area inset (home indicator).
|
|
340
322
|
private func safeAreaBottomInset() -> CGFloat {
|
|
341
|
-
|
|
323
|
+
UIApplication.shared.connectedScenes
|
|
342
324
|
.compactMap { ($0 as? UIWindowScene)?.keyWindow?.safeAreaInsets.bottom }
|
|
343
325
|
.first ?? 0
|
|
344
|
-
return min(bottomInset, 21)
|
|
345
326
|
}
|