@momo-kits/native-kits 0.163.1-beta.3-debug → 0.163.1-beta.5-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 (215) hide show
  1. package/CLAUDE.md +1 -1
  2. package/compose/build.gradle.kts +2 -1
  3. package/compose/build.gradle.kts.backup +1 -0
  4. package/compose/compose.podspec +1 -1
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  6. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +8 -10
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +3 -0
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +11 -9
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +40 -55
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +69 -26
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +3 -1
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +3 -6
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +22 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +28 -21
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +112 -115
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +11 -6
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +3 -4
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +3 -1
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +2 -1
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  24. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  25. package/gradle/libs.versions.toml +2 -0
  26. package/gradle.properties +1 -1
  27. package/ios/Application/ApplicationEnvironment.swift +11 -1
  28. package/ios/Application/Components.swift +34 -44
  29. package/ios/Application/FloatingButton.swift +10 -9
  30. package/ios/Application/HeaderRight.swift +79 -45
  31. package/ios/Application/Navigation/BottomTab/BottomTab.swift +103 -0
  32. package/ios/Application/Navigation/BottomTab/BottomTabBar.swift +215 -0
  33. package/ios/Application/Navigation/BottomTab/CurvedContainer.swift +65 -0
  34. package/ios/Application/Navigation/HeaderBackProps.swift +66 -0
  35. package/ios/Application/Navigation/HeaderTitle.swift +57 -0
  36. package/ios/Application/Navigation/HeaderUser.swift +209 -0
  37. package/ios/Application/Navigation/NavigationContainer.swift +176 -0
  38. package/ios/Application/Navigation/NavigationOptions.swift +109 -0
  39. package/ios/Application/Navigation/Navigator.swift +364 -0
  40. package/ios/Application/Navigation/Overplay/BottomSheet.swift +188 -0
  41. package/ios/Application/Navigation/Overplay/ModalScreen.swift +68 -0
  42. package/ios/Application/Navigation/Overplay/SnackBar.swift +144 -0
  43. package/ios/Application/Navigation/component/Header.swift +178 -0
  44. package/ios/Application/Navigation/component/HeaderBackground.swift +83 -0
  45. package/ios/Application/Navigation/component/HeaderColor.swift +65 -0
  46. package/ios/Application/Screen.swift +2 -1
  47. package/ios/Application/StackScreen.swift +453 -0
  48. package/ios/Avatar/Avatar.swift +193 -0
  49. package/ios/Badge/Badge.swift +11 -14
  50. package/ios/Badge/BadgeRibbon.swift +12 -21
  51. package/ios/BaselineView/BaselineView.swift +163 -0
  52. package/ios/Button/Button.swift +61 -22
  53. package/ios/Carousel/Carousel.swift +181 -0
  54. package/ios/Checkbox/Checkbox.swift +14 -13
  55. package/ios/Chip/Chip.swift +23 -9
  56. package/ios/Collapse/Collapse.swift +182 -0
  57. package/ios/Colors+Radius+Spacing/Colors.swift +12 -12
  58. package/ios/Colors+Radius+Spacing/Theme.swift +295 -0
  59. package/ios/DateTimePicker/DateTimePicker.swift +210 -0
  60. package/ios/DateTimePicker/DateTimePickerTypes.swift +55 -0
  61. package/ios/DateTimePicker/DateTimePickerUtils.swift +167 -0
  62. package/ios/DateTimePicker/WheelPicker.swift +161 -0
  63. package/ios/Divider/Divider.swift +16 -0
  64. package/ios/Extensions/Color++.swift +32 -0
  65. package/ios/Icon/Icon.swift +6 -1
  66. package/ios/IconButton/IconButton.swift +112 -0
  67. package/ios/Input/Input.swift +41 -25
  68. package/ios/Input/InputPhoneNumber.swift +20 -19
  69. package/ios/Input/InputSearch.swift +100 -47
  70. package/ios/Input/InputTextArea.swift +66 -40
  71. package/ios/InputDropDown/InputDropDown.swift +198 -0
  72. package/ios/InputMoney/InputMoney.swift +335 -0
  73. package/ios/InputOTP/InputOTP.swift +210 -0
  74. package/ios/Loader/Loader.swift +113 -0
  75. package/ios/MoMoUIKits.podspec +5 -0
  76. package/ios/Pagination/PaginationDot.swift +61 -0
  77. package/ios/Pagination/PaginationNumber.swift +35 -0
  78. package/ios/Pagination/PaginationScroll.swift +101 -0
  79. package/ios/Pagination/PaginationWhiteDot.swift +37 -0
  80. package/ios/Popup/PopupDisplay.swift +8 -16
  81. package/ios/Popup/PopupInput.swift +2 -8
  82. package/ios/Popup/PopupNotify.swift +219 -0
  83. package/ios/ProgressInfo/ProgressInfo.swift +294 -0
  84. package/ios/Radio/Radio.swift +70 -0
  85. package/ios/Rating/Rating.swift +82 -0
  86. package/ios/Resources/MoMoUIKitsColors.xcassets/AccentColor.colorset/Contents.json +11 -0
  87. package/ios/Resources/MoMoUIKitsColors.xcassets/Background.colorset/Contents.json +38 -0
  88. package/ios/Resources/MoMoUIKitsColors.xcassets/Border.colorset/Contents.json +38 -0
  89. package/ios/Resources/MoMoUIKitsColors.xcassets/Card.colorset/Contents.json +38 -0
  90. package/ios/Resources/MoMoUIKitsColors.xcassets/Contents.json +6 -0
  91. package/ios/Resources/MoMoUIKitsColors.xcassets/Error.colorset/Contents.json +38 -0
  92. package/ios/Resources/MoMoUIKitsColors.xcassets/Primary.colorset/Contents.json +38 -0
  93. package/ios/Resources/MoMoUIKitsColors.xcassets/PrimaryDark.colorset/Contents.json +38 -0
  94. package/ios/Resources/MoMoUIKitsColors.xcassets/PrimaryLight.colorset/Contents.json +38 -0
  95. package/ios/Resources/MoMoUIKitsColors.xcassets/Secondary.colorset/Contents.json +38 -0
  96. package/ios/Resources/MoMoUIKitsColors.xcassets/Success.colorset/Contents.json +38 -0
  97. package/ios/Resources/MoMoUIKitsColors.xcassets/Text.colorset/Contents.json +38 -0
  98. package/ios/Resources/MoMoUIKitsColors.xcassets/TextSecondary.colorset/Contents.json +38 -0
  99. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/Contents.json +9 -0
  100. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/background-default.colorset/Contents.json +38 -0
  101. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/background-disable.colorset/Contents.json +38 -0
  102. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/background-pressed.colorset/Contents.json +38 -0
  103. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/background-selected.colorset/Contents.json +38 -0
  104. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/background-surface.colorset/Contents.json +38 -0
  105. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/background-tonal.colorset/Contents.json +38 -0
  106. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/border-default.colorset/Contents.json +38 -0
  107. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/border-disable.colorset/Contents.json +38 -0
  108. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/gradient.colorset/Contents.json +38 -0
  109. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/primary.colorset/Contents.json +38 -0
  110. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/secondary.colorset/Contents.json +38 -0
  111. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/success-container.colorset/Contents.json +38 -0
  112. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/success-primary.colorset/Contents.json +38 -0
  113. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/success-secondary.colorset/Contents.json +38 -0
  114. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/text-default.colorset/Contents.json +38 -0
  115. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/text-disable.colorset/Contents.json +38 -0
  116. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/text-hint.colorset/Contents.json +38 -0
  117. package/ios/Resources/MoMoUIKitsColors.xcassets/ThemeColors/text-secondary.colorset/Contents.json +38 -0
  118. package/ios/Resources/MoMoUIKitsColors.xcassets/Warning.colorset/Contents.json +38 -0
  119. package/ios/Skeleton/Skeleton.swift +99 -0
  120. package/ios/Slider/Slider.swift +237 -0
  121. package/ios/Stepper/Stepper.swift +220 -0
  122. package/ios/Steps/Steps.swift +451 -0
  123. package/ios/SuggestAction/SuggestAction.swift +97 -0
  124. package/ios/Swipeable/SwipeCell.swift +185 -0
  125. package/ios/Swipeable/SwipeCellModel.swift +21 -0
  126. package/ios/TabView/TabView.swift +530 -0
  127. package/ios/Tag/Tag.swift +98 -0
  128. package/ios/Title/Title.swift +269 -0
  129. package/ios/Tooltip/Tooltip.swift +482 -0
  130. package/ios/Typography/FontScaleStore.swift +19 -0
  131. package/ios/Typography/Text.swift +86 -17
  132. package/ios/Typography/Typography.swift +12 -14
  133. package/ios/Uploader/Uploader.swift +183 -0
  134. package/ios/native-kits.podspec +61 -8
  135. package/ios-demo/MoMoUIKitsDemo.podspec +20 -0
  136. package/ios-demo/README.md +120 -0
  137. package/ios-demo/Resources/dot_loading.json +558 -0
  138. package/ios-demo/Resources/icon.json +4052 -0
  139. package/ios-demo/Resources/lottie_circle_loader.json +1 -0
  140. package/ios-demo/Sources/MoMoUIKitsDemo/DemoScaffold.swift +48 -0
  141. package/ios-demo/Sources/MoMoUIKitsDemo/Demos/UIKitsBadgeDemoView.swift +25 -0
  142. package/ios-demo/Sources/MoMoUIKitsDemo/Demos/UIKitsButtonDemoView.swift +26 -0
  143. package/ios-demo/Sources/MoMoUIKitsDemo/Demos/UIKitsCheckboxDemoView.swift +19 -0
  144. package/ios-demo/Sources/MoMoUIKitsDemo/Demos/UIKitsChipDemoView.swift +33 -0
  145. package/ios-demo/Sources/MoMoUIKitsDemo/Demos/UIKitsInputDemoView.swift +48 -0
  146. package/ios-demo/Sources/MoMoUIKitsDemo/Demos/UIKitsPopupDemoView.swift +21 -0
  147. package/ios-demo/Sources/MoMoUIKitsDemo/Demos/UIKitsRadioDemoView.swift +17 -0
  148. package/ios-demo/Sources/MoMoUIKitsDemo/Demos/UIKitsTypographyDemoView.swift +28 -0
  149. package/ios-demo/Sources/MoMoUIKitsDemo/MoMoUIKitsDemoContext.swift +31 -0
  150. package/ios-demo/Sources/MoMoUIKitsDemo/MoMoUIKitsDemoFactory.swift +24 -0
  151. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/AnimatedHeaderDemo.swift +110 -0
  152. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/AvatarDemo.swift +93 -0
  153. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BadgeDemo.swift +269 -0
  154. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BaselineView.swift +117 -0
  155. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +89 -0
  156. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/ButtonDemo.swift +100 -0
  157. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/CarouselDemo.swift +126 -0
  158. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/CheckboxDemo.swift +63 -0
  159. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/ChipDemo.swift +20 -0
  160. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/CollapseDemo.swift +93 -0
  161. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/ContentView.swift +107 -0
  162. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/DateTimePickerDemo.swift +124 -0
  163. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/DividerDemo.swift +14 -0
  164. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/HeaderUserDemo.swift +49 -0
  165. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/Home.swift +278 -0
  166. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/IconButtonDemo.swift +58 -0
  167. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/ImageDemo.swift +78 -0
  168. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InformationDemo.swift +138 -0
  169. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputDemo.swift +111 -0
  170. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputDropDownDemo.swift +136 -0
  171. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputMoneyDemo.swift +107 -0
  172. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputOTPDemo.swift +73 -0
  173. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputPhoneNumberDemo.swift +100 -0
  174. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputSearchDemo.swift +32 -0
  175. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputTextAreaDemo.swift +57 -0
  176. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/LoaderDemo.swift +70 -0
  177. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +227 -0
  178. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PaginationDemo.swift +72 -0
  179. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupDisplayDemo.swift +175 -0
  180. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +121 -0
  181. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupPromotionDemo.swift +76 -0
  182. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/ProgressInfoDemo.swift +89 -0
  183. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/RadioDemo.swift +32 -0
  184. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/RatingDemo.swift +56 -0
  185. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/SkeletonDemo.swift +32 -0
  186. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/SliderDemo.swift +150 -0
  187. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/SnackBarDemo.swift +138 -0
  188. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/StepperDemo.swift +103 -0
  189. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/StepsDemo.swift +94 -0
  190. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/SuggestActionDemo.swift +79 -0
  191. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/SwipeDemo.swift +152 -0
  192. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/SwitchDemo.swift +33 -0
  193. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/TabViewDemo.swift +190 -0
  194. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/TagDemo.swift +34 -0
  195. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/ThemeDemo.swift +182 -0
  196. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/TitleDemo.swift +109 -0
  197. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/TooltipDemo.swift +187 -0
  198. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/TypographyDemo.swift +87 -0
  199. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/UploaderDemo.swift +131 -0
  200. package/ios-demo/Sources/MoMoUIKitsDemo/SwiftUIDemoBrowserView.swift +51 -0
  201. package/ios-demo/Sources/MoMoUIKitsDemo/UIKitsDemoModels.swift +15 -0
  202. package/ios-demo/Sources/MoMoUIKitsDemo/UIKitsDemoRegistry.swift +73 -0
  203. package/package.json +1 -1
  204. package/publish.sh +50 -0
  205. package/scripts/gen-ios-color.mjs +136 -0
  206. package/example/ios/Example.xcodeproj/xcuserdata/huynhdung.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  207. package/example/ios/Example.xcworkspace/xcuserdata/huynhdung.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  208. package/example/ios/Example.xcworkspace/xcuserdata/huynhdung.xcuserdatad/xcschemes/xcschememanagement.plist +0 -5
  209. package/example/ios/Pods/Pods.xcodeproj/xcuserdata/huynhdung.xcuserdatad/xcschemes/MoMoUIKits.xcscheme +0 -58
  210. package/example/ios/Pods/Pods.xcodeproj/xcuserdata/huynhdung.xcuserdatad/xcschemes/Pods-Example.xcscheme +0 -58
  211. package/example/ios/Pods/Pods.xcodeproj/xcuserdata/huynhdung.xcuserdatad/xcschemes/SDWebImage.xcscheme +0 -58
  212. package/example/ios/Pods/Pods.xcodeproj/xcuserdata/huynhdung.xcuserdatad/xcschemes/SDWebImageSwiftUI.xcscheme +0 -58
  213. package/example/ios/Pods/Pods.xcodeproj/xcuserdata/huynhdung.xcuserdatad/xcschemes/SkeletonUI.xcscheme +0 -58
  214. package/example/ios/Pods/Pods.xcodeproj/xcuserdata/huynhdung.xcuserdatad/xcschemes/xcschememanagement.plist +0 -46
  215. package/ios/Application/FontScaleStore.swift +0 -59
