@momo-kits/native-kits 0.168.1-beta.30 → 0.168.1-beta.31-debug
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +2 -1
- package/build.gradle.kts +11 -0
- package/compose/build.gradle.kts +198 -0
- package/compose/build.gradle.kts.backup +198 -0
- package/compose/compose.podspec +47 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +20 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +153 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +18 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1071 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +357 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +189 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +478 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +265 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +235 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +223 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +265 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +370 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +308 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +330 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +207 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +92 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +560 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +125 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +501 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +236 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +17 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +287 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +321 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +502 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +148 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +116 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +205 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +422 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +732 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +232 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +237 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +97 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +380 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +436 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +455 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +399 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +192 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +91 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +74 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +21 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +218 -0
- 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 +138 -0
- package/gradle/libs.versions.toml +69 -0
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/gradle.properties +26 -0
- package/gradlew +252 -0
- package/gradlew.bat +94 -0
- package/ios/Input/Input.swift +3 -1
- package/ios/Input/InputTextArea.swift +3 -1
- package/ios/Navigation/BottomTab/BottomTab.swift +33 -14
- package/ios/Navigation/BottomTab/BottomTabBar.swift +131 -254
- package/ios/Navigation/BottomTab/CurvedContainer.swift +47 -51
- package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +364 -0
- package/ios/Navigation/BottomTab/DuoTabBar.swift +292 -71
- package/ios/Navigation/StackScreen.swift +1 -3
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/ios-demo/README.md +120 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +59 -224
- package/package.json +1 -1
- package/settings.gradle.kts +64 -0
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +0 -88
|
@@ -16,6 +16,7 @@ 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)?
|
|
19
20
|
|
|
20
21
|
@EnvironmentObject private var navigator: Navigator
|
|
21
22
|
/// The screen hosting the tabs (Compose's `LocalNavigation` in BottomTab).
|
|
@@ -34,28 +35,32 @@ public struct BottomTab: View {
|
|
|
34
35
|
/// starts compressed; tapping the compressed one swaps them.
|
|
35
36
|
/// `onTabPress` gets every tab press with the switch to perform, e.g. after a login gate.
|
|
36
37
|
/// `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.
|
|
37
39
|
public init(
|
|
38
40
|
items: [BottomTabItem],
|
|
39
41
|
floatingButton: BottomTabFloatingButton? = nil,
|
|
40
42
|
compressionBehavior: DuoBarCompressionBehavior = .toolbar,
|
|
41
43
|
initialRouteName: String? = nil,
|
|
42
44
|
onTabPress: ((_ index: Int, _ switchTab: @escaping () -> Void) -> Void)? = nil,
|
|
43
|
-
backToInitialTab: Bool = true
|
|
45
|
+
backToInitialTab: Bool = true,
|
|
46
|
+
onTabLongPress: ((_ index: Int) -> Void)? = nil
|
|
44
47
|
) {
|
|
45
48
|
self.items = items
|
|
46
49
|
self.floatingButton = floatingButton
|
|
47
50
|
self.compressionBehavior = compressionBehavior
|
|
48
51
|
self.onTabPress = onTabPress
|
|
49
52
|
self.backToInitialTab = backToInitialTab
|
|
53
|
+
self.onTabLongPress = onTabLongPress
|
|
50
54
|
let start = items.firstIndex { $0.name == initialRouteName } ?? 0
|
|
51
55
|
_startIndex = State(initialValue: start)
|
|
52
56
|
_selectedIndex = State(initialValue: start)
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
private var bottomInset: CGFloat { safeAreaBottomInset() }
|
|
56
|
-
// the bars
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
// the Duo bars overlay the content or sit in the side strip, so only the home indicator is kept clear
|
|
61
|
+
private var reservedBottom: CGFloat {
|
|
62
|
+
layout.isIPhoneDuo ? layout.insets.bottom : BOTTOM_TAB_BAR_HEIGHT + bottomInset + Spacing.S
|
|
63
|
+
}
|
|
59
64
|
|
|
60
65
|
private var compression: DuoBarCompression {
|
|
61
66
|
DuoBarCompression.resolve(
|
|
@@ -100,16 +105,30 @@ public struct BottomTab: View {
|
|
|
100
105
|
floatingButton: floatingButton,
|
|
101
106
|
selectedIndex: selectedIndex,
|
|
102
107
|
onTabSelected: selectTab,
|
|
103
|
-
compression: compression
|
|
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
|
+
}
|
|
104
117
|
)
|
|
105
118
|
} else {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
119
|
+
// Tab bar + home-indicator filler.
|
|
120
|
+
VStack(spacing: 0) {
|
|
121
|
+
BottomTabBar(
|
|
122
|
+
items: items,
|
|
123
|
+
floatingButton: floatingButton,
|
|
124
|
+
selectedIndex: selectedIndex,
|
|
125
|
+
onTabSelected: selectTab,
|
|
126
|
+
onTabLongPress: onTabLongPress
|
|
127
|
+
)
|
|
128
|
+
theme.colors.background.surface
|
|
129
|
+
.frame(height: bottomInset + Spacing.S)
|
|
130
|
+
.ignoresSafeArea(edges: .horizontal)
|
|
131
|
+
}
|
|
113
132
|
}
|
|
114
133
|
}
|
|
115
134
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
@@ -131,7 +150,6 @@ public struct BottomTab: View {
|
|
|
131
150
|
}
|
|
132
151
|
|
|
133
152
|
private func selectTab(_ index: Int) {
|
|
134
|
-
navigator.maxApi?.triggerEventVibration("light")
|
|
135
153
|
let switchTab = { if index != selectedIndex { selectedIndex = index } }
|
|
136
154
|
if let onTabPress { onTabPress(index, switchTab) } else { switchTab() }
|
|
137
155
|
}
|
|
@@ -320,7 +338,8 @@ private struct TabCard: View {
|
|
|
320
338
|
|
|
321
339
|
/// Bottom safe-area inset (home indicator).
|
|
322
340
|
private func safeAreaBottomInset() -> CGFloat {
|
|
323
|
-
UIApplication.shared.connectedScenes
|
|
341
|
+
let bottomInset = UIApplication.shared.connectedScenes
|
|
324
342
|
.compactMap { ($0 as? UIWindowScene)?.keyWindow?.safeAreaInsets.bottom }
|
|
325
343
|
.first ?? 0
|
|
344
|
+
return min(bottomInset, 21)
|
|
326
345
|
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// MoMoUIKits
|
|
4
4
|
//
|
|
5
5
|
// SwiftUI mirror of Compose's `navigation/bottomtab/BottomTabBar.kt`.
|
|
6
|
-
//
|
|
7
|
-
//
|
|
6
|
+
// Renders the row of tab items, an animated selection indicator, a top shadow,
|
|
7
|
+
// badges/dots, and an optional center floating button (with the curved notch).
|
|
8
8
|
//
|
|
9
9
|
|
|
10
10
|
import SwiftUI
|
|
@@ -57,311 +57,188 @@ public struct BottomTabFloatingButton {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
let
|
|
60
|
+
let bottomTabFloatingButtonWidth: CGFloat = 75
|
|
61
|
+
let BOTTOM_TAB_BAR_HEIGHT: CGFloat = 64
|
|
61
62
|
|
|
62
63
|
// MARK: - Tab bar
|
|
63
64
|
|
|
64
|
-
/// Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
|
|
65
65
|
struct BottomTabBar: View {
|
|
66
66
|
let items: [BottomTabItem]
|
|
67
67
|
let floatingButton: BottomTabFloatingButton?
|
|
68
68
|
let selectedIndex: Int
|
|
69
69
|
let onTabSelected: (Int) -> Void
|
|
70
|
-
|
|
70
|
+
var onTabLongPress: ((Int) -> Void)?
|
|
71
71
|
|
|
72
72
|
@Environment(\.screenLayout) private var layout
|
|
73
|
+
@Environment(\.appTheme) private var theme
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
floatingButton: floatingButton,
|
|
78
|
-
selectedIndex: selectedIndex,
|
|
79
|
-
onTabSelected: onTabSelected,
|
|
80
|
-
width: TabBarMetrics.horizontalBarWidth(layout)
|
|
81
|
-
)
|
|
82
|
-
.padding(.bottom, TabBarMetrics.bottomGap(bottomInset))
|
|
83
|
-
.frame(maxWidth: .infinity)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/// Horizontal navigation bar: floating container, items split evenly; Special type puts the center
|
|
88
|
-
/// action in a notch in the middle, rising ctaLift above the container. One active indicator slides
|
|
89
|
-
/// behind the selected item.
|
|
90
|
-
struct HorizontalTabBar: View {
|
|
91
|
-
let items: [BottomTabItem]
|
|
92
|
-
let floatingButton: BottomTabFloatingButton?
|
|
93
|
-
let selectedIndex: Int
|
|
94
|
-
let onTabSelected: (Int) -> Void
|
|
95
|
-
let width: CGFloat
|
|
96
|
-
var fixedFontScale = false
|
|
75
|
+
// the bar sits between the side safe areas
|
|
76
|
+
private var screenWidth: CGFloat { layout.width - layout.insets.leading - layout.insets.trailing }
|
|
77
|
+
private var mid: Int { items.count / 2 }
|
|
97
78
|
|
|
98
|
-
private var
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
private var itemWidth: CGFloat {
|
|
104
|
-
let slots = CGFloat(items.count + (cta == nil ? 0 : 1))
|
|
105
|
-
let content = width - 2 * TabBarMetrics.paddingHorizontal - (slots - 1) * TabBarMetrics.itemGap
|
|
106
|
-
return max((content - (cta == nil ? 0 : TabBarMetrics.ctaSlotWidth)) / CGFloat(max(items.count, 1)), 0)
|
|
79
|
+
private var tabWidth: CGFloat {
|
|
80
|
+
if floatingButton != nil {
|
|
81
|
+
return (screenWidth - bottomTabFloatingButtonWidth) / CGFloat(items.count)
|
|
82
|
+
}
|
|
83
|
+
return screenWidth / CGFloat(items.count)
|
|
107
84
|
}
|
|
108
85
|
|
|
109
|
-
private
|
|
110
|
-
let
|
|
111
|
-
return
|
|
112
|
-
+ (afterCta ? TabBarMetrics.ctaSlotWidth + TabBarMetrics.itemGap : 0)
|
|
86
|
+
private var indicatorOffset: CGFloat {
|
|
87
|
+
let adjust: CGFloat = (floatingButton != nil && selectedIndex >= mid) ? bottomTabFloatingButtonWidth : 0
|
|
88
|
+
return tabWidth * CGFloat(selectedIndex) + tabWidth / 2 - screenWidth / 2 + adjust
|
|
113
89
|
}
|
|
114
90
|
|
|
115
91
|
var body: some View {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if cta != nil && index == items.count / 2 {
|
|
127
|
-
Color.clear.frame(width: TabBarMetrics.ctaSlotWidth)
|
|
128
|
-
}
|
|
129
|
-
SwiftUI.Button { onTabSelected(index) } label: {
|
|
130
|
-
VStack(spacing: Spacing.XXS) {
|
|
131
|
-
TabItemContent(item: items[index], selected: index == selectedIndex, fixedFontScale: fixedFontScale)
|
|
132
|
-
}
|
|
133
|
-
.frame(width: itemWidth)
|
|
134
|
-
.contentShape(Rectangle())
|
|
135
|
-
}
|
|
136
|
-
.buttonStyle(.plain)
|
|
137
|
-
.accessibilityLabel(items[index].label)
|
|
138
|
-
.accessibilityAddTraits(index == selectedIndex ? .isSelected : [])
|
|
139
|
-
}
|
|
92
|
+
ZStack(alignment: .bottom) {
|
|
93
|
+
HStack(spacing: 0) {
|
|
94
|
+
if floatingButton == nil {
|
|
95
|
+
tabItems(from: 0, to: items.count)
|
|
96
|
+
} else {
|
|
97
|
+
tabItems(from: 0, to: mid)
|
|
98
|
+
Spacer()
|
|
99
|
+
.frame(width: bottomTabFloatingButtonWidth)
|
|
100
|
+
.padding(.horizontal, Spacing.XXS)
|
|
101
|
+
tabItems(from: mid, to: items.count)
|
|
140
102
|
}
|
|
141
|
-
.padding(.horizontal, TabBarMetrics.paddingHorizontal)
|
|
142
|
-
.padding(.vertical, TabBarMetrics.paddingVertical)
|
|
143
103
|
}
|
|
144
|
-
.frame(
|
|
145
|
-
.
|
|
146
|
-
.
|
|
147
|
-
|
|
148
|
-
|
|
104
|
+
.frame(maxWidth: .infinity)
|
|
105
|
+
.frame(height: BOTTOM_TAB_BAR_HEIGHT)
|
|
106
|
+
.background(theme.colors.background.surface.ignoresSafeArea(edges: .horizontal))
|
|
107
|
+
|
|
108
|
+
// Animated selection indicator.
|
|
109
|
+
RoundedRectangle(cornerRadius: 2)
|
|
110
|
+
.fill(theme.colors.primary)
|
|
111
|
+
.frame(width: 44, height: 2)
|
|
112
|
+
.offset(x: indicatorOffset, y: -BOTTOM_TAB_BAR_HEIGHT + 2)
|
|
113
|
+
.animation(.easeInOut(duration: 0.25), value: selectedIndex)
|
|
114
|
+
|
|
115
|
+
// Top shadow.
|
|
116
|
+
LinearGradient(
|
|
117
|
+
colors: [Color.black.opacity(0.05), .clear],
|
|
118
|
+
startPoint: .bottom,
|
|
119
|
+
endPoint: .top
|
|
120
|
+
)
|
|
121
|
+
.frame(height: 6)
|
|
122
|
+
.frame(maxWidth: .infinity)
|
|
123
|
+
.offset(y: -BOTTOM_TAB_BAR_HEIGHT)
|
|
149
124
|
|
|
150
|
-
if let
|
|
151
|
-
|
|
125
|
+
if let floatingButton {
|
|
126
|
+
CenterFloatingButton(data: floatingButton)
|
|
152
127
|
}
|
|
153
128
|
}
|
|
154
|
-
.frame(width: width)
|
|
155
129
|
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/// One active indicator per bar: Background/tonal with its inner light (white 12% from below) and
|
|
159
|
-
/// tint (primary 12% from above).
|
|
160
|
-
struct ActiveIndicator: View {
|
|
161
|
-
let radius: CGFloat
|
|
162
|
-
|
|
163
|
-
@Environment(\.appTheme) private var theme
|
|
164
130
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
.init(color: Color.white.opacity(0), location: 0.85),
|
|
176
|
-
.init(color: Color.white.opacity(0.12), location: 1),
|
|
177
|
-
],
|
|
178
|
-
startPoint: .top,
|
|
179
|
-
endPoint: .bottom
|
|
180
|
-
)
|
|
181
|
-
.clipShape(shape)
|
|
131
|
+
@ViewBuilder
|
|
132
|
+
private func tabItems(from: Int, to: Int) -> some View {
|
|
133
|
+
ForEach(from..<to, id: \.self) { index in
|
|
134
|
+
TabBarItem(
|
|
135
|
+
item: items[index],
|
|
136
|
+
selected: index == selectedIndex,
|
|
137
|
+
// from the icon's center to the cell's end edge, inside both XXS paddings
|
|
138
|
+
badgeMaxWidth: tabWidth / 2 - Spacing.XXS * 2,
|
|
139
|
+
onClick: { onTabSelected(index) },
|
|
140
|
+
onLongClick: onTabLongPress.map { callback in { callback(index) } }
|
|
182
141
|
)
|
|
183
|
-
.
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/// Like the system tab bar, text keeps its design size instead of growing with the wide Duo displays.
|
|
188
|
-
struct FixedFontScale: ViewModifier {
|
|
189
|
-
let enabled: Bool
|
|
190
|
-
|
|
191
|
-
@Environment(\.momoFontScale) private var fontScale
|
|
192
|
-
|
|
193
|
-
func body(content: Content) -> some View {
|
|
194
|
-
content.environment(\.momoFontScale, enabled ? FontScale(userScaleRate: 1, useOSScaleRate: false) : fontScale)
|
|
142
|
+
.frame(maxWidth: .infinity)
|
|
143
|
+
}
|
|
195
144
|
}
|
|
196
145
|
}
|
|
197
146
|
|
|
198
147
|
// MARK: - Tab item
|
|
199
148
|
|
|
200
|
-
|
|
201
|
-
/// slots; the icon and label tint cross-fade on focus.
|
|
202
|
-
struct TabItemContent: View {
|
|
149
|
+
private struct TabBarItem: View {
|
|
203
150
|
let item: BottomTabItem
|
|
204
151
|
let selected: Bool
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
152
|
+
let badgeMaxWidth: CGFloat
|
|
153
|
+
let onClick: () -> Void
|
|
154
|
+
let onLongClick: (() -> Void)?
|
|
208
155
|
|
|
209
156
|
@Environment(\.appTheme) private var theme
|
|
210
157
|
|
|
211
|
-
var
|
|
212
|
-
TabIcon(item: item, selected: selected, vertical: vertical)
|
|
213
|
-
.frame(height: vertical ? TabBarMetrics.railIndicatorHeight : TabBarMetrics.indicatorHeight)
|
|
214
|
-
if showLabel {
|
|
215
|
-
let label = ZStack {
|
|
216
|
-
labelText(theme.colors.text.secondary).opacity(selected ? 0 : 1)
|
|
217
|
-
labelText(theme.colors.primary).opacity(selected ? 1 : 0)
|
|
218
|
-
}
|
|
219
|
-
.animation(TabBarMetrics.tintMotion, value: selected)
|
|
220
|
-
.frame(maxWidth: vertical ? nil : .infinity)
|
|
221
|
-
label.modifier(FixedFontScale(enabled: fixedFontScale))
|
|
222
|
-
}
|
|
223
|
-
}
|
|
158
|
+
private var tintColor: Color { selected ? theme.colors.primary : theme.colors.text.hint }
|
|
224
159
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
textAlign: .center,
|
|
231
|
-
maxLines: 1
|
|
232
|
-
)
|
|
233
|
-
.truncationMode(.tail)
|
|
160
|
+
/// Mirrors Compose's `formatLabel`: hide a badge that is the number "0".
|
|
161
|
+
private var badgeLabel: String? {
|
|
162
|
+
guard let label = item.badgeLabel else { return nil }
|
|
163
|
+
if let n = Int(label), n == 0 { return nil }
|
|
164
|
+
return label
|
|
234
165
|
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/// Badge value shown on a tab: nil hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity).
|
|
238
|
-
func tabBadgeLabel(_ item: BottomTabItem) -> String? {
|
|
239
|
-
guard let label = item.badgeLabel else { return item.showDot ? "" : nil }
|
|
240
|
-
if label.isEmpty { return "" }
|
|
241
|
-
if label.allSatisfy({ ("0"..."9").contains($0) }) {
|
|
242
|
-
let value = Int(label) ?? Int.max
|
|
243
|
-
if value == 0 { return item.showDot ? "" : nil }
|
|
244
|
-
return value > 99 ? "99+" : label
|
|
245
|
-
}
|
|
246
|
-
return label
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/// 24 icon, active and inactive tints cross-faded; badges hang off it: dot at 16/-2, label badge at
|
|
250
|
-
/// 12/-7 growing right, or centered over the icon at -10 on the rail.
|
|
251
|
-
struct TabIcon: View {
|
|
252
|
-
let item: BottomTabItem
|
|
253
|
-
let selected: Bool
|
|
254
|
-
var vertical = false
|
|
255
|
-
|
|
256
|
-
@Environment(\.appTheme) private var theme
|
|
257
166
|
|
|
258
167
|
var body: some View {
|
|
259
|
-
|
|
260
|
-
Icon(source: item.icon, size:
|
|
261
|
-
.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if let badge = tabBadgeLabel(item) {
|
|
269
|
-
if badge.isEmpty {
|
|
270
|
-
BadgeDot(size: .small)
|
|
271
|
-
.offset(x: vertical ? 16 - (TabBarMetrics.iconSize - 10) / 2 : 16, y: -Spacing.XXS)
|
|
272
|
-
} else {
|
|
273
|
-
TabBadge(label: badge)
|
|
274
|
-
.fixedSize()
|
|
275
|
-
.frame(width: TabBarMetrics.badgeMaxWidth, alignment: vertical ? .center : .leading)
|
|
276
|
-
.offset(x: vertical ? 0 : Spacing.M, y: vertical ? -10 : -7)
|
|
168
|
+
VStack(spacing: 0) {
|
|
169
|
+
Icon(source: item.icon, size: 28, color: tintColor)
|
|
170
|
+
.overlay(alignment: .topLeading) {
|
|
171
|
+
// starts at the icon's center and grows toward the cell's end edge, ellipsized past it
|
|
172
|
+
if let badgeLabel, !badgeLabel.isEmpty {
|
|
173
|
+
Badge(label: badgeLabel)
|
|
174
|
+
.frame(width: max(badgeMaxWidth, 0), alignment: .leading)
|
|
175
|
+
.offset(x: 14, y: -Spacing.S)
|
|
176
|
+
}
|
|
277
177
|
}
|
|
278
|
-
|
|
178
|
+
.overlay(alignment: .topTrailing) {
|
|
179
|
+
if badgeLabel?.isEmpty == true || (badgeLabel == nil && item.showDot) {
|
|
180
|
+
BadgeDot(size: .small).offset(x: 4, y: -4)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
.padding(Spacing.XS)
|
|
184
|
+
MomoText(
|
|
185
|
+
item.label,
|
|
186
|
+
typography: selected ? .labelXsMedium : .descriptionXsRegular,
|
|
187
|
+
color: tintColor,
|
|
188
|
+
textAlign: .center,
|
|
189
|
+
maxLines: 1
|
|
190
|
+
)
|
|
191
|
+
.truncationMode(.tail)
|
|
279
192
|
}
|
|
193
|
+
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
194
|
+
.padding(.horizontal, Spacing.S)
|
|
195
|
+
.padding(.vertical, Spacing.S)
|
|
196
|
+
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
197
|
+
.padding(.horizontal, Spacing.XXS)
|
|
198
|
+
.contentShape(Rectangle())
|
|
199
|
+
.onTapGesture { onClick() }
|
|
200
|
+
.modifier(TabLongPress(action: onLongClick))
|
|
280
201
|
}
|
|
281
202
|
}
|
|
282
203
|
|
|
283
|
-
///
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
let label: String
|
|
287
|
-
|
|
288
|
-
@Environment(\.appTheme) private var theme
|
|
289
|
-
|
|
290
|
-
private var isNumber: Bool {
|
|
291
|
-
let digits = label.hasSuffix("+") ? String(label.dropLast()) : label
|
|
292
|
-
return !digits.isEmpty && digits.allSatisfy { ("0"..."9").contains($0) }
|
|
293
|
-
}
|
|
204
|
+
/// Only attached with a callback, so a held tab without one still selects on release.
|
|
205
|
+
private struct TabLongPress: ViewModifier {
|
|
206
|
+
let action: (() -> Void)?
|
|
294
207
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
.
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
.background(Capsule().fill(isNumber ? theme.colors.error.primary : theme.colors.warning.primary))
|
|
302
|
-
.overlay(Capsule().strokeBorder(theme.colors.background.surface, lineWidth: 1))
|
|
208
|
+
func body(content: Content) -> some View {
|
|
209
|
+
if let action {
|
|
210
|
+
content.onLongPressGesture(minimumDuration: 0.5, perform: action)
|
|
211
|
+
} else {
|
|
212
|
+
content
|
|
213
|
+
}
|
|
303
214
|
}
|
|
304
215
|
}
|
|
305
216
|
|
|
306
|
-
// MARK: - Center
|
|
217
|
+
// MARK: - Center floating button
|
|
307
218
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
struct CenterActionStyle: ButtonStyle {
|
|
311
|
-
let size: CGFloat
|
|
312
|
-
let vertical: Bool
|
|
313
|
-
let icon: String
|
|
314
|
-
let label: String
|
|
315
|
-
var fixedFontScale = false
|
|
219
|
+
private struct CenterFloatingButton: View {
|
|
220
|
+
let data: BottomTabFloatingButton
|
|
316
221
|
|
|
317
222
|
@Environment(\.appTheme) private var theme
|
|
318
223
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
.frame(width: size, height: size)
|
|
333
|
-
.scaleEffect(pressed ? TabBarMetrics.ctaPressedScale : 1)
|
|
334
|
-
.animation(TabBarMetrics.ctaPressMotion, value: pressed)
|
|
335
|
-
MomoText(
|
|
336
|
-
label,
|
|
337
|
-
typography: vertical ? .labelXsMedium : .labelSMedium,
|
|
338
|
-
color: pressed ? Colors.black01 : theme.colors.text.secondary,
|
|
339
|
-
textAlign: .center,
|
|
340
|
-
maxLines: 1
|
|
341
|
-
)
|
|
342
|
-
.truncationMode(.tail)
|
|
343
|
-
.modifier(FixedFontScale(enabled: fixedFontScale))
|
|
344
|
-
.padding(.horizontal, vertical ? Spacing.XS : Spacing.XXS)
|
|
345
|
-
.frame(minHeight: vertical ? nil : TabBarMetrics.ctaLabelHeight)
|
|
346
|
-
.background(Capsule().fill(pressed ? theme.colors.primary : Color.clear))
|
|
224
|
+
var body: some View {
|
|
225
|
+
VStack(spacing: 0) {
|
|
226
|
+
CurvedContainer()
|
|
227
|
+
Circle()
|
|
228
|
+
.fill(theme.colors.primary)
|
|
229
|
+
.frame(width: 48, height: 48)
|
|
230
|
+
.overlay(Icon(source: data.icon, size: 28, color: .white))
|
|
231
|
+
Spacer().frame(height: 4)
|
|
232
|
+
MomoText(data.label, typography: .labelXsMedium, color: Colors.black01, textAlign: .center, maxLines: 1)
|
|
233
|
+
.frame(maxWidth: .infinity)
|
|
234
|
+
.frame(height: 14)
|
|
235
|
+
.background(theme.colors.primary)
|
|
236
|
+
.clipShape(RoundedRectangle(cornerRadius: Radius.XL))
|
|
347
237
|
}
|
|
348
|
-
|
|
349
|
-
.
|
|
238
|
+
.frame(width: bottomTabFloatingButtonWidth)
|
|
239
|
+
.padding(.horizontal, Spacing.XXS)
|
|
240
|
+
.padding(.vertical, Spacing.S)
|
|
350
241
|
.contentShape(Rectangle())
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/// Center action (.Nav/CTA): button rising out of the notch, label under it.
|
|
355
|
-
private struct CenterAction: View {
|
|
356
|
-
let data: BottomTabFloatingButton
|
|
357
|
-
var fixedFontScale = false
|
|
358
|
-
|
|
359
|
-
var body: some View {
|
|
360
|
-
SwiftUI.Button(action: data.onPress) { EmptyView() }
|
|
361
|
-
.buttonStyle(CenterActionStyle(size: TabBarMetrics.ctaSize, vertical: false, icon: data.icon,
|
|
362
|
-
label: data.label, fixedFontScale: fixedFontScale))
|
|
363
|
-
.frame(width: TabBarMetrics.ctaSlotWidth, height: TabBarMetrics.ctaSize + TabBarMetrics.ctaLabelGap + TabBarMetrics.ctaLabelHeight)
|
|
364
|
-
.accessibilityLabel(data.label)
|
|
365
|
-
.accessibilityIdentifier(data.label)
|
|
242
|
+
.onTapGesture { data.onPress() }
|
|
366
243
|
}
|
|
367
244
|
}
|