@momo-kits/native-kits 0.300.7-debug → 0.300.8-beta.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.
Files changed (202) hide show
  1. package/CLAUDE.md +12 -8
  2. package/README.md +8 -7
  3. package/compose/build.gradle.kts +2 -4
  4. package/compose/build.gradle.kts.backup +1 -3
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +1 -2
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +1 -1
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +2 -3
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/application/KitsBinding.kt +60 -0
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/KitsHost.kt +32 -0
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +20 -24
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +5 -6
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +7 -17
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +18 -18
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +2 -2
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +15 -18
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +4 -2
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +13 -73
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +1 -1
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +1 -8
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +1 -53
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +3 -8
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +2 -3
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +12 -15
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +11 -9
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +17 -12
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +20 -5
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +3 -5
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +7 -8
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +1 -2
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -2
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +1 -2
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +83 -82
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +3 -3
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +6 -10
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +9 -9
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -2
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +13 -35
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +2 -4
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +5 -22
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -2
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -3
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +6 -24
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +55 -5
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +1 -7
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +3 -6
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +1 -1
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +22 -50
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +2 -7
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +11 -7
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +71 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +184 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +18 -9
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +5 -3
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +123 -64
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +24 -8
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +11 -9
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +16 -19
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +59 -41
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +69 -51
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +14 -10
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +5 -10
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +43 -32
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +330 -149
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +87 -70
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +1 -5
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +92 -261
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +133 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -2
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +31 -40
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +3 -1
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +46 -72
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +8 -12
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +29 -24
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +8 -11
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +9 -9
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +26 -3
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +1 -3
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +4 -3
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +2 -3
  84. package/compose/src/commonTest/kotlin/vn/momo/kits/application/KitsHostTest.kt +44 -0
  85. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +2 -7
  86. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +9 -18
  87. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +1 -1
  88. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +3 -6
  89. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +5 -6
  90. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +12 -12
  91. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  92. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +11 -6
  93. package/gradle/libs.versions.toml +1 -3
  94. package/gradle.properties +1 -3
  95. package/ios/Application/ApplicationEnvironment.swift +6 -4
  96. package/ios/Application/DesignSystemKits.swift +59 -13
  97. package/ios/Application/DesignSystemKitsPayload.swift +0 -8
  98. package/ios/Application/LanguageSource.swift +2 -11
  99. package/ios/Application/Localize.swift +8 -35
  100. package/ios/Application/LocalizeModifier.swift +2 -11
  101. package/ios/Application/MaxApi.swift +3 -11
  102. package/ios/Avatar/Avatar.swift +0 -1
  103. package/ios/Badge/Badge.swift +5 -8
  104. package/ios/Badge/BadgeRibbon.swift +2 -5
  105. package/ios/Button/Button.swift +4 -8
  106. package/ios/CalculatorKeyboard/CalculatorKeyboard.swift +5 -7
  107. package/ios/Carousel/Carousel.swift +4 -17
  108. package/ios/Checkbox/Checkbox.swift +0 -2
  109. package/ios/Collapse/Collapse.swift +17 -11
  110. package/ios/Colors+Radius+Spacing/Theme.swift +0 -7
  111. package/ios/DateTimePicker/DateTimePicker.swift +4 -10
  112. package/ios/DateTimePicker/DateTimePickerTypes.swift +1 -3
  113. package/ios/DateTimePicker/DateTimePickerUtils.swift +0 -3
  114. package/ios/DateTimePicker/WheelPicker.swift +2 -4
  115. package/ios/Extensions/ActiveOpacityButtonStyle.swift +2 -3
  116. package/ios/Extensions/Color++.swift +2 -4
  117. package/ios/Extensions/SkeletonUICompat.swift +0 -8
  118. package/ios/Icon/Icon.swift +3 -6
  119. package/ios/IconButton/IconButton.swift +2 -5
  120. package/ios/Input/ErrorView.swift +0 -7
  121. package/ios/Input/Input.swift +9 -20
  122. package/ios/Input/InputPhoneNumber.swift +37 -20
  123. package/ios/Input/InputSearch.swift +23 -12
  124. package/ios/Input/InputTextArea.swift +4 -13
  125. package/ios/InputDropDown/InputDropDown.swift +1 -11
  126. package/ios/InputMoney/InputMoney.swift +9 -28
  127. package/ios/InputOTP/InputOTP.swift +2 -9
  128. package/ios/Layout/HeaderLayout.swift +72 -0
  129. package/ios/Layout/Item.swift +1 -2
  130. package/ios/Layout/ModalLayout.swift +144 -0
  131. package/ios/Layout/ScreenLayout.swift +48 -31
  132. package/ios/Layout/Section.swift +2 -3
  133. package/ios/Loader/Loader.swift +3 -12
  134. package/ios/Lottie/LottieView.swift +0 -11
  135. package/ios/Navigation/BottomSheet.swift +73 -94
  136. package/ios/Navigation/BottomTab/BottomTab.swift +58 -73
  137. package/ios/Navigation/BottomTab/BottomTabBar.swift +286 -121
  138. package/ios/Navigation/BottomTab/CurvedContainer.swift +52 -54
  139. package/ios/Navigation/BottomTab/DuoBarCompression.swift +5 -12
  140. package/ios/Navigation/BottomTab/DuoTabBar.swift +67 -202
  141. package/ios/Navigation/BottomTab/TabBarMetrics.swift +97 -0
  142. package/ios/Navigation/Component/FloatingButton.swift +4 -11
  143. package/ios/Navigation/Component/Header.swift +35 -54
  144. package/ios/Navigation/Component/HeaderBackground.swift +2 -8
  145. package/ios/Navigation/Component/HeaderJourney.swift +4 -8
  146. package/ios/Navigation/Component/HeaderLocation.swift +4 -8
  147. package/ios/Navigation/Component/HeaderRight.swift +20 -22
  148. package/ios/Navigation/Component/HeaderTitle.swift +1 -6
  149. package/ios/Navigation/Component/HeaderUser.swift +4 -10
  150. package/ios/Navigation/Component/SideBar.swift +6 -21
  151. package/ios/Navigation/Component/SnackBar.swift +9 -13
  152. package/ios/Navigation/HostBackGestureBridge.swift +2 -9
  153. package/ios/Navigation/ModalScreen.swift +24 -13
  154. package/ios/Navigation/Navigation.swift +35 -19
  155. package/ios/Navigation/NavigationContainer.swift +4 -15
  156. package/ios/Navigation/Navigator.swift +21 -39
  157. package/ios/Navigation/StackScreen.swift +64 -51
  158. package/ios/Navigation/StackTransition.swift +7 -14
  159. package/ios/Navigation/SwipeBackHaptic.swift +2 -7
  160. package/ios/Navigation/Tracking/ScreenTracker.swift +2 -7
  161. package/ios/Pagination/PaginationDot.swift +0 -9
  162. package/ios/Pagination/PaginationNumber.swift +1 -9
  163. package/ios/Pagination/PaginationScroll.swift +2 -14
  164. package/ios/Pagination/PaginationWhiteDot.swift +1 -10
  165. package/ios/Popup/PopupDisplay.swift +7 -5
  166. package/ios/Popup/PopupInput.swift +6 -4
  167. package/ios/Popup/PopupLayout.swift +17 -9
  168. package/ios/Popup/PopupNotify.swift +32 -25
  169. package/ios/PopupView/FullscreenPopup.swift +3 -4
  170. package/ios/PopupView/PopupView.swift +2 -2
  171. package/ios/PopupView/Utils++.swift +1 -2
  172. package/ios/ProgressInfo/ProgressInfo.swift +2 -13
  173. package/ios/Skeleton/Skeleton.swift +5 -16
  174. package/ios/Slider/Slider.swift +5 -12
  175. package/ios/StatusBarTap/StatusBarTap.h +2 -3
  176. package/ios/StatusBarTap/StatusBarTap.m +3 -16
  177. package/ios/Stepper/Stepper.swift +8 -27
  178. package/ios/Steps/Steps.swift +29 -26
  179. package/ios/Swipeable/SwipeCell.swift +2 -2
  180. package/ios/Swipeable/SwipeCellModel.swift +3 -6
  181. package/ios/TabView/TabView.swift +14 -28
  182. package/ios/Template/TrustBanner/TrustBanner.swift +2 -9
  183. package/ios/Title/Title.swift +1 -3
  184. package/ios/Tooltip/Tooltip.swift +4 -9
  185. package/ios/Typography/FontScale.swift +79 -24
  186. package/ios/Typography/Text.swift +6 -12
  187. package/ios/Typography/Typography.swift +8 -11
  188. package/ios/Uploader/Uploader.swift +2 -17
  189. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  190. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  191. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/AnimatedHeaderDemo.swift +11 -2
  192. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +296 -59
  193. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputPhoneNumberDemo.swift +15 -4
  194. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/LocalizeDemo.swift +0 -8
  195. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +114 -0
  196. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
  197. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/TypographyDemo.swift +16 -0
  198. package/package.json +1 -1
  199. package/publish.sh +8 -2
  200. package/scripts/ci/build-swiftui.sh +22 -0
  201. package/scripts/ci/resolve-version.mjs +144 -0
  202. package/settings.gradle.kts +0 -1