@@ -0,0 +1,176 @@
1
+ //
2
+ // NavigationContainer.swift
3
+ // MoMoUIKits
4
+ //
5
+ // SwiftUI mirror of Compose's NavigationContainer.
6
+ // Wraps NavigationStack, injects Navigator into the environment, and renders
7
+ // every registered screen inside `Screen(options)` chrome — same auto-wrap
8
+ // behavior as Compose's StackScreen.
9
+ //
10
+
11
+ import SwiftUI
12
+
13
+ @available(iOS 16.0, *)
14
+ public struct NavigationContainer<Initial: View>: View {
15
+ @StateObject private var navigator: Navigator
16
+ @StateObject private var applicationEnvironment: ApplicationEnvironment
17
+
18
+ private let setNavigator: ((Navigator) -> Void)?
19
+ private let composeApi: KitComposeApi?
20
+
21
+ public init(
22
+ initialScreenName: String = "",
23
+ @ViewBuilder initialScreen: @escaping () -> Initial,
24
+ options: NavigationOptions? = nil,
25
+ applicationContext: MiniAppContext? = nil,
26
+ composeApi: KitComposeApi? = nil,
27
+ config: KitConfig? = nil,
28
+ setNavigator: ((Navigator) -> Void)? = nil
29
+ ) {
30
+ let nav = Navigator(
31
+ initialScreenName: initialScreenName.isEmpty ? (options?.screenName ?? "") : initialScreenName,
32
+ initialContent: { AnyView(initialScreen()) },
33
+ options: options,
34
+ composeApi: composeApi
35
+ )
36
+ _navigator = StateObject(wrappedValue: nav)
37
+ _applicationEnvironment = StateObject(
38
+ wrappedValue: ApplicationEnvironment(
39
+ applicationContext: applicationContext,
40
+ composeApi: composeApi,
41
+ config: config
42
+ )
43
+ )
44
+ self.composeApi = composeApi
45
+ self.setNavigator = setNavigator
46
+ }
47
+
48
+ public var body: some View {
49
+ NavigationStack(path: $navigator.path) {
50
+ screenView(for: navigator.rootRoute)
51
+ .navigationDestination(for: DynamicScreenRoute.self) { route in
52
+ screenView(for: route)
53
+ }
54
+ }
55
+ .environmentObject(navigator)
56
+ .environmentObject(applicationEnvironment)
57
+ .environment(\.applicationEnvironment, applicationEnvironment)
58
+ .fullScreenCover(item: $navigator.presented) { route in
59
+ screenView(forDialog: route)
60
+ .environmentObject(navigator)
61
+ .environmentObject(applicationEnvironment)
62
+ .environment(\.applicationEnvironment, applicationEnvironment)
63
+ }
64
+ .overlay {
65
+ if let item = navigator.overplay {
66
+ OverplayHost(item: item)
67
+ .environmentObject(navigator)
68
+ .environmentObject(applicationEnvironment)
69
+ .environment(\.applicationEnvironment, applicationEnvironment)
70
+ }
71
+ }
72
+ .onAppear {
73
+ if navigator.composeApi == nil {
74
+ navigator.composeApi = composeApi
75
+ }
76
+ setNavigator?(navigator)
77
+ }
78
+ }
79
+
80
+ @ViewBuilder
81
+ private func screenView(for route: DynamicScreenRoute) -> some View {
82
+ if let screen = DynamicScreenRegistry.shared.getScreen(id: route.id) {
83
+ ScreenHost(screen: screen, navigator: navigator)
84
+ .navigationBarBackButtonHidden(true)
85
+ } else {
86
+ EmptyView()
87
+ }
88
+ }
89
+
90
+ @ViewBuilder
91
+ private func screenView(forDialog route: DynamicDialogRoute) -> some View {
92
+ if let screen = DynamicScreenRegistry.shared.getScreen(id: route.id) {
93
+ ScreenHost(screen: screen, navigator: navigator)
94
+ } else {
95
+ EmptyView()
96
+ }
97
+ }
98
+ }
99
+
100
+ // MARK: - ScreenHost
101
+
102
+ @available(iOS 16.0, *)
103
+ private struct ScreenHost: View {
104
+ let screen: DynamicScreen
105
+ let navigator: Navigator
106
+
107
+ var body: some View {
108
+ let options = screen.options ?? NavigationOptions()
109
+ StackScreen(
110
+ backgroundColor: options.backgroundColor,
111
+ headerTransparent: options.headerTransparent,
112
+ fullScreenContent: options.fullScreenContent,
113
+ tintColor: options.tintColor ?? Colors.black17,
114
+ isBack: !options.hiddenBack,
115
+ headerType: options.headerType,
116
+ useAnimated: options.useAnimated,
117
+ title: options.title,
118
+ headerTitle: options.headerTitle,
119
+ titlePosition: options.titlePosition,
120
+ goBack: options.hiddenBack ? nil : { navigator.onBackSafe() },
121
+ scrollable: options.scrollable,
122
+ scrollToTopCallback: options.scrollToTopCallback,
123
+ useAvoidKeyboard: options.useAvoidKeyboard,
124
+ keyboardShouldPersistTaps: options.keyboardShouldPersistTaps,
125
+ footer: options.footer,
126
+ headerRight: options.resolvedHeaderRight,
127
+ animatedHeader: options.animatedHeader,
128
+ layoutOffset: options.layoutOffset,
129
+ inputSearchProps: options.inputSearchProps,
130
+ fabProps: options.fabProps,
131
+ content: { screen.content() }
132
+ )
133
+ }
134
+ }
135
+
136
+ // MARK: - Overplay host
137
+
138
+ @available(iOS 16.0, *)
139
+ private struct OverplayHost: View {
140
+ let item: OverplayItem
141
+ @EnvironmentObject var navigator: Navigator
142
+
143
+ var body: some View {
144
+ // Each component self-animates on appear and drives its own exit through
145
+ // the Navigator before the item is removed (mirrors Compose's overplay).
146
+ switch item.type {
147
+ case .modal:
148
+ ModalScreen(barrierDismissible: item.barrierDismissible) {
149
+ item.content()
150
+ }
151
+ .id(item.id)
152
+ case .bottomSheet:
153
+ BottomSheetView(
154
+ header: item.header ?? .title(),
155
+ isSurface: item.isSurface,
156
+ barrierDismissible: item.barrierDismissible
157
+ ) {
158
+ item.content()
159
+ }
160
+ .id(item.id)
161
+ case .snackBar:
162
+ if let snackBar = item.snackBar {
163
+ SnackBarView(snackBar: snackBar, bottomInset: safeAreaBottomInset() + Spacing.S)
164
+ .id(item.id)
165
+ }
166
+ }
167
+ }
168
+ }
169
+
170
+ /// Bottom safe-area inset (home indicator), used to lift the snack bar.
171
+ @available(iOS 16.0, *)
172
+ private func safeAreaBottomInset() -> CGFloat {
173
+ UIApplication.shared.connectedScenes
174
+ .compactMap { ($0 as? UIWindowScene)?.keyWindow?.safeAreaInsets.bottom }
175
+ .first ?? 0
176
+ }
@@ -0,0 +1,109 @@
1
+ //
2
+ // NavigationOptions.swift
3
+ // MoMoUIKits
4
+ //
5
+ // SwiftUI mirror of Compose's NavigationOptions.
6
+ // Each option lines up with a parameter on the existing `Screen` view,
7
+ // so NavigationContainer can auto-wrap a registered screen body in `Screen(options)`.
8
+ //
9
+
10
+ import SwiftUI
11
+
12
+ public struct NavigationOptions {
13
+ public var screenName: String?
14
+ public var title: String
15
+ /// Rich header title (mirrors Compose's `headerTitle`). When set to `.user`
16
+ /// the header renders an avatar group instead of `title`; `.default` keeps
17
+ /// the plain `title` text.
18
+ public var headerTitle: HeaderTitle?
19
+ public var titlePosition: TitlePosition
20
+ public var headerType: HeaderType
21
+ /// Mirrors Compose's `HeaderType.Extended/Default(useAnimated = ...)`: when true
22
+ /// and `inputSearchProps` is set, the search bar animates into the header on scroll.
23
+ public var useAnimated: Bool
24
+ public var headerTransparent: Bool
25
+ public var fullScreenContent: Bool
26
+ public var hiddenBack: Bool
27
+ public var backgroundColor: Color?
28
+ public var tintColor: Color?
29
+ public var scrollable: Bool
30
+ /// Mirrors Compose's `ScrollData.scrollToTopCallback`: invoked when the
31
+ /// screen is asked to scroll to top (e.g. on a status-bar tap).
32
+ public var scrollToTopCallback: (() -> Void)?
33
+ public var useAvoidKeyboard: Bool
34
+ /// Mirrors Compose's `KeyboardOptions.keyboardShouldPersistTaps`: when true,
35
+ /// tapping anywhere on the screen dismisses the keyboard.
36
+ public var keyboardShouldPersistTaps: Bool
37
+ /// Mirrors Compose's `HeaderBackProps`: drives the prevent-back confirm popup.
38
+ public var headerBackProps: HeaderBackProps?
39
+ /// Typed toolkit data for the default header right control (mirrors
40
+ /// Compose's `HeaderRight.Toolkit`). Use `headerRight` for `.custom` and nil
41
+ /// for `.none`.
42
+ public var headerRightData: HeaderRightData?
43
+ public var headerRight: (() -> any View)?
44
+ public var footer: (() -> AnyView)?
45
+ public var animatedHeader: AnimatedHeader?
46
+ public var layoutOffset: CGFloat
47
+ public var inputSearchProps: InputSearchProps?
48
+ public var fabProps: FabProps?
49
+ public var onBackHandler: (() -> Void)?
50
+
51
+ public init(
52
+ screenName: String? = nil,
53
+ title: String = "Stack",
54
+ headerTitle: HeaderTitle? = nil,
55
+ titlePosition: TitlePosition = .left,
56
+ headerType: HeaderType = .default,
57
+ useAnimated: Bool = false,
58
+ headerTransparent: Bool = false,
59
+ fullScreenContent: Bool = false,
60
+ hiddenBack: Bool = false,
61
+ backgroundColor: Color? = nil,
62
+ tintColor: Color? = Colors.black17,
63
+ scrollable: Bool = true,
64
+ scrollToTopCallback: (() -> Void)? = nil,
65
+ useAvoidKeyboard: Bool = true,
66
+ keyboardShouldPersistTaps: Bool = false,
67
+ headerBackProps: HeaderBackProps? = nil,
68
+ headerRightData: HeaderRightData? = nil,
69
+ headerRight: (() -> any View)? = { HeaderRight() },
70
+ footer: (() -> AnyView)? = nil,
71
+ animatedHeader: AnimatedHeader? = nil,
72
+ layoutOffset: CGFloat = 56,
73
+ inputSearchProps: InputSearchProps? = nil,
74
+ fabProps: FabProps? = nil,
75
+ onBackHandler: (() -> Void)? = nil
76
+ ) {
77
+ self.screenName = screenName
78
+ self.title = title
79
+ self.headerTitle = headerTitle
80
+ self.titlePosition = titlePosition
81
+ self.headerType = headerType
82
+ self.useAnimated = useAnimated
83
+ self.headerTransparent = headerTransparent
84
+ self.fullScreenContent = fullScreenContent
85
+ self.hiddenBack = hiddenBack
86
+ self.backgroundColor = backgroundColor
87
+ self.tintColor = tintColor
88
+ self.scrollable = scrollable
89
+ self.scrollToTopCallback = scrollToTopCallback
90
+ self.useAvoidKeyboard = useAvoidKeyboard
91
+ self.keyboardShouldPersistTaps = keyboardShouldPersistTaps
92
+ self.headerBackProps = headerBackProps
93
+ self.headerRightData = headerRightData
94
+ self.headerRight = headerRight
95
+ self.footer = footer
96
+ self.animatedHeader = animatedHeader
97
+ self.layoutOffset = layoutOffset
98
+ self.inputSearchProps = inputSearchProps
99
+ self.fabProps = fabProps
100
+ self.onBackHandler = onBackHandler
101
+ }
102
+ }
103
+
104
+ extension NavigationOptions {
105
+ var resolvedHeaderRight: (() -> any View)? {
106
+ guard let headerRightData else { return headerRight }
107
+ return { HeaderRight(headerRight: headerRightData, tintColor: tintColor) }
108
+ }
109
+ }
@@ -0,0 +1,364 @@
1
+ //
2
+ // Navigator.swift
3
+ // MoMoUIKits
4
+ //
5
+ // SwiftUI mirror of Compose's Navigator + DynamicScreenRegistry.
6
+ // Screens are registered by Int id; the NavigationStack path stores routes
7
+ // by id and looks up content from the registry on render.
8
+ //
9
+
10
+ import SwiftUI
11
+ import Combine
12
+
13
+ // MARK: - Routes
14
+
15
+ public struct DynamicScreenRoute: Hashable, Identifiable {
16
+ public let id: Int
17
+ }
18
+
19
+ public struct DynamicDialogRoute: Hashable, Identifiable {
20
+ public let id: Int
21
+ }
22
+
23
+ // MARK: - Registry
24
+
25
+ public struct DynamicScreen {
26
+ public let id: Int
27
+ public let name: String
28
+ public let content: () -> AnyView
29
+ public var options: NavigationOptions?
30
+ }
31
+
32
+ public final class DynamicScreenRegistry {
33
+ public static let shared = DynamicScreenRegistry()
34
+
35
+ private var screens: [Int: DynamicScreen] = [:]
36
+ private var idCounter: Int = 1
37
+
38
+ private init() {}
39
+
40
+ @discardableResult
41
+ public func register(
42
+ screenName: String = "",
43
+ content: @escaping () -> AnyView,
44
+ options: NavigationOptions? = nil
45
+ ) -> DynamicScreenRoute {
46
+ let id = idCounter
47
+ idCounter += 1
48
+ screens[id] = DynamicScreen(id: id, name: screenName, content: content, options: options)
49
+ return DynamicScreenRoute(id: id)
50
+ }
51
+
52
+ public func unregister(id: Int) {
53
+ screens.removeValue(forKey: id)
54
+ }
55
+
56
+ public func unregisterAll() {
57
+ screens.removeAll()
58
+ }
59
+
60
+ public func getScreen(id: Int) -> DynamicScreen? { screens[id] }
61
+
62
+ public func latest() -> DynamicScreen? {
63
+ screens.max(by: { $0.key < $1.key })?.value
64
+ }
65
+
66
+ public func setOptions(id: Int, options: NavigationOptions) {
67
+ screens[id]?.options = options
68
+ }
69
+ }
70
+
71
+ // MARK: - Overplay
72
+
73
+ public enum OverplayType {
74
+ case modal, bottomSheet, snackBar
75
+ }
76
+
77
+ public struct OverplayItem: Identifiable {
78
+ public let id = UUID()
79
+ public let type: OverplayType
80
+ public let content: () -> AnyView
81
+ public let barrierDismissible: Bool
82
+ public let onDismiss: (() -> Void)?
83
+ // Bottom-sheet params (mirrors Compose's OverplayComponentParams.BottomSheet).
84
+ public var isSurface: Bool = false
85
+ public var header: BottomSheetHeader? = nil
86
+ // Snack-bar payload (mirrors Compose's SnackBar value).
87
+ public var snackBar: SnackBar? = nil
88
+ }
89
+
90
+ // MARK: - Navigator
91
+
92
+ @available(iOS 16.0, *)
93
+ public final class Navigator: ObservableObject {
94
+ @Published public var path: [DynamicScreenRoute] = []
95
+ @Published public var presented: DynamicDialogRoute?
96
+ @Published public var overplay: OverplayItem?
97
+
98
+ /// Animated-close handler registered by the active overplay component
99
+ /// (mirrors Compose's `OverplayComponentRegistry.bindClose`). When set, a
100
+ /// dismiss request runs the component's exit animation before the item is
101
+ /// actually removed via `finishOverplayDismiss`.
102
+ private var overplayDismissHandler: (() -> Void)?
103
+
104
+ public private(set) var rootRoute: DynamicScreenRoute
105
+ public var composeApi: KitComposeApi?
106
+
107
+ public init(
108
+ initialScreenName: String = "",
109
+ initialContent: @escaping () -> AnyView,
110
+ options: NavigationOptions? = nil,
111
+ composeApi: KitComposeApi? = nil
112
+ ) {
113
+ self.composeApi = composeApi
114
+ self.rootRoute = DynamicScreenRegistry.shared.register(
115
+ screenName: initialScreenName,
116
+ content: initialContent,
117
+ options: options
118
+ )
119
+ }
120
+
121
+ // MARK: Stack
122
+
123
+ public func push<V: View>(@ViewBuilder _ content: @escaping () -> V, options: NavigationOptions? = nil) {
124
+ let route = DynamicScreenRegistry.shared.register(
125
+ screenName: options?.screenName ?? "",
126
+ content: { AnyView(content()) },
127
+ options: options
128
+ )
129
+ path.append(route)
130
+ }
131
+
132
+ public func push<V: View>(
133
+ screenName: String,
134
+ @ViewBuilder _ content: @escaping () -> V,
135
+ options: NavigationOptions? = nil
136
+ ) {
137
+ let route = DynamicScreenRegistry.shared.register(
138
+ screenName: screenName,
139
+ content: { AnyView(content()) },
140
+ options: options
141
+ )
142
+ path.append(route)
143
+ }
144
+
145
+ public func replace<V: View>(@ViewBuilder _ content: @escaping () -> V, options: NavigationOptions? = nil) {
146
+ guard !path.isEmpty else { return }
147
+ let removed = path.removeLast()
148
+ DynamicScreenRegistry.shared.unregister(id: removed.id)
149
+ push(content, options: options)
150
+ }
151
+
152
+ public func replace<V: View>(
153
+ screenName: String,
154
+ @ViewBuilder _ content: @escaping () -> V,
155
+ options: NavigationOptions? = nil
156
+ ) {
157
+ guard !path.isEmpty else { return }
158
+ let removed = path.removeLast()
159
+ DynamicScreenRegistry.shared.unregister(id: removed.id)
160
+ push(screenName: screenName, content, options: options)
161
+ }
162
+
163
+ public func reset<V: View>(@ViewBuilder _ content: @escaping () -> V, options: NavigationOptions? = nil) {
164
+ for route in path { DynamicScreenRegistry.shared.unregister(id: route.id) }
165
+ DynamicScreenRegistry.shared.unregister(id: rootRoute.id)
166
+ path.removeAll()
167
+ let route = DynamicScreenRegistry.shared.register(
168
+ screenName: options?.screenName ?? "",
169
+ content: { AnyView(content()) },
170
+ options: options
171
+ )
172
+ rootRoute = route
173
+ }
174
+
175
+ public func reset<V: View>(
176
+ screenName: String,
177
+ @ViewBuilder _ content: @escaping () -> V,
178
+ options: NavigationOptions? = nil
179
+ ) {
180
+ for route in path { DynamicScreenRegistry.shared.unregister(id: route.id) }
181
+ DynamicScreenRegistry.shared.unregister(id: rootRoute.id)
182
+ path.removeAll()
183
+ let route = DynamicScreenRegistry.shared.register(
184
+ screenName: screenName,
185
+ content: { AnyView(content()) },
186
+ options: options
187
+ )
188
+ rootRoute = route
189
+ }
190
+
191
+ public func pop(_ count: Int = 1, callback: (() -> Void)? = nil) {
192
+ var remaining = count
193
+ while remaining > 0 {
194
+ if overplay != nil {
195
+ hideOverplay()
196
+ } else if presented != nil {
197
+ let dismissedId = presented?.id
198
+ presented = nil
199
+ if let id = dismissedId { DynamicScreenRegistry.shared.unregister(id: id) }
200
+ } else if !path.isEmpty {
201
+ let removed = path.removeLast()
202
+ DynamicScreenRegistry.shared.unregister(id: removed.id)
203
+ } else {
204
+ composeApi?.requestCallback(funcName: "dismiss", params: nil, onResponse: nil)
205
+ break
206
+ }
207
+ remaining -= 1
208
+ }
209
+ callback?()
210
+ }
211
+
212
+ public func popToRoot() {
213
+ for route in path { DynamicScreenRegistry.shared.unregister(id: route.id) }
214
+ path.removeAll()
215
+ }
216
+
217
+ public func onBackSafe(callback: (() -> Void)? = nil) {
218
+ let latest = DynamicScreenRegistry.shared.latest()
219
+ if let onBack = latest?.options?.onBackHandler {
220
+ onBack()
221
+ return
222
+ }
223
+ if let preventBack = latest?.options?.headerBackProps?.preventBack {
224
+ showModal {
225
+ PopupDisplay(
226
+ isPresented: .constant(true),
227
+ title: preventBack.title,
228
+ description: preventBack.description,
229
+ url: preventBack.image,
230
+ buttonDirection: preventBack.buttonDirection,
231
+ buttonType: .button,
232
+ actionButtonTitle: preventBack.primary?.title ?? "",
233
+ closeButtonTitle: preventBack.secondary?.title ?? "",
234
+ onPressAction: { [weak self] in
235
+ preventBack.primary?.onPress?()
236
+ // Close the popup, then leave the screen (matches Compose's pop(2)).
237
+ self?.pop(2, callback: callback)
238
+ },
239
+ onPressCloseButton: { [weak self] in
240
+ preventBack.secondary?.onPress?()
241
+ self?.hideOverplay()
242
+ },
243
+ onClose: { [weak self] in
244
+ preventBack.onIconClose?()
245
+ self?.hideOverplay()
246
+ },
247
+ errorCode: preventBack.error,
248
+ isShowCloseIcon: preventBack.isShowCloseIcon
249
+ )
250
+ }
251
+ return
252
+ }
253
+ pop(1, callback: callback)
254
+ }
255
+
256
+ // MARK: Modal-style screen (vertical slide)
257
+
258
+ public func present<V: View>(@ViewBuilder _ content: @escaping () -> V, options: NavigationOptions? = nil) {
259
+ let route = DynamicScreenRegistry.shared.register(
260
+ screenName: options?.screenName ?? "",
261
+ content: { AnyView(content()) },
262
+ options: options
263
+ )
264
+ presented = DynamicDialogRoute(id: route.id)
265
+ }
266
+
267
+ public func present<V: View>(
268
+ screenName: String,
269
+ @ViewBuilder _ content: @escaping () -> V,
270
+ options: NavigationOptions? = nil
271
+ ) {
272
+ let route = DynamicScreenRegistry.shared.register(
273
+ screenName: screenName,
274
+ content: { AnyView(content()) },
275
+ options: options
276
+ )
277
+ presented = DynamicDialogRoute(id: route.id)
278
+ }
279
+
280
+ public func dismiss() {
281
+ if let id = presented?.id {
282
+ DynamicScreenRegistry.shared.unregister(id: id)
283
+ }
284
+ presented = nil
285
+ }
286
+
287
+ // MARK: Overplay
288
+
289
+ public func showModal<V: View>(
290
+ @ViewBuilder _ content: @escaping () -> V,
291
+ barrierDismissible: Bool = true,
292
+ onDismiss: (() -> Void)? = nil
293
+ ) {
294
+ overplayDismissHandler = nil
295
+ overplay = OverplayItem(
296
+ type: .modal,
297
+ content: { AnyView(content()) },
298
+ barrierDismissible: barrierDismissible,
299
+ onDismiss: onDismiss
300
+ )
301
+ }
302
+
303
+ public func showBottomSheet<V: View>(
304
+ @ViewBuilder _ content: @escaping () -> V,
305
+ isSurface: Bool = false,
306
+ barrierDismissible: Bool = true,
307
+ header: BottomSheetHeader? = nil,
308
+ onDismiss: (() -> Void)? = nil
309
+ ) {
310
+ overplayDismissHandler = nil
311
+ overplay = OverplayItem(
312
+ type: .bottomSheet,
313
+ content: { AnyView(content()) },
314
+ barrierDismissible: barrierDismissible,
315
+ onDismiss: onDismiss,
316
+ isSurface: isSurface,
317
+ header: header
318
+ )
319
+ }
320
+
321
+ /// Mirrors Compose's `showSnackBar(snackBar:)`.
322
+ public func showSnackBar(_ snackBar: SnackBar, onDismiss: (() -> Void)? = nil) {
323
+ overplayDismissHandler = nil
324
+ overplay = OverplayItem(
325
+ type: .snackBar,
326
+ content: { AnyView(EmptyView()) },
327
+ barrierDismissible: false,
328
+ onDismiss: onDismiss,
329
+ snackBar: snackBar
330
+ )
331
+ }
332
+
333
+ // MARK: Overplay dismissal
334
+
335
+ /// Registered by the active overplay component so external dismiss requests
336
+ /// run its exit animation (mirrors Compose's `bindClose`).
337
+ public func registerOverplayDismiss(_ handler: @escaping () -> Void) {
338
+ overplayDismissHandler = handler
339
+ }
340
+
341
+ /// Removes the overplay and fires its `onDismiss` (mirrors Compose's
342
+ /// `hardClearAfterDismiss`). Called by a component once its exit animation
343
+ /// has completed.
344
+ public func finishOverplayDismiss() {
345
+ let dismissCallback = overplay?.onDismiss
346
+ overplayDismissHandler = nil
347
+ overplay = nil
348
+ dismissCallback?()
349
+ }
350
+
351
+ public func hideOverplay() {
352
+ if let close = overplayDismissHandler {
353
+ // Component runs its exit animation, then calls finishOverplayDismiss.
354
+ overplayDismissHandler = nil
355
+ close()
356
+ } else {
357
+ finishOverplayDismiss()
358
+ }
359
+ }
360
+
361
+ public func hideSnackBar() {
362
+ if overplay?.type == .snackBar { hideOverplay() }
363
+ }
364
+ }