@momo-kits/native-kits 0.168.1-beta.4 → 0.168.1-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +15 -10
- package/README.md +2 -10
- package/ios/Application/ApplicationEnvironment.swift +7 -6
- package/ios/Application/DesignSystemKits.swift +163 -0
- package/ios/Application/DesignSystemKitsPayload.swift +68 -0
- package/ios/Badge/BadgeRibbon.swift +8 -1
- package/ios/Extensions/Color++.swift +2 -4
- package/ios/Input/Input.swift +16 -4
- package/ios/Input/InputPhoneNumber.swift +1 -3
- package/ios/Input/InputSearch.swift +1 -2
- package/ios/Input/InputTextArea.swift +8 -4
- package/ios/InputMoney/InputMoney.swift +6 -7
- package/ios/Layout/ModalLayout.swift +152 -0
- package/ios/Layout/ScreenLayout.swift +77 -18
- package/ios/Navigation/BottomSheet.swift +56 -53
- 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/DuoBarCompression.swift +2 -3
- package/ios/Navigation/BottomTab/DuoTabBar.swift +64 -172
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
- package/ios/Navigation/Component/HeaderBackground.swift +22 -1
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/Component/SnackBar.swift +4 -0
- package/ios/Navigation/ModalScreen.swift +20 -5
- package/ios/Navigation/StackScreen.swift +6 -8
- package/ios/Popup/PopupDisplay.swift +6 -4
- package/ios/Popup/PopupInput.swift +6 -4
- package/ios/Popup/PopupLayout.swift +17 -11
- package/ios/Popup/PopupNotify.swift +32 -25
- package/ios/Stepper/Stepper.swift +1 -2
- package/ios/Template/TrustBanner/TrustBanner.swift +4 -2
- package/ios/Typography/FontScale.swift +29 -15
- package/ios/Typography/Text.swift +88 -14
- package/ios/Typography/Typography.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/package.json +1 -1
- package/publish.sh +2 -33
- package/ios/Typography/FontScaleStore.swift +0 -58
- package/ios/Typography/KitDesignSystem.swift +0 -17
|
@@ -2,64 +2,68 @@
|
|
|
2
2
|
// CurvedContainer.swift
|
|
3
3
|
// MoMoUIKits
|
|
4
4
|
//
|
|
5
|
-
// SwiftUI mirror of Compose's `CurvedContainer
|
|
6
|
-
//
|
|
7
|
-
// carving a circular cut-out into the tab bar's top edge.
|
|
5
|
+
// SwiftUI mirror of Compose's `CurvedContainer.kt`: the navigation bar container shape, a rounded
|
|
6
|
+
// rectangle with a notch cut into the top edge around the center action, and its floating shadow.
|
|
8
7
|
//
|
|
9
8
|
|
|
10
9
|
import SwiftUI
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var height: CGFloat = 16
|
|
18
|
-
var color: Color = Colors.black01
|
|
11
|
+
/// Rounded container, with the notch dipped into the top edge around `notchCenterX` (from the
|
|
12
|
+
/// leading edge).
|
|
13
|
+
struct NotchedBarShape: Shape {
|
|
14
|
+
var radius: CGFloat
|
|
15
|
+
var notchCenterX: CGFloat?
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
let
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let
|
|
17
|
+
func path(in rect: CGRect) -> Path {
|
|
18
|
+
let r = min(radius, rect.height / 2, rect.width / 2)
|
|
19
|
+
guard let cx = notchCenterX else {
|
|
20
|
+
return Path(roundedRect: rect, cornerRadius: r)
|
|
21
|
+
}
|
|
22
|
+
let w = rect.width
|
|
23
|
+
let h = rect.height
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.
|
|
25
|
+
var path = Path()
|
|
26
|
+
path.move(to: CGPoint(x: r, y: 0))
|
|
27
|
+
path.addLine(to: CGPoint(x: cx - TabBarMetrics.notchHalfWidth, y: 0))
|
|
28
|
+
for curve in TabBarMetrics.notchCurves {
|
|
29
|
+
path.addCurve(
|
|
30
|
+
to: CGPoint(x: cx + curve[2].x, y: curve[2].y),
|
|
31
|
+
control1: CGPoint(x: cx + curve[0].x, y: curve[0].y),
|
|
32
|
+
control2: CGPoint(x: cx + curve[1].x, y: curve[1].y)
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
path.addLine(to: CGPoint(x: w - r, y: 0))
|
|
36
|
+
path.addRelativeArc(center: CGPoint(x: w - r, y: r), radius: r, startAngle: .degrees(-90), delta: .degrees(90))
|
|
37
|
+
path.addLine(to: CGPoint(x: w, y: h - r))
|
|
38
|
+
path.addRelativeArc(center: CGPoint(x: w - r, y: h - r), radius: r, startAngle: .degrees(0), delta: .degrees(90))
|
|
39
|
+
path.addLine(to: CGPoint(x: r, y: h))
|
|
40
|
+
path.addRelativeArc(center: CGPoint(x: r, y: h - r), radius: r, startAngle: .degrees(90), delta: .degrees(90))
|
|
41
|
+
path.addLine(to: CGPoint(x: 0, y: r))
|
|
42
|
+
path.addRelativeArc(center: CGPoint(x: r, y: r), radius: r, startAngle: .degrees(180), delta: .degrees(90))
|
|
43
|
+
path.closeSubpath()
|
|
44
|
+
return path.offsetBy(dx: rect.minX, dy: rect.minY)
|
|
32
45
|
}
|
|
33
46
|
}
|
|
34
47
|
|
|
35
|
-
///
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
let circleOverTop: CGFloat
|
|
39
|
-
let centerX: CGFloat
|
|
40
|
-
let circleOverR: CGFloat
|
|
41
|
-
let width: CGFloat
|
|
48
|
+
/// Navigation bar container: surface fill with the floating shadow following the shape.
|
|
49
|
+
struct TabBarContainer<S: Shape>: ViewModifier {
|
|
50
|
+
let shape: S
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
var path = Path()
|
|
45
|
-
path.move(to: CGPoint(x: 0, y: circleOverTop))
|
|
46
|
-
path.addLine(to: CGPoint(x: centerX - circleOverR - 40, y: circleOverTop))
|
|
52
|
+
@Environment(\.appTheme) private var theme
|
|
47
53
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
func body(content: Content) -> some View {
|
|
55
|
+
content.background(
|
|
56
|
+
// Figma Shadow/floating, one layer per shadow so they don't shadow each other:
|
|
57
|
+
// 12% blur 24, then 4% blur 32 spread -16 cast from the shape shrunk by 16
|
|
58
|
+
ZStack {
|
|
59
|
+
shape.fill(theme.colors.background.surface)
|
|
60
|
+
.padding(16)
|
|
61
|
+
.shadow(color: Color.black.opacity(0.04), radius: 16, x: 0, y: 12)
|
|
62
|
+
shape.fill(theme.colors.background.surface)
|
|
63
|
+
.shadow(color: Color.black.opacity(0.12), radius: 12)
|
|
64
|
+
shape.fill(theme.colors.background.surface)
|
|
65
|
+
}
|
|
66
|
+
.allowsHitTesting(false)
|
|
57
67
|
)
|
|
58
|
-
|
|
59
|
-
path.addLine(to: CGPoint(x: width, y: circleOverTop))
|
|
60
|
-
path.addLine(to: CGPoint(x: width, y: 60))
|
|
61
|
-
path.addLine(to: CGPoint(x: 0, y: 60))
|
|
62
|
-
path.closeSubpath()
|
|
63
|
-
return path
|
|
64
68
|
}
|
|
65
69
|
}
|
|
@@ -35,8 +35,6 @@ struct DuoBarCompression {
|
|
|
35
35
|
static let defaultToolbarHeight = DuoMetrics.controlSize + Spacing.M + 2 * DuoMetrics.itemPitch
|
|
36
36
|
/// Back, then the single button the toolbar folds into.
|
|
37
37
|
private static let compressedToolbarHeight = 2 * DuoMetrics.controlSize + Spacing.M
|
|
38
|
-
/// Back alone, while a rail opened from the compressed state takes the toolbar slot.
|
|
39
|
-
private static let backOnlyHeight = DuoMetrics.controlSize
|
|
40
38
|
|
|
41
39
|
/// - both fit: both stay whole
|
|
42
40
|
/// - one fits whole beside the other compressed: one is compressed, tapping it swaps them
|
|
@@ -72,7 +70,8 @@ struct DuoBarCompression {
|
|
|
72
70
|
|
|
73
71
|
let expandToolbar = { opened.wrappedValue = .toolbar }
|
|
74
72
|
let expandTabBar = { opened.wrappedValue = .tabBar }
|
|
75
|
-
|
|
73
|
+
// an opened rail always shows, even when only the group gap is short: it closes once a tab is picked
|
|
74
|
+
if opened.wrappedValue == .tabBar {
|
|
76
75
|
return DuoBarCompression(
|
|
77
76
|
toolbarCompressed: true,
|
|
78
77
|
tabBarCompressed: false,
|
|
@@ -2,27 +2,13 @@
|
|
|
2
2
|
// DuoTabBar.swift
|
|
3
3
|
// MoMoUIKits
|
|
4
4
|
//
|
|
5
|
-
// iPhone Duo tab bar, port of RN `BottomTab/DuoTabBar.tsx` (Figma
|
|
6
|
-
// a
|
|
5
|
+
// iPhone Duo tab bar, port of RN `BottomTab/DuoTabBar.tsx` (Figma "Specs Navigation", DS-984):
|
|
6
|
+
// a rail in the side bar, or the horizontal bar at 65% of the short side when unfolded portrait.
|
|
7
7
|
//
|
|
8
8
|
|
|
9
9
|
import SwiftUI
|
|
10
10
|
|
|
11
|
-
private let
|
|
12
|
-
private let iconSize: CGFloat = 28
|
|
13
|
-
private let qrIconSize: CGFloat = 24
|
|
14
|
-
private let railPadding: CGFloat = 6
|
|
15
|
-
private let railGap = Spacing.XXS
|
|
16
|
-
// selection bubble overflows the 48 rail cell by 5 above and below (Figma MT2)
|
|
17
|
-
private let railBubbleWidth: CGFloat = 44
|
|
18
|
-
private let railBubbleHeight: CGFloat = 58
|
|
19
|
-
let duoFloatingTabBarHeight: CGFloat = 62
|
|
20
|
-
private let floatingPadding = Spacing.XS
|
|
21
|
-
private let floatingQrSize: CGFloat = 44
|
|
22
|
-
// floating bar spans 6 of the 8 portrait grid columns, like the content
|
|
23
|
-
private let gridColumns: CGFloat = 8
|
|
24
|
-
private let gridSpan: CGFloat = 6
|
|
25
|
-
private let tabSpring = Animation.interpolatingSpring(mass: 0.8, stiffness: 220, damping: 18)
|
|
11
|
+
private let compactSize = DuoMetrics.controlSize
|
|
26
12
|
|
|
27
13
|
/// Room tab screens leave for the Duo tab bar, provided by BottomTab to its tab StackScreens.
|
|
28
14
|
struct DuoTabBarInsets: Equatable {
|
|
@@ -43,58 +29,33 @@ extension EnvironmentValues {
|
|
|
43
29
|
}
|
|
44
30
|
}
|
|
45
31
|
|
|
46
|
-
/// Rail plus the
|
|
32
|
+
/// Rail container plus the center action under it; compressed, the rail is a single button.
|
|
47
33
|
func duoRailHeight(itemCount: Int, hasQr: Bool, compressed: Bool = false) -> CGFloat {
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
|
|
34
|
+
let rail = compressed
|
|
35
|
+
? compactSize
|
|
36
|
+
: CGFloat(itemCount) * TabBarMetrics.railItemHeight + TabBarMetrics.railPaddingBottom
|
|
37
|
+
return rail + (hasQr ? TabBarMetrics.railCtaGap + TabBarMetrics.railCtaHeight : 0)
|
|
51
38
|
}
|
|
52
39
|
|
|
53
40
|
extension ScreenLayout {
|
|
41
|
+
/// The horizontal bar sits above the home indicator area.
|
|
42
|
+
var duoFloatingTabBarBottom: CGFloat {
|
|
43
|
+
TabBarMetrics.bottomGap(insets.bottom)
|
|
44
|
+
}
|
|
45
|
+
|
|
54
46
|
func duoTabBarInsets(itemCount: Int, hasFloatingButton: Bool, tabBarCompressed: Bool = false) -> DuoTabBarInsets {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
// the horizontal bar floats over the content (phone and unfolded Duo); the overlay is measured
|
|
48
|
+
// from the bottom safe area, the bar reaches into it
|
|
49
|
+
guard isIPhoneDuo, let sideBar else {
|
|
50
|
+
// the center action's button rises above the bar, tab content leaves room for it too
|
|
51
|
+
let ctaLift = hasFloatingButton && itemCount % 2 == 0 ? TabBarMetrics.ctaLift : 0
|
|
52
|
+
return DuoTabBarInsets(overlay: TabBarMetrics.height + ctaLift + duoFloatingTabBarBottom - insets.bottom)
|
|
58
53
|
}
|
|
59
54
|
let rail = duoRailHeight(itemCount: itemCount, hasQr: hasFloatingButton, compressed: tabBarCompressed)
|
|
60
55
|
return DuoTabBarInsets(sideBarReserve: sideBar.bottom + rail + DuoBarCompression.groupGap)
|
|
61
56
|
}
|
|
62
57
|
}
|
|
63
58
|
|
|
64
|
-
/// Glass on iOS 26, a system blur before it (RN GlassView's fallback).
|
|
65
|
-
struct DuoBarMaterial<S: Shape>: ViewModifier {
|
|
66
|
-
let shape: S
|
|
67
|
-
var visible: Bool = true
|
|
68
|
-
|
|
69
|
-
func body(content: Content) -> some View {
|
|
70
|
-
content.background(material.allowsHitTesting(false))
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
@ViewBuilder
|
|
74
|
-
private var material: some View {
|
|
75
|
-
#if compiler(>=6.2)
|
|
76
|
-
if #available(iOS 26.0, *) {
|
|
77
|
-
// glass materializes by toggling its effect, it does not fade with opacity
|
|
78
|
-
Color.clear
|
|
79
|
-
.glassEffect(visible ? .regular : .identity, in: shape)
|
|
80
|
-
.shadow(color: Color.black.opacity(visible ? 0.16 : 0), radius: 16, x: 0, y: 6)
|
|
81
|
-
.animation(.easeInOut(duration: 0.25), value: visible)
|
|
82
|
-
} else {
|
|
83
|
-
blur
|
|
84
|
-
}
|
|
85
|
-
#else
|
|
86
|
-
blur
|
|
87
|
-
#endif
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
private var blur: some View {
|
|
91
|
-
shape.fill(.regularMaterial)
|
|
92
|
-
.shadow(color: Color.black.opacity(0.16), radius: 16, x: 0, y: 6)
|
|
93
|
-
.opacity(visible ? 1 : 0)
|
|
94
|
-
.animation(.easeInOut(duration: 0.25), value: visible)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
59
|
struct DuoTabBar: View {
|
|
99
60
|
let items: [BottomTabItem]
|
|
100
61
|
let floatingButton: BottomTabFloatingButton?
|
|
@@ -115,7 +76,7 @@ struct DuoTabBar: View {
|
|
|
115
76
|
}
|
|
116
77
|
}
|
|
117
78
|
|
|
118
|
-
/// Vertical bar anchored to the bottom of the side bar,
|
|
79
|
+
/// Vertical bar anchored to the bottom of the side bar, center action below it.
|
|
119
80
|
/// When the side bar is short it can shrink to one button showing the current tab
|
|
120
81
|
/// (HIG "Tab bar compressed"); tapping it expands the rail and compresses the toolbar.
|
|
121
82
|
private struct DuoRailTabBar: View {
|
|
@@ -131,15 +92,15 @@ private struct DuoRailTabBar: View {
|
|
|
131
92
|
private var isRight: Bool { sideBar.edge == .right }
|
|
132
93
|
|
|
133
94
|
var body: some View {
|
|
134
|
-
VStack(spacing:
|
|
95
|
+
VStack(spacing: TabBarMetrics.railCtaGap) {
|
|
135
96
|
if compression.tabBarCompressed, items.indices.contains(selectedIndex) {
|
|
136
97
|
SwiftUI.Button(action: compression.expandTabBar) {
|
|
137
|
-
|
|
138
|
-
.frame(width:
|
|
98
|
+
TabIcon(item: items[selectedIndex], selected: true, vertical: true)
|
|
99
|
+
.frame(width: compactSize, height: compactSize)
|
|
139
100
|
.contentShape(Circle())
|
|
140
101
|
}
|
|
141
102
|
.buttonStyle(.plain)
|
|
142
|
-
.modifier(
|
|
103
|
+
.modifier(TabBarContainer(shape: Circle()))
|
|
143
104
|
.accessibilityLabel(items[selectedIndex].label)
|
|
144
105
|
.accessibilityIdentifier("bottom_tab_bar")
|
|
145
106
|
} else {
|
|
@@ -147,9 +108,12 @@ private struct DuoRailTabBar: View {
|
|
|
147
108
|
}
|
|
148
109
|
|
|
149
110
|
if let floatingButton {
|
|
150
|
-
|
|
111
|
+
RailCenterAction(data: floatingButton)
|
|
151
112
|
}
|
|
152
113
|
}
|
|
114
|
+
// the rail lines up with the header buttons in the side bar: centered on a 48 lane kept
|
|
115
|
+
// Spacing.M from the strip's inner edge; the wider rail and center action overflow it evenly
|
|
116
|
+
.frame(width: compactSize)
|
|
153
117
|
.padding(isRight ? .leading : .trailing, Spacing.M)
|
|
154
118
|
.frame(width: sideBar.width, alignment: isRight ? .leading : .trailing)
|
|
155
119
|
.padding(.bottom, sideBar.bottom)
|
|
@@ -157,39 +121,42 @@ private struct DuoRailTabBar: View {
|
|
|
157
121
|
.ignoresSafeArea()
|
|
158
122
|
}
|
|
159
123
|
|
|
160
|
-
///
|
|
124
|
+
/// Column of rail items (.Nav/Duo/Item) with the sliding active indicator.
|
|
161
125
|
private var rail: some View {
|
|
162
126
|
ZStack(alignment: .top) {
|
|
163
|
-
|
|
164
|
-
.
|
|
165
|
-
.
|
|
166
|
-
.
|
|
167
|
-
+ CGFloat(selectedIndex) * (itemSize + railGap))
|
|
168
|
-
.animation(tabSpring, value: selectedIndex)
|
|
127
|
+
ActiveIndicator(radius: TabBarMetrics.railIndicatorRadius)
|
|
128
|
+
.frame(width: TabBarMetrics.railItemWidth, height: TabBarMetrics.railIndicatorHeight)
|
|
129
|
+
.offset(y: Spacing.XS + CGFloat(selectedIndex) * TabBarMetrics.railItemHeight)
|
|
130
|
+
.animation(TabBarMetrics.indicatorMotion, value: selectedIndex)
|
|
169
131
|
|
|
170
|
-
VStack(spacing:
|
|
132
|
+
VStack(spacing: 0) {
|
|
171
133
|
ForEach(items.indices, id: \.self) { index in
|
|
172
134
|
SwiftUI.Button {
|
|
173
135
|
onTabSelected(index)
|
|
174
136
|
compression.onTabSelected()
|
|
175
137
|
} label: {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
138
|
+
VStack(spacing: 0) {
|
|
139
|
+
TabItemContent(item: items[index], selected: index == selectedIndex, vertical: true, fixedFontScale: true)
|
|
140
|
+
}
|
|
141
|
+
.frame(width: TabBarMetrics.railItemWidth, height: TabBarMetrics.railItemHeight)
|
|
142
|
+
.contentShape(Rectangle())
|
|
179
143
|
}
|
|
180
144
|
.buttonStyle(.plain)
|
|
181
145
|
.accessibilityLabel(items[index].label)
|
|
146
|
+
.accessibilityAddTraits(index == selectedIndex ? .isSelected : [])
|
|
182
147
|
}
|
|
183
148
|
}
|
|
184
|
-
.padding(.vertical, railPadding)
|
|
185
149
|
}
|
|
186
|
-
.
|
|
187
|
-
.
|
|
150
|
+
.padding(.horizontal, TabBarMetrics.railPaddingHorizontal)
|
|
151
|
+
.padding(.bottom, TabBarMetrics.railPaddingBottom)
|
|
152
|
+
.frame(width: TabBarMetrics.railContainerWidth)
|
|
153
|
+
.modifier(TabBarContainer(shape: RoundedRectangle(cornerRadius: Radius.XL)))
|
|
154
|
+
.accessibilityElement(children: .contain)
|
|
188
155
|
.accessibilityIdentifier("bottom_tab_bar")
|
|
189
156
|
}
|
|
190
157
|
}
|
|
191
158
|
|
|
192
|
-
///
|
|
159
|
+
/// Horizontal navigation bar of the unfolded display: 65% of the short side, centered.
|
|
193
160
|
private struct DuoFloatingTabBar: View {
|
|
194
161
|
let items: [BottomTabItem]
|
|
195
162
|
let floatingButton: BottomTabFloatingButton?
|
|
@@ -197,108 +164,33 @@ private struct DuoFloatingTabBar: View {
|
|
|
197
164
|
let onTabSelected: (Int) -> Void
|
|
198
165
|
|
|
199
166
|
@Environment(\.screenLayout) private var layout
|
|
200
|
-
@Environment(\.appTheme) private var theme
|
|
201
|
-
|
|
202
|
-
private var barWidth: CGFloat {
|
|
203
|
-
let columnWidth = (layout.width - 2 * Spacing.M - (gridColumns - 1) * Spacing.M) / gridColumns
|
|
204
|
-
return columnWidth * gridSpan + (gridSpan - 1) * Spacing.M
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
private var useQr: Bool { floatingButton != nil && items.count % 2 == 0 }
|
|
208
|
-
private var middle: Int { items.count / 2 }
|
|
209
|
-
private var cellCount: Int { items.count + (useQr ? 1 : 0) }
|
|
210
|
-
private var cellWidth: CGFloat { (barWidth - floatingPadding * 2) / CGFloat(max(cellCount, 1)) }
|
|
211
|
-
private var visualIndex: Int { useQr && selectedIndex >= middle ? selectedIndex + 1 : selectedIndex }
|
|
212
167
|
|
|
213
168
|
var body: some View {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if useQr && cell == middle, let floatingButton {
|
|
224
|
-
DuoQrButton(data: floatingButton, size: floatingQrSize)
|
|
225
|
-
.frame(width: cellWidth)
|
|
226
|
-
} else {
|
|
227
|
-
let index = useQr && cell > middle ? cell - 1 : cell
|
|
228
|
-
tabCell(index)
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
.padding(floatingPadding)
|
|
234
|
-
.frame(width: barWidth, height: duoFloatingTabBarHeight)
|
|
235
|
-
.modifier(DuoBarMaterial(shape: Capsule()))
|
|
236
|
-
.accessibilityIdentifier("bottom_tab_bar")
|
|
237
|
-
.padding(.bottom, layout.insets.bottom + Spacing.M)
|
|
169
|
+
HorizontalTabBar(
|
|
170
|
+
items: items,
|
|
171
|
+
floatingButton: floatingButton,
|
|
172
|
+
selectedIndex: selectedIndex,
|
|
173
|
+
onTabSelected: onTabSelected,
|
|
174
|
+
width: TabBarMetrics.horizontalBarWidth(layout),
|
|
175
|
+
fixedFontScale: true
|
|
176
|
+
)
|
|
177
|
+
.padding(.bottom, layout.duoFloatingTabBarBottom)
|
|
238
178
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
|
|
239
179
|
.ignoresSafeArea()
|
|
240
180
|
}
|
|
241
|
-
|
|
242
|
-
private func tabCell(_ index: Int) -> some View {
|
|
243
|
-
let selected = index == selectedIndex
|
|
244
|
-
return SwiftUI.Button { onTabSelected(index) } label: {
|
|
245
|
-
VStack(spacing: Spacing.XXS) {
|
|
246
|
-
DuoTabIcon(item: items[index], selected: selected)
|
|
247
|
-
MomoText(
|
|
248
|
-
items[index].label,
|
|
249
|
-
typography: .labelXsMedium,
|
|
250
|
-
color: selected ? theme.colors.primary : theme.colors.text.default,
|
|
251
|
-
textAlign: .center,
|
|
252
|
-
maxLines: 1
|
|
253
|
-
)
|
|
254
|
-
}
|
|
255
|
-
.frame(width: cellWidth)
|
|
256
|
-
.frame(maxHeight: .infinity)
|
|
257
|
-
.contentShape(Rectangle())
|
|
258
|
-
}
|
|
259
|
-
.buttonStyle(.plain)
|
|
260
|
-
.accessibilityLabel(items[index].label)
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
private struct DuoTabIcon: View {
|
|
265
|
-
let item: BottomTabItem
|
|
266
|
-
let selected: Bool
|
|
267
|
-
|
|
268
|
-
@Environment(\.appTheme) private var theme
|
|
269
|
-
|
|
270
|
-
private var badgeLabel: String? {
|
|
271
|
-
guard let label = item.badgeLabel else { return nil }
|
|
272
|
-
if let n = Int(label), n == 0 { return nil }
|
|
273
|
-
return label
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
var body: some View {
|
|
277
|
-
Icon(source: item.icon, size: iconSize, color: selected ? theme.colors.primary : theme.colors.text.default)
|
|
278
|
-
.overlay(alignment: .topTrailing) {
|
|
279
|
-
if let badgeLabel, !badgeLabel.isEmpty {
|
|
280
|
-
Badge(label: badgeLabel).offset(x: Spacing.S, y: -Spacing.XS)
|
|
281
|
-
} else if badgeLabel != nil || item.showDot {
|
|
282
|
-
BadgeDot(size: .small)
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
181
|
}
|
|
287
182
|
|
|
288
|
-
|
|
183
|
+
/// Center action of the rail: round button with its label, under the container.
|
|
184
|
+
private struct RailCenterAction: View {
|
|
289
185
|
let data: BottomTabFloatingButton
|
|
290
|
-
let size: CGFloat
|
|
291
|
-
|
|
292
|
-
@Environment(\.appTheme) private var theme
|
|
293
186
|
|
|
294
187
|
var body: some View {
|
|
295
|
-
SwiftUI.Button(action: data.onPress) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
.accessibilityLabel(data.label)
|
|
188
|
+
SwiftUI.Button(action: data.onPress) { EmptyView() }
|
|
189
|
+
.buttonStyle(CenterActionStyle(size: TabBarMetrics.railCtaSize, vertical: true, icon: data.icon,
|
|
190
|
+
iconContent: data.iconContent, labelContent: data.labelContent,
|
|
191
|
+
label: data.label, fixedFontScale: true))
|
|
192
|
+
.frame(width: TabBarMetrics.railCtaWidth, height: TabBarMetrics.railCtaHeight)
|
|
193
|
+
.accessibilityLabel(data.label)
|
|
194
|
+
.accessibilityIdentifier(data.label)
|
|
303
195
|
}
|
|
304
196
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
//
|
|
2
|
+
// TabBarMetrics.swift
|
|
3
|
+
// MoMoUIKits
|
|
4
|
+
//
|
|
5
|
+
// Navigation bar measurements (Figma "Specs Navigation", DS-984), mirrored from Compose's
|
|
6
|
+
// `navigation/bottomtab/TabBarMetrics.kt` and RN `BottomTab/metrics.ts`.
|
|
7
|
+
// Horizontal: floating container with items split evenly, center action in a notch.
|
|
8
|
+
// Vertical: iPhone Duo rail, center action under the container.
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
import SwiftUI
|
|
12
|
+
|
|
13
|
+
enum TabBarMetrics {
|
|
14
|
+
static let height: CGFloat = 68
|
|
15
|
+
static let margin = Spacing.S
|
|
16
|
+
static let paddingVertical = Spacing.S
|
|
17
|
+
static let paddingHorizontal = Spacing.M
|
|
18
|
+
static let itemGap = Spacing.XS
|
|
19
|
+
static let iconSize: CGFloat = 24
|
|
20
|
+
static let indicatorHeight: CGFloat = 32
|
|
21
|
+
static let indicatorRadius = Radius.XL
|
|
22
|
+
// home indicator / gesture bar area under the container
|
|
23
|
+
static let systemIndicatorHeight: CGFloat = 24
|
|
24
|
+
// unfolded foldables (short side from 600, the smallest in the spec) use 65% of the short side,
|
|
25
|
+
// centered; phones and folded outer displays fill the window
|
|
26
|
+
static let foldableMinShortSide: CGFloat = 600
|
|
27
|
+
static let foldableWidthRatio: CGFloat = 0.65
|
|
28
|
+
static let ctaSlotWidth: CGFloat = 92
|
|
29
|
+
static let ctaSize: CGFloat = 48
|
|
30
|
+
// the icon sits 10 inside the 48 button (prototype .cta: 28 icon), 12 inside the 52 rail one
|
|
31
|
+
static let ctaIconSize: CGFloat = 28
|
|
32
|
+
// the button rises 22 above the container top edge
|
|
33
|
+
static let ctaLift: CGFloat = 22
|
|
34
|
+
static let ctaLabelGap = Spacing.M
|
|
35
|
+
static let ctaLabelHeight: CGFloat = 18
|
|
36
|
+
// notch dipped into the container top edge under the center action (Figma "Backgroud" path):
|
|
37
|
+
// starts notchHalfWidth left of the center, then cubic segments of control1, control2, end,
|
|
38
|
+
// each point as (dx from the center, dy below the top edge)
|
|
39
|
+
static let notchHalfWidth: CGFloat = 50.758
|
|
40
|
+
static let notchCurves: [[CGPoint]] = [
|
|
41
|
+
[CGPoint(x: -39.749, y: 0), CGPoint(x: -31.231, y: 9.765), CGPoint(x: -24.563, y: 18.526)],
|
|
42
|
+
[CGPoint(x: -18.928, y: 25.93), CGPoint(x: -10.022, y: 30.709), CGPoint(x: 0, y: 30.709)],
|
|
43
|
+
[CGPoint(x: 10.022, y: 30.709), CGPoint(x: 18.928, y: 25.93), CGPoint(x: 24.563, y: 18.526)],
|
|
44
|
+
[CGPoint(x: 31.231, y: 9.765), CGPoint(x: 39.749, y: 0), CGPoint(x: notchHalfWidth, y: 0)],
|
|
45
|
+
]
|
|
46
|
+
static let railContainerWidth: CGFloat = 56
|
|
47
|
+
static let railPaddingHorizontal = Spacing.XS
|
|
48
|
+
static let railPaddingBottom = Spacing.S
|
|
49
|
+
static let railItemWidth: CGFloat = 48
|
|
50
|
+
static let railItemHeight: CGFloat = 62
|
|
51
|
+
static let railIndicatorHeight: CGFloat = 40
|
|
52
|
+
static let railIndicatorRadius: CGFloat = 20
|
|
53
|
+
static let railCtaGap = Spacing.L
|
|
54
|
+
static let railCtaSize: CGFloat = 52
|
|
55
|
+
static let railCtaLabelGap = Spacing.XS
|
|
56
|
+
static let railCtaWidth: CGFloat = 68
|
|
57
|
+
static let railCtaHeight: CGFloat = 70
|
|
58
|
+
static let badgeMaxWidth: CGFloat = 58
|
|
59
|
+
|
|
60
|
+
// motion (MoMo Navigation Prototype): one active indicator slides to the selected item overshooting
|
|
61
|
+
// a little, icon and label tint cross-fade, the center action shrinks while held
|
|
62
|
+
static let indicatorMotion = Animation.timingCurve(0.34, 1.4, 0.5, 1, duration: 0.55)
|
|
63
|
+
static let tintMotion = Animation.easeInOut(duration: 0.25)
|
|
64
|
+
static let ctaPressMotion = Animation.easeOut(duration: 0.15)
|
|
65
|
+
static let ctaPressedScale: CGFloat = 0.92
|
|
66
|
+
|
|
67
|
+
/// Width of the horizontal bar: 65% of the short side on an unfolded foldable, otherwise the window
|
|
68
|
+
/// minus the side safe areas and margins.
|
|
69
|
+
static func horizontalBarWidth(_ layout: ScreenLayout) -> CGFloat {
|
|
70
|
+
let shortSide = min(layout.width, layout.height)
|
|
71
|
+
if shortSide >= foldableMinShortSide { return shortSide * foldableWidthRatio }
|
|
72
|
+
return layout.width - layout.insets.leading - layout.insets.trailing - 2 * margin
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// Gap under the container: the home indicator area.
|
|
76
|
+
static func bottomGap(_ bottomInset: CGFloat) -> CGFloat {
|
|
77
|
+
max(min(bottomInset, systemIndicatorHeight), Spacing.S)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/// The center action needs a tab on each side: Special type takes 2 or 4 tabs.
|
|
81
|
+
static func hasCenterAction(_ floatingButton: BottomTabFloatingButton?, tabCount: Int) -> Bool {
|
|
82
|
+
floatingButton != nil && tabCount % 2 == 0
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -90,6 +90,27 @@ private let duoGradientExtra: CGFloat = 52
|
|
|
90
90
|
// scroll distance over which the extended gradient collapses to the header
|
|
91
91
|
private let duoExtendedCollapseDistance: CGFloat = 100
|
|
92
92
|
|
|
93
|
+
// scroll distance over which the bar fades in
|
|
94
|
+
private let duoBarFadeDistance: CGFloat = 16
|
|
95
|
+
|
|
96
|
+
/// Port of RN `DuoGlassBackground`: translucent surface with a hairline, shown once the content
|
|
97
|
+
/// scrolls `fadeStart` under the header.
|
|
98
|
+
struct DuoHeaderBar: View {
|
|
99
|
+
let scrollOffset: CGFloat
|
|
100
|
+
var fadeStart: CGFloat = 0
|
|
101
|
+
|
|
102
|
+
@Environment(\.appTheme) private var theme
|
|
103
|
+
|
|
104
|
+
var body: some View {
|
|
105
|
+
theme.colors.background.surface.opacity(0.8)
|
|
106
|
+
.overlay(alignment: .bottom) {
|
|
107
|
+
theme.colors.border.default.frame(height: 0.5)
|
|
108
|
+
}
|
|
109
|
+
.opacity(min(max((scrollOffset - fadeStart) / duoBarFadeDistance, 0), 1))
|
|
110
|
+
.allowsHitTesting(false)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
93
114
|
/// Port of RN `DuoScrollGradient`: with the glass header the content scrolls under the bar, so the
|
|
94
115
|
/// header gradient is drawn under it. Compose draws this inside `HeaderBackground`.
|
|
95
116
|
struct DuoScrollGradient: View {
|
|
@@ -114,7 +135,7 @@ struct DuoScrollGradient: View {
|
|
|
114
135
|
let progress = min(scroll / duoExtendedCollapseDistance, 1)
|
|
115
136
|
gradient
|
|
116
137
|
.frame(height: headerHeight + (extended ? duoGradientExtra * (1 - progress) : 0))
|
|
117
|
-
.opacity(1 - min(scroll / duoGradientExtra, 1))
|
|
138
|
+
.opacity(Double(1 - min(scroll / duoGradientExtra, 1)))
|
|
118
139
|
}
|
|
119
140
|
}
|
|
120
141
|
.frame(maxWidth: .infinity, maxHeight: .infinity, 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: 65, height: 28)
|
|
362
|
+
.frame(width: usesHelpCenter(context) ? 65 : 28, height: 28)
|
|
363
363
|
.background(headerColor.backgroundButton)
|
|
364
364
|
.cornerRadius(14)
|
|
365
365
|
.overlay(RoundedRectangle(cornerRadius: 14).stroke(headerColor.borderColor, lineWidth: 0.2))
|
|
@@ -57,6 +57,7 @@ struct SnackBarView: View {
|
|
|
57
57
|
let bottomInset: CGFloat
|
|
58
58
|
|
|
59
59
|
@EnvironmentObject private var navigator: Navigator
|
|
60
|
+
@Environment(\.screenLayout) private var layout
|
|
60
61
|
|
|
61
62
|
@State private var contentHeight: CGFloat = 0
|
|
62
63
|
@State private var offsetY: CGFloat = 0
|
|
@@ -75,6 +76,9 @@ struct SnackBarView: View {
|
|
|
75
76
|
)
|
|
76
77
|
.offset(y: offsetY)
|
|
77
78
|
.padding(.bottom, bottomInset)
|
|
79
|
+
// iPhone Duo: clear of the side toolbar strip, like the screen content (0 elsewhere)
|
|
80
|
+
.padding(.leading, layout.insetLeft)
|
|
81
|
+
.padding(.trailing, layout.insetRight)
|
|
78
82
|
}
|
|
79
83
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
80
84
|
.ignoresSafeArea()
|