@@ -2,77 +2,318 @@
2
2
  // BottomTabDemo.swift
3
3
  // Example
4
4
  //
5
- // Usage demo for the bottom-tab navigation. Mirrors Compose's `BottomTabUsage`:
6
- // four tabs (each with its own header title + badge) and a center floating
7
- // button. Must be hosted inside a `NavigationContainer` (uses the Navigator).
5
+ // Usage demo for the bottom-tab navigation, same as RN app/screens/Navigation/BottomTab and
6
+ // Compose's `BottomTabUsage`: the bar shows right away, every tab holds the options and each
7
+ // change rebuilds the bar below. Must be hosted inside a `NavigationContainer`.
8
8
  //
9
9
 
10
+ import Combine
11
+ import Lottie
10
12
  import MoMoUIKits
11
13
  import SwiftUI
12
14
 
13
- @available(iOS 16.0, *)
15
+ private struct TabConfig: Hashable {
16
+ let name: String
17
+ var label: String
18
+ var icon: String
19
+ // nil = no badge, "" = dot, "0" = hidden, numbers > 99 = 99+, text = text badge
20
+ var badgeLabel: String?
21
+ var showDot = false
22
+ }
23
+
24
+ private struct DemoConfig: Hashable {
25
+ var tabs: [TabConfig] = [
26
+ TabConfig(name: "Momo", label: "Momo", icon: "home_momo_active"),
27
+ TabConfig(name: "UuDai", label: "Ưu đãi", icon: "home_promotions_active", badgeLabel: "Mới"),
28
+ TabConfig(name: "GiaoDich", label: "Giao dịch", icon: "home_history_active", badgeLabel: "5"),
29
+ TabConfig(name: "Toi", label: "Tôi", icon: "home_friends_active", badgeLabel: ""),
30
+ TabConfig(name: "Vi", label: "Ví", icon: "home_wallet_inactive", badgeLabel: "1999"),
31
+ ]
32
+ var tabCount = 4
33
+ var longLabels = false
34
+ var special = true
35
+ var ctaLabel = "Quét mọi QR"
36
+ var ctaIcon = "momomain_scan_code"
37
+ // the Home Lottie, split into its button and label parts, instead of icon and label
38
+ var ctaLottie = false
39
+ var initialRouteName = "Momo"
40
+ var compressionBehavior: DuoBarCompressionBehavior = .toolbar
41
+ var backToInitialTab = true
42
+ // a sticky footer in the tab's content body, to check it clears the floating bar
43
+ var footer = false
44
+
45
+ var visibleTabs: [TabConfig] { Array(tabs.prefix(tabCount)) }
46
+ }
47
+
48
+ private let icons = [
49
+ "home_momo_active", "home_promotions_active", "home_history_active", "home_friends_active",
50
+ "home_wallet_inactive", "notifications_bell", "basic_setting",
51
+ ]
52
+ private let ctaIcons = ["momomain_scan_code", "navigation_scan", "navigation_qrcode"]
53
+ // The Home "Quét mọi QR" animation in two files on a 160 canvas: pink circle 100 centered at y 70, label
54
+ // centered at y 138. At 77 the circle is the 48 button; the button part moves down 5 onto the button center,
55
+ // the label part up 28 onto the label line.
56
+ private let ctaLottieSize: CGFloat = 77
57
+ private let ctaLottieButtonOffset: CGFloat = 5
58
+ private let ctaLottieLabelOffset: CGFloat = 28
59
+
60
+ private let ctaLottieButtonURL = URL(string: "https://static.momocdn.net/app/app/kits/animation_scan_qr_icon_button.json")!
61
+ private let ctaLottieLabelURL = URL(string: "https://static.momocdn.net/app/app/kits/animation_scan_qr_text.json")!
62
+
63
+ /// Loads the two CTA Lotties from the CDN once (no bundled files), mirroring the kit's LottieView(url:).
64
+ private final class CtaLottieLoader: ObservableObject {
65
+ @Published var button: LottieAnimation?
66
+ @Published var label: LottieAnimation?
67
+
68
+ func load() {
69
+ if button == nil {
70
+ LottieAnimation.loadedFrom(url: ctaLottieButtonURL, closure: { [weak self] in self?.button = $0 }, animationCache: nil)
71
+ }
72
+ if label == nil {
73
+ LottieAnimation.loadedFrom(url: ctaLottieLabelURL, closure: { [weak self] in self?.label = $0 }, animationCache: nil)
74
+ }
75
+ }
76
+ }
77
+
78
+ // both parts read their progress from the same clock, two playing views start at different times
79
+ private func ctaLottie(_ animation: LottieAnimation?, offset: CGFloat) -> some View {
80
+ TimelineView(.animation) { timeline in
81
+ let duration = animation?.duration ?? 1
82
+ let elapsed = timeline.date.timeIntervalSinceReferenceDate
83
+ LottieView(animation: animation)
84
+ .currentProgress(elapsed.truncatingRemainder(dividingBy: duration) / duration)
85
+ .resizable()
86
+ .frame(width: ctaLottieSize, height: ctaLottieSize)
87
+ .offset(y: offset)
88
+ }
89
+ }
90
+ private let badges: [(String, String?)] = [
91
+ ("Không", nil), ("Dot \"\"", ""), ("\"0\"", "0"), ("\"5\"", "5"),
92
+ ("\"1999\"", "1999"), ("\"Mới\"", "Mới"), ("Chữ dài", "Khuyến mãi lớn"),
93
+ ]
94
+
14
95
  struct BottomTabDemoContent: View {
15
- @EnvironmentObject private var navigator: Navigator
96
+ @State private var config = DemoConfig()
97
+ @StateObject private var ctaLottieLoader = CtaLottieLoader()
98
+ // the bar is rebuilt on every change: reopen it on the tab the user is on
99
+ @State private var focused = DemoConfig().initialRouteName
16
100
 
17
101
  var body: some View {
102
+ let tabs = config.visibleTabs
103
+ let initial = tabs.contains { $0.name == focused } ? focused : tabs[0].name
18
104
  BottomTab(
19
- items: [
20
- BottomTabItem(
21
- name: "Tab1",
22
- label: "Option 1",
23
- icon: "16_basic_home",
24
- badgeLabel: "",
25
- options: NavigationOptions(headerTitle: .default("Option 1"), hiddenBack: false),
26
- screen: { tabBody("Option 1", Colors.blue09) }
27
- ),
28
- BottomTabItem(
29
- name: "Tab2",
30
- label: "Option 2",
31
- icon: "help_center",
32
- badgeLabel: "0", // hidden (mirrors Compose's "0" → no badge)
33
- options: NavigationOptions(headerTitle: .default("Option 2")),
34
- screen: { tabBody("Option 2", Colors.pink09) }
35
- ),
36
- BottomTabItem(
37
- name: "Tab3",
38
- label: "Option 3 with a very long label",
39
- icon: "pin_star",
40
- badgeLabel: "New",
41
- options: NavigationOptions(headerTitle: .default("Option 3")),
42
- screen: { tabBody("Option 3", Colors.yellow09) }
43
- ),
105
+ items: tabs.map { tab in
44
106
  BottomTabItem(
45
- name: "Tab4",
46
- label: "Option 4 also quite long here",
47
- icon: "navigation_more_icon",
48
- badgeLabel: "9999",
49
- options: NavigationOptions(headerTitle: .default("Option 4")),
50
- screen: { tabBody("Option 4", Colors.blue10) }
107
+ name: tab.name,
108
+ label: config.longLabels ? "\(tab.label) dài quá" : tab.label,
109
+ icon: tab.icon,
110
+ showDot: tab.showDot,
111
+ badgeLabel: tab.badgeLabel,
112
+ options: NavigationOptions(
113
+ headerTitle: .default(tab.label),
114
+ footer: config.footer ? { AnyView(demoFooter) } : nil
115
+ ),
116
+ screen: { TabContent(name: tab.name, config: $config, focused: $focused) }
51
117
  )
52
- ],
53
- floatingButton: BottomTabFloatingButton(
54
- icon: "16_basic_home",
55
- label: "Quét QR",
56
- onPress: { navigator.push({ qrScreen }, options: NavigationOptions(title: "QR")) }
57
- )
118
+ },
119
+ floatingButton: floatingButton,
120
+ compressionBehavior: config.compressionBehavior,
121
+ initialRouteName: initial,
122
+ onTabPress: { index, switchTab in
123
+ focused = tabs[index].name
124
+ switchTab()
125
+ },
126
+ backToInitialTab: config.backToInitialTab
127
+ )
128
+ .id(config)
129
+ .onAppear { ctaLottieLoader.load() }
130
+ }
131
+
132
+ private var demoFooter: some View {
133
+ MoMoUIKits.Button(title: "Footer trong content", action: {}, isFull: true)
134
+ }
135
+
136
+ private var floatingButton: BottomTabFloatingButton? {
137
+ guard config.special else { return nil }
138
+ guard config.ctaLottie else {
139
+ return BottomTabFloatingButton(icon: config.ctaIcon, label: config.ctaLabel, onPress: {})
140
+ }
141
+ return BottomTabFloatingButton(
142
+ label: config.ctaLabel,
143
+ onPress: {},
144
+ iconContent: { ctaLottie(ctaLottieLoader.button, offset: ctaLottieButtonOffset) },
145
+ labelContent: { ctaLottie(ctaLottieLoader.label, offset: -ctaLottieLabelOffset) }
58
146
  )
59
147
  }
148
+ }
149
+
150
+ /// Content of every tab: this tab's own props, the bar props, then the center action. The tab's
151
+ /// StackScreen scrolls it under the floating bar and keeps its end clear of it.
152
+ private struct TabContent: View {
153
+ let name: String
154
+ @Binding var config: DemoConfig
155
+ @Binding var focused: String
156
+
157
+ private var tab: TabConfig { config.tabs.first { $0.name == name }! }
158
+
159
+ private func updateTab(_ change: (inout TabConfig) -> Void) {
160
+ guard let index = config.tabs.firstIndex(where: { $0.name == name }) else { return }
161
+ change(&config.tabs[index])
162
+ }
163
+
164
+ private func yesNo(_ value: Bool, _ onChange: @escaping (Bool) -> Void) -> [Option] {
165
+ [Option(title: "Có", selected: value) { onChange(true) },
166
+ Option(title: "Không", selected: !value) { onChange(false) }]
167
+ }
168
+
169
+ var body: some View {
170
+ let ctaHidden = config.special && config.tabCount % 2 != 0
171
+ VStack(alignment: .leading, spacing: Spacing.M) {
172
+ MomoText("Chạm các tab bên dưới để xem indicator chạy qua lại. Mỗi thay đổi áp dụng ngay lên thanh tab.",
173
+ typography: .bodyDefaultRegular)
174
+
175
+ Section(title: "Tab đang mở · \(name)") {
176
+ IconOptions(title: "icon", icons: icons, value: tab.icon) { icon in updateTab { $0.icon = icon } }
177
+ Options(title: "badgeLabel",
178
+ hint: "\"\" là dot, \"0\" ẩn badge, số > 99 hiện 99+, chữ dài bị cắt ở 58",
179
+ options: badges.map { title, value in
180
+ Option(title: title, selected: tab.badgeLabel == value) { updateTab { $0.badgeLabel = value } }
181
+ })
182
+ Options(title: "showDot",
183
+ hint: "Hiện dot khi không có badgeLabel hoặc badgeLabel là \"0\"",
184
+ options: yesNo(tab.showDot) { value in updateTab { $0.showDot = value } })
185
+ }
186
+
187
+ Section(title: "Thanh tab") {
188
+ Options(title: "Số tab (items)", options: (2...5).map { count in
189
+ Option(title: "\(count)", selected: config.tabCount == count) { config.tabCount = count }
190
+ })
191
+ Options(title: "label", options: [
192
+ Option(title: "Ngắn", selected: !config.longLabels) { config.longLabels = false },
193
+ Option(title: "Dài", selected: config.longLabels) { config.longLabels = true },
194
+ ])
195
+ Options(title: "initialRouteName", hint: "Tab được chọn khi BottomTab mở",
196
+ options: config.visibleTabs.map { item in
197
+ Option(title: item.name, selected: config.initialRouteName == item.name) {
198
+ focused = item.name
199
+ config.initialRouteName = item.name
200
+ }
201
+ })
202
+ Options(title: "compressionBehavior",
203
+ hint: "iPhone Duo: bar nào thu gọn trước khi side bar không đủ chỗ",
204
+ options: [
205
+ Option(title: "toolbar", selected: config.compressionBehavior == .toolbar) {
206
+ config.compressionBehavior = .toolbar
207
+ },
208
+ Option(title: "tabBar", selected: config.compressionBehavior == .tabBar) {
209
+ config.compressionBehavior = .tabBar
210
+ },
211
+ ])
212
+ Options(title: "backToInitialTab", hint: "Back ở tab khác quay về tab đầu trước khi rời màn",
213
+ options: yesNo(config.backToInitialTab) { config.backToInitialTab = $0 })
214
+ Options(title: "footer",
215
+ hint: "Footer dính trong content body, kiểm tra nó nằm trên thanh tab nổi",
216
+ options: yesNo(config.footer) { config.footer = $0 })
217
+ }
218
+
219
+ Section(title: "Nút giữa (floatingButton)") {
220
+ Options(title: "floatingButton",
221
+ hint: ctaHidden
222
+ ? "Đang ẩn: nút giữa chỉ hiện khi có 2 hoặc 4 tab"
223
+ : "Có = Special (nút giữa trong notch), Không = Default",
224
+ options: yesNo(config.special) { config.special = $0 })
225
+ if config.special {
226
+ Options(title: "label", options: ["Quét mọi QR", "Quét mã thanh toán"].map { label in
227
+ Option(title: label, selected: config.ctaLabel == label) { config.ctaLabel = label }
228
+ })
229
+ Options(title: "icon dạng", hint: "Lottie: animation Quét mọi QR của Home, 2 phần nút và chữ", options: [
230
+ Option(title: "Icon", selected: !config.ctaLottie) { config.ctaLottie = false },
231
+ Option(title: "Lottie", selected: config.ctaLottie) { config.ctaLottie = true },
232
+ ])
233
+ if !config.ctaLottie {
234
+ IconOptions(title: "icon", icons: ctaIcons, value: config.ctaIcon) { config.ctaIcon = $0 }
235
+ }
236
+ }
237
+ }
60
238
 
61
- @ViewBuilder
62
- private func tabBody(_ title: String, _ color: Color) -> some View {
63
- VStack {
64
- MomoText(title, typography: .headerDefaultBold)
65
- .padding(.top, 24)
66
- Spacer()
239
+ MoMoUIKits.Button(title: "Khôi phục mặc định", action: { config = DemoConfig() }, type: .outline)
67
240
  }
68
- .frame(maxWidth: .infinity, maxHeight: .infinity)
69
- .background(color)
241
+ .padding(Spacing.M)
70
242
  }
243
+ }
244
+
245
+ private struct Option: Identifiable {
246
+ var id: String { title }
247
+ let title: String
248
+ let selected: Bool
249
+ let onPress: () -> Void
250
+ }
251
+
252
+ private struct Section<Content: View>: View {
253
+ let title: String
254
+ @ViewBuilder let content: () -> Content
71
255
 
72
- private var qrScreen: some View {
73
- VStack { MomoText("QR scanner placeholder") }
74
- .frame(maxWidth: .infinity)
75
- .padding(24)
256
+ @Environment(\.appTheme) private var theme
257
+
258
+ var body: some View {
259
+ VStack(alignment: .leading, spacing: Spacing.M) {
260
+ MomoText(title, typography: .headerSSemibold)
261
+ content()
262
+ }
263
+ .padding(Spacing.M)
264
+ .frame(maxWidth: .infinity, alignment: .leading)
265
+ .background(RoundedRectangle(cornerRadius: Radius.M).fill(theme.colors.background.surface))
266
+ }
267
+ }
268
+
269
+ private struct Options: View {
270
+ let title: String
271
+ var hint: String? = nil
272
+ let options: [Option]
273
+
274
+ var body: some View {
275
+ VStack(alignment: .leading, spacing: Spacing.XS) {
276
+ MomoText(title, typography: .labelDefaultMedium)
277
+ if let hint {
278
+ MomoText(hint, typography: .descriptionXsRegular)
279
+ }
280
+ LazyVGrid(columns: [GridItem(.adaptive(minimum: 88), spacing: Spacing.S, alignment: .leading)],
281
+ alignment: .leading, spacing: Spacing.S) {
282
+ ForEach(options) { option in
283
+ MoMoUIKits.Button(title: option.title, action: option.onPress,
284
+ type: option.selected ? .primary : .outline, size: .small, isFull: false)
285
+ }
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ private struct IconOptions: View {
292
+ let title: String
293
+ let icons: [String]
294
+ let value: String
295
+ let onChange: (String) -> Void
296
+
297
+ @Environment(\.appTheme) private var theme
298
+
299
+ var body: some View {
300
+ VStack(alignment: .leading, spacing: Spacing.XS) {
301
+ MomoText(title, typography: .labelDefaultMedium)
302
+ HStack(spacing: Spacing.S) {
303
+ ForEach(icons, id: \.self) { icon in
304
+ let selected = icon == value
305
+ SwiftUI.Button { onChange(icon) } label: {
306
+ Icon(source: icon, size: 24, color: selected ? theme.colors.primary : theme.colors.text.default)
307
+ .frame(width: 40, height: 40)
308
+ .overlay(
309
+ RoundedRectangle(cornerRadius: Radius.S)
310
+ .stroke(selected ? theme.colors.primary : theme.colors.border.default, lineWidth: 1)
311
+ )
312
+ }
313
+ .buttonStyle(.plain)
314
+ }
315
+ }
316
+ }
76
317
  }
77
318
  }
78
319
 
@@ -80,10 +321,6 @@ struct BottomTabDemoContent: View {
80
321
 
81
322
  struct BottomTabDemo: View {
82
323
  var body: some View {
83
- if #available(iOS 16.0, *) {
84
- BottomTabDemoContent()
85
- } else {
86
- Text("Bottom tab demo requires iOS 16+").padding()
87
- }
324
+ BottomTabDemoContent()
88
325
  }
89
326
  }
@@ -28,6 +28,8 @@ private struct InputPhoneNumberPreview: View {
28
28
  @State private var t3 = ""
29
29
  @State private var t4 = ""
30
30
  @State private var t5 = ""
31
+ @State private var t6 = ""
32
+ @State private var trailingPressCount = 0
31
33
 
32
34
  var body: some View {
33
35
  BasicColumnBox("Size", alignment: .leading) {
@@ -41,7 +43,16 @@ private struct InputPhoneNumberPreview: View {
41
43
  InputPhoneNumber(text: $t4, placeholder: "Enter here", error: "error message")
42
44
  }
43
45
  BasicColumnBox("Trailing Icon", alignment: .leading) {
44
- InputPhoneNumber(text: $t5, placeholder: "Phone", rightIcon: "24_ic_public", rightIconColor: Colors.pink03)
46
+ InputPhoneNumber(text: $t5, placeholder: "Phone", trailing: "24_ic_public", trailingColor: Colors.pink03)
47
+ }
48
+ BasicColumnBox("Trailing bấm được", alignment: .leading) {
49
+ InputPhoneNumber(
50
+ text: $t6,
51
+ placeholder: "Phone",
52
+ trailing: "Phonebook",
53
+ onPressTrailing: { trailingPressCount += 1 }
54
+ )
55
+ MomoText("Đã bấm icon: \(trailingPressCount)")
45
56
  }
46
57
  }
47
58
  }
@@ -55,7 +66,7 @@ private struct InputPhoneNumberPlayground: View {
55
66
  @State private var hintText = ""
56
67
  @State private var error = ""
57
68
  @State private var size: PlaygroundOption? = inputSizeList.first { $0.key == "small" }
58
- @State private var rightIcon: PlaygroundOption?
69
+ @State private var trailing: PlaygroundOption?
59
70
  @State private var loading = false
60
71
  @State private var required = false
61
72
 
@@ -70,7 +81,7 @@ private struct InputPhoneNumberPlayground: View {
70
81
  error: error,
71
82
  loading: loading,
72
83
  required: required,
73
- rightIcon: (rightIcon?.value as? String) ?? ""
84
+ trailing: (trailing?.value as? String) ?? ""
74
85
  )
75
86
  },
76
87
  params: [
@@ -78,7 +89,7 @@ private struct InputPhoneNumberPlayground: View {
78
89
  .string("HintText", $hintText),
79
90
  .string("Error", $error),
80
91
  .radio("Size", inputSizeList, $size),
81
- .option("RightIcon", playgroundIcons, $rightIcon),
92
+ .option("Trailing", playgroundIcons, $trailing),
82
93
  .checkbox("Loading", $loading),
83
94
  .checkbox("Required", $required),
84
95
  ]
@@ -24,14 +24,11 @@ private let AppTranslations = LocalizationObject(
24
24
  )
25
25
 
26
26
  struct LocalizeDemo: View {
27
- // AI-GENERATED START: observe the app language and drive it through the real platform API
28
27
  @Environment(\.localize) private var localize
29
28
  @Environment(\.applicationEnvironment) private var applicationEnvironment
30
- // AI-GENERATED END: observe the app language and drive it through the real platform API
31
29
 
32
30
  private var isEnglish: Bool { localize.currentLanguage == Localize.EN }
33
31
 
34
- // AI-GENERATED START: observe the app language and drive it through the real platform API
35
32
  private var storedLanguage: String {
36
33
  UserDefaults.standard.string(forKey: UserDefaultsLanguageSource.defaultKey) ?? "nil"
37
34
  }
@@ -45,7 +42,6 @@ struct LocalizeDemo: View {
45
42
  localize.changeLanguage(language) // #Preview / sample app: no host bridge
46
43
  }
47
44
  }
48
- // AI-GENERATED END: observe the app language and drive it through the real platform API
49
45
 
50
46
  var body: some View {
51
47
  ScrollView {
@@ -65,7 +61,6 @@ struct LocalizeDemo: View {
65
61
  MomoText("currentLanguage = \(localize.currentLanguage)", typography: .labelDefaultMedium)
66
62
  }
67
63
 
68
- // AI-GENERATED START: prove the observation loop, not kit-local state, drives updates
69
64
  LocalizeSectionBox(title: "Nguồn thật: UserDefaults") {
70
65
  MomoText(
71
66
  "Ghi thẳng vào UserDefaults, bỏ qua mọi API của kit — màn hình vẫn đổi, chứng minh "
@@ -88,7 +83,6 @@ struct LocalizeDemo: View {
88
83
  isFull: false
89
84
  )
90
85
  }
91
- // AI-GENERATED END: prove the observation loop, not kit-local state, drives updates
92
86
 
93
87
  LocalizeSectionBox(title: "translate(key) — từ điển mặc định của kit") {
94
88
  TranslationRow(key: "confirm", value: localize.translate("confirm"))
@@ -224,10 +218,8 @@ private struct TranslationRow: View {
224
218
  #Preview {
225
219
  if #available(iOS 16.0, *) {
226
220
  NavigationStack {
227
- // AI-GENERATED START: preview needs the observing provider or the toggle will not update
228
221
  LocalizeDemo()
229
222
  .momoLocalize(Localize())
230
- // AI-GENERATED END: preview needs the observing provider or the toggle will not update
231
223
  }
232
224
  } else {
233
225
  // Fallback on earlier versions
@@ -202,6 +202,13 @@ private struct NavigationDemoContent: View {
202
202
  )
203
203
  }
204
204
 
205
+ row("Header Types") {
206
+ navigator.push(
207
+ { HeaderTypesScreen() },
208
+ options: NavigationOptions(title: "Header Types")
209
+ )
210
+ }
211
+
205
212
  row("Bottom Tabs") {
206
213
  navigator.push(
207
214
  { BottomTabDemoContent() },
@@ -253,6 +260,113 @@ private struct UpdateOptionsScreen: View {
253
260
  }
254
261
  }
255
262
 
263
+ /// Header options switched at runtime (Compose `HeaderTypeUsage`).
264
+ @available(iOS 16.0, *)
265
+ private struct HeaderTypesScreen: View {
266
+ private enum Kind: String, CaseIterable {
267
+ case none = "None", `default` = "Default", extended = "Extended", transparent = "Transparent"
268
+ }
269
+
270
+ private enum HeaderRightOption: String, CaseIterable {
271
+ case toolkit = "Toolkit", homeOnly = "Home only", none = "None"
272
+ }
273
+
274
+ @EnvironmentObject private var navigation: Navigation
275
+ @Environment(\.applicationEnvironment) private var applicationEnvironment
276
+ @Environment(\.screenLayout) private var layout
277
+ @State private var kind: AnyHashable = Kind.default
278
+ @State private var contentLayout: AnyHashable = ContentLayout.grid
279
+ @State private var titlePosition: AnyHashable = TitlePosition.left
280
+ @State private var showBack = true
281
+ @State private var headerRight: AnyHashable = HeaderRightOption.toolkit
282
+ @State private var isAnimated = false
283
+ @State private var isHeader = false
284
+ @State private var isFullScreenContent = false
285
+ @State private var searchText = ""
286
+
287
+ var body: some View {
288
+ VStack(alignment: .leading, spacing: Spacing.M) {
289
+ ForEach(Kind.allCases, id: \.self) { item in
290
+ Radio(value: item, groupValue: $kind, onChange: applyHeader, label: item.rawValue)
291
+ }
292
+ Divider()
293
+ MomoText("Title Position")
294
+ ForEach([TitlePosition.left, TitlePosition.center], id: \.self) { position in
295
+ Radio(value: position, groupValue: $titlePosition, onChange: {
296
+ navigation.setOptions { $0.titlePosition = position }
297
+ }, label: position == .left ? "LEFT" : "CENTER")
298
+ }
299
+ Divider()
300
+ // stretch only differs on wide windows (short side >= 600, iPhone Duo excluded)
301
+ let headerLayout = layout.headerLayout(contentLayout.base as? ContentLayout ?? .grid)
302
+ MomoText("Content Layout · wide: \(headerLayout.isWide), frame inset: \(Int(headerLayout.frameInset))")
303
+ ForEach([ContentLayout.grid, ContentLayout.stretch], id: \.self) { item in
304
+ Radio(value: item, groupValue: $contentLayout, onChange: {
305
+ navigation.setOptions { $0.contentLayout = item }
306
+ }, label: item == .grid ? "Grid" : "Stretch")
307
+ }
308
+ Divider()
309
+ Checkbox($showBack, onChange: { checked in
310
+ navigation.setOptions { $0.hiddenBack = !checked }
311
+ }, title: "Show Back")
312
+ MomoText("Header Right")
313
+ ForEach(HeaderRightOption.allCases, id: \.self) { option in
314
+ Radio(value: option, groupValue: $headerRight, onChange: { applyHeaderRight(option) }, label: option.rawValue)
315
+ }
316
+ Divider()
317
+ Checkbox($isAnimated, onChange: { checked in
318
+ if checked { isHeader = false }
319
+ applyHeader()
320
+ }, title: "Search Animated")
321
+ Checkbox($isHeader, onChange: { checked in
322
+ if checked { isAnimated = false }
323
+ applyHeader()
324
+ }, title: "Search Header")
325
+ if kind == AnyHashable(Kind.transparent) {
326
+ Checkbox($isFullScreenContent, onChange: { _ in applyHeader() }, title: "Is Full Screen Content")
327
+ }
328
+ Color.clear.frame(height: 1600)
329
+ }
330
+ .padding(Spacing.M)
331
+ }
332
+
333
+ private func applyHeaderRight(_ option: HeaderRightOption) {
334
+ let maxApi = applicationEnvironment.maxApi
335
+ navigation.setOptions {
336
+ $0.headerRightData = option == .toolkit ? HeaderRightData() : nil
337
+ $0.headerRight = option == .homeOnly ? {
338
+ NavigationButton(icon: "16_basic_home") { maxApi?.dismissAll(completion: nil) }
339
+ } : nil
340
+ }
341
+ }
342
+
343
+ private func applyHeader() {
344
+ let selected = kind.base as? Kind ?? .default
345
+ var search: InputSearchProps?
346
+ if isAnimated {
347
+ search = InputSearchProps(text: $searchText, placeholder: "Search input")
348
+ } else if isHeader {
349
+ search = InputSearchProps(text: $searchText, buttonText: "Huỷ", showButtonText: true, placeholder: "Search input")
350
+ }
351
+ navigation.setOptions {
352
+ switch selected {
353
+ case .none:
354
+ $0.headerType = .none
355
+ case .default, .extended:
356
+ $0.headerType = selected == .default ? .default : .extended
357
+ $0.useAnimated = isAnimated
358
+ $0.inputSearchProps = search
359
+ case .transparent:
360
+ $0.headerType = .default
361
+ $0.useAnimated = false
362
+ $0.inputSearchProps = nil
363
+ }
364
+ $0.headerTransparent = selected == .transparent
365
+ $0.fullScreenContent = selected == .transparent && isFullScreenContent
366
+ }
367
+ }
368
+ }
369
+
256
370
  @available(iOS 16.0, *)
257
371
  private struct DemoLeafScreen: View {
258
372
  @EnvironmentObject private var navigator: Navigator