@momo-kits/native-kits 0.162.2-sp.7 → 0.162.2-sp.8
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/settings.local.json +15 -1
- package/CLAUDE.md +78 -0
- package/ios/Application/ApplicationEnvironment.swift +4 -2
- package/ios/Application/Components.swift +16 -0
- package/ios/Application/Localize.swift +277 -0
- package/ios/Application/MaxApi.swift +18 -0
- package/ios/Application/Navigation/BottomTab/BottomTab.swift +1 -0
- package/ios/Application/Navigation/NavigationContainer.swift +27 -3
- package/ios/Application/Navigation/Navigator.swift +50 -29
- package/ios/Application/Navigation/Overplay/BottomSheet.swift +87 -19
- package/ios/Application/Navigation/Overplay/ModalScreen.swift +6 -0
- package/ios/Application/Navigation/Tracking/ScreenTracker.swift +117 -0
- package/ios/Application/Screen.swift +1 -1
- package/ios/Application/StackScreen.swift +49 -1
- package/ios/Badge/BadgeRibbon.swift +80 -0
- package/ios/Button/Button.swift +68 -12
- package/ios/Carousel/Carousel.swift +16 -1
- package/ios/Checkbox/Checkbox.swift +14 -20
- package/ios/Chip/Chip.swift +35 -26
- package/ios/Collapse/Collapse.swift +11 -1
- package/ios/Colors+Radius+Spacing/Colors.swift +9 -6
- package/ios/Colors+Radius+Spacing/Spacing.swift +3 -1
- package/ios/DateTimePicker/DateTimePicker.swift +4 -2
- package/ios/DateTimePicker/WheelPicker.swift +7 -3
- package/ios/Extensions/ActiveOpacityButtonStyle.swift +14 -0
- package/ios/Extensions/Color++.swift +5 -2
- package/ios/Icon/Icon.swift +5 -1
- package/ios/IconButton/IconButton.swift +35 -7
- package/ios/Image/Image.swift +16 -3
- package/ios/Information/Information.swift +3 -1
- package/ios/Input/ErrorView.swift +3 -1
- package/ios/Input/Input.swift +31 -8
- package/ios/Input/InputPhoneNumber.swift +14 -3
- package/ios/Input/InputSearch.swift +7 -1
- package/ios/Input/InputTextArea.swift +78 -34
- package/ios/InputDropDown/InputDropDown.swift +4 -1
- package/ios/InputMoney/InputMoney.swift +16 -4
- package/ios/PARITY_AUDIT.md +641 -0
- package/ios/Popup/PopupDisplay.swift +3 -4
- package/ios/Popup/PopupNotify.swift +3 -4
- package/ios/Popup/PopupPromotion.swift +16 -8
- package/ios/ProgressInfo/ProgressInfo.swift +4 -2
- package/ios/Radio/Radio.swift +12 -13
- package/ios/Rating/Rating.swift +1 -1
- package/ios/Stepper/Stepper.swift +2 -2
- package/ios/Steps/Steps.swift +22 -6
- package/ios/SuggestAction/SuggestAction.swift +5 -3
- package/ios/Swipeable/SwipeCell.swift +5 -3
- package/ios/Switch/Switch.swift +53 -28
- package/ios/TabView/TabView.swift +18 -14
- package/ios/Template/TrustBanner/TrustBanner.swift +6 -7
- package/ios/Tooltip/Tooltip.swift +3 -0
- package/ios/Typography/FontScaleStore.swift +19 -0
- package/ios/Typography/Text.swift +3 -0
- package/ios/Typography/Typography.swift +8 -5
- package/ios/Uploader/Uploader.swift +0 -9
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/package.json +1 -1
- package/ios/Colors+Radius+Spacing/MoMoUIKitsResources.swift +0 -2
|
@@ -49,7 +49,21 @@
|
|
|
49
49
|
"Bash(xcodebuild -workspace iosApp.xcworkspace -scheme MoMoUIKits -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14 Pro' build)",
|
|
50
50
|
"Bash(xcodebuild -workspace iosApp.xcworkspace -scheme MoMoUIKits -sdk iphonesimulator -destination 'platform=iOS Simulator,id=E6A899C0-098E-473A-95B8-A2BBD2D42A92' build)",
|
|
51
51
|
"Bash(xcodebuild -workspace iosApp.xcworkspace -scheme iosApp -sdk iphonesimulator -destination 'platform=iOS Simulator,id=E6A899C0-098E-473A-95B8-A2BBD2D42A92' build)",
|
|
52
|
-
"Bash(xcodebuild build *)"
|
|
52
|
+
"Bash(xcodebuild build *)",
|
|
53
|
+
"Bash(git stash *)",
|
|
54
|
+
"Bash(plutil -lint sample/iosApp/iosApp.xcodeproj/project.pbxproj)",
|
|
55
|
+
"Bash(git add *)",
|
|
56
|
+
"Bash(git commit -m 'feat: DS-646 [ci build] *)",
|
|
57
|
+
"Bash(git commit -q -m 'fix: DS-656 [ci build] *)",
|
|
58
|
+
"Bash(xargs git log --oneline -1)",
|
|
59
|
+
"Bash(git rev-list *)",
|
|
60
|
+
"Bash(git status *)",
|
|
61
|
+
"Bash(git rebase *)",
|
|
62
|
+
"Bash(git merge *)",
|
|
63
|
+
"Bash(git reset *)",
|
|
64
|
+
"Bash(awk '/^ *)",
|
|
65
|
+
"Bash(git ls-tree *)",
|
|
66
|
+
"Bash(awk *)"
|
|
53
67
|
]
|
|
54
68
|
}
|
|
55
69
|
}
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
Guidance for working in this repo. Keep it accurate — update it when structure or commands change.
|
|
4
|
+
|
|
5
|
+
## What this is
|
|
6
|
+
|
|
7
|
+
`momo-native-kits` — MoMo's design-system / UI-kit as a **Kotlin Multiplatform + Compose Multiplatform** library, published for Android (AAR/Maven) and iOS (static framework + CocoaPods). It is the Compose port of the React Native `momo-kits`. Consumed by mini-apps embedded in the host MoMo app.
|
|
8
|
+
|
|
9
|
+
- Artifact: `vn.momo.kits:kits` (version in `gradle.properties`). NPM mirror: `@momo-kits/native-kits`.
|
|
10
|
+
- Targets: `androidTarget` (JVM 17, compile/min/target SDK 36/24/36), `iosArm64`, `iosSimulatorArm64` (framework `baseName = "kits"`, `isStatic = true`).
|
|
11
|
+
- Kotlin 2.3.10, Compose MP 1.10.3.
|
|
12
|
+
|
|
13
|
+
## Modules
|
|
14
|
+
|
|
15
|
+
- `:compose` — the published library. All real code lives here.
|
|
16
|
+
- `:sample:shared` + `:sample:androidApp` — demo app (`UIKitHome` lists all components). iOS demo in `sample/iosApp` (Xcode).
|
|
17
|
+
|
|
18
|
+
## Source layout (`compose/src/commonMain/kotlin/vn/momo/kits/`)
|
|
19
|
+
|
|
20
|
+
- `components/` — ~50 UI components, **one file per component** (`Button.kt`, `Input*.kt`, `PopupNotify.kt`, …).
|
|
21
|
+
- `application/` — app-level context & config: `Context.kt` (CompositionLocals, `MiniAppContext`, `DesignSystemConfig`), `Localize.kt` (i18n: `LocalizationObject`, `Localize`, default dictionary), `Screen.kt`, header pieces. Also holds the **deprecated** `ApplicationContainer`.
|
|
22
|
+
- `navigation/` — `NavigationContainer.kt` (**canonical entry point**), `Navigator.kt`, `Navigation.kt`, `StackScreen.kt`, `bottomtab/`, `component/`, `tracking/`.
|
|
23
|
+
- `const/` — design tokens: `Theme.kt`, `Colors.kt`, `Typography.kt`, `Spacing.kt`, `Radius.kt`.
|
|
24
|
+
- `layout/`, `modifier/`, `utils/`.
|
|
25
|
+
- `platform/` — `Platform.kt` `expect` declarations, actualized in `androidMain` / `iosMain` (`Platform.android.kt`, `Platform.ios.kt`).
|
|
26
|
+
|
|
27
|
+
## Build & verify
|
|
28
|
+
|
|
29
|
+
No unit-test suite is configured. Validate changes by compiling the relevant target(s); use the sample app for visual checks.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
./gradlew :compose:compileCommonMainKotlinMetadata # validate commonMain (fast, do this first)
|
|
33
|
+
./gradlew :compose:compileDebugKotlinAndroid # Android target
|
|
34
|
+
./gradlew :compose:linkDebugFrameworkIosSimulatorArm64 # iOS framework (slow)
|
|
35
|
+
./gradlew :sample:androidApp:installDebug # run demo on device/emulator
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Publishing is automated (`publish.sh` + GitLab CI on `[ci build]` / `main`). Do not publish manually unless asked: `sh publish.sh beta` / `sh publish.sh release` (Maven→GitLab + NPM).
|
|
39
|
+
|
|
40
|
+
## Architecture essentials
|
|
41
|
+
|
|
42
|
+
- **Entry point:** wrap content in `NavigationContainer(...)` from `navigation/`. It builds the `Navigator`, takes a host-supplied `Localize` (falls back to an empty one), and provides the CompositionLocals below. **Do not use** `ApplicationContainer` (`application/NavigationContainer.kt`) — deprecated and does **not** wire `LocalLocalize` / `LocalNavigator` / `LocalMaxApi`.
|
|
43
|
+
- **Configuration flows via CompositionLocals**, not params. Public ones: `AppTheme`, `AppStatusBar`, `AppNavigationBar` (`const/Theme.kt`); `ApplicationContext`, `AppConfig`, `AppLanguage`, `LocalLocalize` (`application/`); `LocalNavigator`, `LocalMaxApi` (`navigation/`). Read with `X.current`.
|
|
44
|
+
- **Platform code** goes through `expect`/`actual` in `platform/` — never reference Android/iOS APIs from `commonMain` directly.
|
|
45
|
+
- **Native bridge:** `IMaxApi` (`vn.momo.maxapi`, exposed as `LocalMaxApi`) is the host-app bridge (dismiss, tracking, device info, language).
|
|
46
|
+
- Navigation uses a runtime `DynamicScreenRegistry`; overlays (modal/bottom-sheet/snackbar) go through `Navigator` + `OverplayComponentRegistry`.
|
|
47
|
+
|
|
48
|
+
## i18n / Localize (port of RN `Localize`)
|
|
49
|
+
|
|
50
|
+
- `application/Localize.kt`: everything i18n. `LocalizationObject` is a data class with required `vi` / `en` maps (`LocalizationObject(vi = mapOf(…), en = mapOf(…))`). `Localize` constructors take a `LocalizationObject` or a `(vi, en)` map pair; the constructor **merges** the kit defaults with the host data (host wins on key clash). Methods: `translate(key)` (missing/empty → returns the key), `translateData(map)` / `translateData(vi, en)`, `addTranslations` (existing keys win), `changeLanguage(lang)`. Default language `"vi"`, `"en"` only on exact match; language is snapshot state so a switch recomposes consumers.
|
|
51
|
+
- The default dictionary lives **inside `Localize`** (companion `defaultLanguage`), **generated 1:1 from `momo-kits` RN `Assets/language.json`** — do not hand-edit that block; edit the RN source and regenerate.
|
|
52
|
+
- The host creates one `Localize` and passes it in: `NavigationContainer(localize = myLocalize, …)`. There is **no** `language` param and `DesignSystemConfig` carries no translations — overrides go through the `Localize` constructor / `addTranslations`. Switch language at runtime with `myLocalize.changeLanguage("en")`.
|
|
53
|
+
- Access in a `@Composable`: `LocalLocalize.current.translate("errorCode")`. Language is host-controlled, never read from the OS locale. `AppLanguage` is still provided (derived from `Localize.currentLanguage`) for older components that read it.
|
|
54
|
+
- Some older components still do ad-hoc `AppLanguage.current` + `Map` lookups; new/changed code should use `LocalLocalize`.
|
|
55
|
+
|
|
56
|
+
## Code conventions
|
|
57
|
+
|
|
58
|
+
- **Tokens, not literals:** use `Colors`, `Typography`, `Spacing`, `Radius` objects and `AppTheme.current` for colors/styles. Per-component sizing is bundled in enums (e.g. `Button.Size(val value: ButtonSpecs)`).
|
|
59
|
+
- **Composable signatures:** required params first, slot lambdas next, `modifier: Modifier = Modifier` **last**; give optional params sensible defaults.
|
|
60
|
+
- **Stability:** annotate token/config data classes `@Stable`/`@Immutable`; memoize derived colors/styles/handlers with `remember(keys) { … }`.
|
|
61
|
+
- **Custom modifiers** are preferred: `conditional(...)`, `setAutomationId(...)`, the `clickable` variants in `modifier/`.
|
|
62
|
+
- Match the surrounding file's style when adding code.
|
|
63
|
+
|
|
64
|
+
## Writing docs in code (follow this)
|
|
65
|
+
|
|
66
|
+
Comments are **sparse and in English**. Document only what is **not obvious from the code** — non-obvious behavior, platform quirks, RN-parity semantics, memoization intent, or important gotchas worth flagging. Do **not**:
|
|
67
|
+
|
|
68
|
+
- write KDoc walls or restate what the signature/code already says;
|
|
69
|
+
- narrate obvious steps or add section-banner noise;
|
|
70
|
+
- use a language other than English in code comments.
|
|
71
|
+
|
|
72
|
+
Prefer one tight line at the surprising spot over a paragraph. Match the (low) comment density already in the codebase.
|
|
73
|
+
|
|
74
|
+
## Gotchas
|
|
75
|
+
|
|
76
|
+
- **Resource qualifier drift:** the generated Compose `Res` namespace is `vn.momo.uikits.resources`, but `utils/Resources.kt` and `platform/Platform.ios.kt` reference `vn.momo.compose.resources`. Keep bundled strings/dictionaries as plain Kotlin (the `defaultLanguage` map in `Localize.kt`), not `composeResources/values`, to avoid iOS framework resource-loading issues.
|
|
77
|
+
- Prefer `NavigationContainer` over the deprecated `ApplicationContainer`; prefer `IMaxApi`/`LocalMaxApi` over the deprecated `PlatformApi`.
|
|
78
|
+
- iOS strings/maps must survive Kotlin/Native framework packaging — keep them compiled-in, not loaded from resource bundles.
|
|
@@ -41,11 +41,13 @@ public class ApplicationEnvironment: ObservableObject {
|
|
|
41
41
|
let applicationContext: MiniAppContext?
|
|
42
42
|
let composeApi: KitComposeApi?
|
|
43
43
|
let config: KitConfig?
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
let maxApi: MaxApi?
|
|
45
|
+
|
|
46
|
+
public init(applicationContext: MiniAppContext? = nil, composeApi: KitComposeApi? = nil, config: KitConfig? = nil, maxApi: MaxApi? = nil) {
|
|
46
47
|
self.applicationContext = applicationContext
|
|
47
48
|
self.composeApi = composeApi
|
|
48
49
|
self.config = config
|
|
50
|
+
self.maxApi = maxApi
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -143,6 +143,22 @@ public struct HeaderRightWidthKey: PreferenceKey {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
// MARK: - Bottom-tab root preference
|
|
147
|
+
|
|
148
|
+
/// Set by `BottomTab` on appear so its enclosing `StackScreen` can detect that
|
|
149
|
+
/// it's hosting a self-contained bottom-tab surface and skip its own bottom
|
|
150
|
+
/// safe-area reservation — mirrors Compose's `Navigation.markAsBottomTabRoot()`
|
|
151
|
+
/// (`navigation.isBottomTabRoot`, read by `StackScreen.kt`'s `MainContent`).
|
|
152
|
+
/// Without this, `BottomTab`'s own internal safe-area handling gets an extra,
|
|
153
|
+
/// unwanted inset stacked on top of it by the outer `StackScreen`, pushing the
|
|
154
|
+
/// tab bar up higher than the true bottom inset.
|
|
155
|
+
public struct IsBottomTabRootKey: PreferenceKey {
|
|
156
|
+
public static var defaultValue: Bool = false
|
|
157
|
+
public static func reduce(value: inout Bool, nextValue: () -> Bool) {
|
|
158
|
+
value = value || nextValue()
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
146
162
|
// MARK: - Header View
|
|
147
163
|
|
|
148
164
|
public struct Header: View {
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Localize.swift
|
|
3
|
+
// MoMoUIKits
|
|
4
|
+
//
|
|
5
|
+
// SwiftUI mirror of Compose's `application/Localize.kt`, itself a port of
|
|
6
|
+
// momo-kits React Native's `Application/Localize.ts`. Holds the merged
|
|
7
|
+
// dictionary (kit defaults + host overrides) and the active language,
|
|
8
|
+
// switched at runtime via `changeLanguage`. `Localize` is an `ObservableObject`
|
|
9
|
+
// so a language switch republishes to consumers of `translate`/`translateData`,
|
|
10
|
+
// mirroring Compose's snapshot-state-backed `language`.
|
|
11
|
+
//
|
|
12
|
+
|
|
13
|
+
import Foundation
|
|
14
|
+
|
|
15
|
+
/// Translation dictionary keyed by language; both `vi` and `en` are required.
|
|
16
|
+
public struct LocalizationObject {
|
|
17
|
+
public var vi: [String: String]
|
|
18
|
+
public var en: [String: String]
|
|
19
|
+
|
|
20
|
+
public init(vi: [String: String] = [:], en: [String: String] = [:]) {
|
|
21
|
+
self.vi = vi
|
|
22
|
+
self.en = en
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public final class Localize: ObservableObject {
|
|
27
|
+
public static let VI = "vi"
|
|
28
|
+
public static let EN = "en"
|
|
29
|
+
|
|
30
|
+
private var assets: LocalizationObject
|
|
31
|
+
@Published public private(set) var currentLanguage: String = Localize.VI
|
|
32
|
+
|
|
33
|
+
public init(_ translations: LocalizationObject = LocalizationObject()) {
|
|
34
|
+
self.assets = Localize.merge(base: Localize.defaultLanguage, override: translations)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public func changeLanguage(_ language: String?) {
|
|
38
|
+
currentLanguage = (language == Localize.EN) ? Localize.EN : Localize.VI
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public func translate(_ key: String) -> String {
|
|
42
|
+
let dictionary = currentLanguage == Localize.EN ? assets.en : assets.vi
|
|
43
|
+
if let value = dictionary[key], !value.isEmpty { return value }
|
|
44
|
+
return key
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public func translateData(_ data: [String: String]) -> String {
|
|
48
|
+
if let value = data[currentLanguage] { return value }
|
|
49
|
+
let body = data.map { "\"\($0.key)\":\"\($0.value)\"" }.joined(separator: ",")
|
|
50
|
+
return "{\(body)}"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public func translateData(vi: String, en: String) -> String {
|
|
54
|
+
currentLanguage == Localize.EN ? en : vi
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// Existing keys win (mirrors Compose: `merge(translations, assets)`).
|
|
58
|
+
public func addTranslations(_ translations: LocalizationObject) {
|
|
59
|
+
assets = Localize.merge(base: translations, override: assets)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private static func merge(base: LocalizationObject, override: LocalizationObject) -> LocalizationObject {
|
|
63
|
+
LocalizationObject(
|
|
64
|
+
vi: base.vi.merging(override.vi) { _, new in new },
|
|
65
|
+
en: base.en.merging(override.en) { _, new in new }
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private static let defaultLanguage = LocalizationObject(
|
|
70
|
+
vi: [
|
|
71
|
+
"errorCode": "Mã lỗi: ",
|
|
72
|
+
"seeMore": "Xem thêm",
|
|
73
|
+
"cancel": "Huỷ",
|
|
74
|
+
"done": "Xong",
|
|
75
|
+
"confirm": "Xác nhận",
|
|
76
|
+
"month": "tháng",
|
|
77
|
+
"day": "ngày",
|
|
78
|
+
"choose": "Chọn",
|
|
79
|
+
"sent": "Đã gửi",
|
|
80
|
+
"received": "Đã tiếp nhận",
|
|
81
|
+
"processing": "Đang xử lý",
|
|
82
|
+
"processed": "Đã xử lý",
|
|
83
|
+
"addImg": "Thêm hình",
|
|
84
|
+
"chooseBtn": "Chọn button",
|
|
85
|
+
"imgEg": "Hình ảnh tham khảo",
|
|
86
|
+
"filter": "Sắp xếp",
|
|
87
|
+
"shipping": "Đang giao hàng",
|
|
88
|
+
"men": "Nam",
|
|
89
|
+
"women": "Nữ",
|
|
90
|
+
"more": "Khác",
|
|
91
|
+
"expDate": "Ngày hết hạn",
|
|
92
|
+
"exp": "HSD",
|
|
93
|
+
"inActive": "Chưa kích hoạt",
|
|
94
|
+
"voucherRemindHour": "Hết hạn sau {hours} giờ",
|
|
95
|
+
"voucherRemindMinute": "Hết hạn sau {minutes} phút",
|
|
96
|
+
"voucherRemindSecond": "Hết hạn sau {seconds} giây",
|
|
97
|
+
"voucherRemindDay": "Hết hạn sau {days} ngày",
|
|
98
|
+
"chooseRoundtrip": "Chọn vé khứ hồi",
|
|
99
|
+
"depart": "Ngày đi",
|
|
100
|
+
"return": "Ngày về",
|
|
101
|
+
"departing": "Đi",
|
|
102
|
+
"returning": "Về",
|
|
103
|
+
"jan": "Tháng 1",
|
|
104
|
+
"feb": "Tháng 2",
|
|
105
|
+
"mar": "Tháng 3",
|
|
106
|
+
"apr": "Tháng 4",
|
|
107
|
+
"may": "Tháng 5",
|
|
108
|
+
"jun": "Tháng 6",
|
|
109
|
+
"jul": "Tháng 7",
|
|
110
|
+
"aug": "Tháng 8",
|
|
111
|
+
"sep": "Tháng 9",
|
|
112
|
+
"oct": "Tháng 10",
|
|
113
|
+
"nov": "Tháng 11",
|
|
114
|
+
"dec": "Tháng 12",
|
|
115
|
+
"mon": "T2",
|
|
116
|
+
"tue": "T3",
|
|
117
|
+
"wed": "T4",
|
|
118
|
+
"thu": "T5",
|
|
119
|
+
"fri": "T6",
|
|
120
|
+
"sat": "T7",
|
|
121
|
+
"sun": "CN",
|
|
122
|
+
"showLunar": "Hiển thị lịch âm",
|
|
123
|
+
"newYear": "Tết Dương lịch",
|
|
124
|
+
"valentine": "Ngày Lễ Tình nhân",
|
|
125
|
+
"womenDay": "Ngày Quốc tế Phụ nữ",
|
|
126
|
+
"liberationDay": "Ngày giải phóng Miền Nam thống nhất đất nước",
|
|
127
|
+
"laborDay": "Ngày Quốc tế Lao động",
|
|
128
|
+
"childrenDay": "Ngày Quốc tế Thiếu nhi",
|
|
129
|
+
"nationalDay": "Quốc khánh nước CHXHCN Việt Nam",
|
|
130
|
+
"womenDayVN": "Ngày Phụ nữ Việt Nam",
|
|
131
|
+
"teacherDay": "Ngày Nhà giáo Việt Nam",
|
|
132
|
+
"christmasEve": "Ngày Lễ Giáng Sinh",
|
|
133
|
+
"christmas": "Ngày Lễ Giáng Sinh",
|
|
134
|
+
"lunarNewYear": "Tết Nguyên Đán",
|
|
135
|
+
"hungKingDay": "Giỗ Tổ Hùng Vương",
|
|
136
|
+
"balance": "Số dư trong ví",
|
|
137
|
+
"chooseDate": "Chọn ngày tháng năm",
|
|
138
|
+
"year": "năm",
|
|
139
|
+
"hour": "giờ",
|
|
140
|
+
"minute": "phút",
|
|
141
|
+
"from": "Từ",
|
|
142
|
+
"to": "Đến",
|
|
143
|
+
"connected": "Đã kết nối",
|
|
144
|
+
"disconnected": "Mất kết nối",
|
|
145
|
+
"hide": "Ẩn",
|
|
146
|
+
"viewAllTitle": "Xem tất cả",
|
|
147
|
+
"headerTitle": "Lịch sử thanh toán",
|
|
148
|
+
"SHORTEN": "THU GỌN",
|
|
149
|
+
"viewMoreBank": "XEM THÊM (${otherItemCount} ngân hàng)",
|
|
150
|
+
"transaction_success": "Thành công",
|
|
151
|
+
"transaction_fail": "Thất bại",
|
|
152
|
+
"transaction_processing": "Đang xử lý",
|
|
153
|
+
"viewMore": "Xem thêm",
|
|
154
|
+
"shorten": "Thu gọn",
|
|
155
|
+
"Payment": "Thanh toán ${serviceName}",
|
|
156
|
+
"currencyUnit": "đ",
|
|
157
|
+
"Month": "Tháng",
|
|
158
|
+
"save": "Lưu",
|
|
159
|
+
"favoriteIn": "Thêm dịch vụ yêu thích",
|
|
160
|
+
"favoriteOut": "Xóa dịch vụ yêu thích",
|
|
161
|
+
"deviceIn": "Thêm vào thiết bị",
|
|
162
|
+
"setting": "Cài đặt",
|
|
163
|
+
"transaction": "Lịch sử giao dịch",
|
|
164
|
+
"share": "Chia sẽ dịch vụ",
|
|
165
|
+
"information": "Thông tin chung",
|
|
166
|
+
"tutorial": "Hướng dẫn sử dụng",
|
|
167
|
+
"question": "Câu hỏi thường gặp",
|
|
168
|
+
"support": "Trung tâm hỗ trợ",
|
|
169
|
+
"skip": "Bỏ qua",
|
|
170
|
+
"enterPhoneNumber": "Vui lòng nhập số điện thoại",
|
|
171
|
+
"invalidPhoneNumber": "Số điện thoại không đúng",
|
|
172
|
+
],
|
|
173
|
+
en: [
|
|
174
|
+
"seeMore": "See more",
|
|
175
|
+
"cancel": "Cancel",
|
|
176
|
+
"done": "Done",
|
|
177
|
+
"confirm": "Confirm",
|
|
178
|
+
"month": "month",
|
|
179
|
+
"day": "day",
|
|
180
|
+
"choose": "Choose",
|
|
181
|
+
"sent": "Sent",
|
|
182
|
+
"received": "Received",
|
|
183
|
+
"processing": "Processing",
|
|
184
|
+
"processed": "Done",
|
|
185
|
+
"addImg": "Add image",
|
|
186
|
+
"chooseBtn": "Choose button",
|
|
187
|
+
"imgEg": "Example images",
|
|
188
|
+
"filter": "Filter",
|
|
189
|
+
"shipping": "Shipping",
|
|
190
|
+
"men": "Men",
|
|
191
|
+
"women": "Women",
|
|
192
|
+
"more": "More",
|
|
193
|
+
"expDate": "Expiration date",
|
|
194
|
+
"exp": "EXP",
|
|
195
|
+
"inActive": "Not Activated",
|
|
196
|
+
"voucherRemindHour": "Revoke after {hours} hours",
|
|
197
|
+
"voucherRemindMinute": "Revoke after {minutes} minutes",
|
|
198
|
+
"voucherRemindSecond": "Revoke after {seconds} seconds",
|
|
199
|
+
"voucherRemindDay": "Revoke after {days} days",
|
|
200
|
+
"chooseRoundtrip": "Choose roundtrip ticket",
|
|
201
|
+
"depart": "Departing",
|
|
202
|
+
"return": "Returning",
|
|
203
|
+
"departing": "De",
|
|
204
|
+
"returning": "Re",
|
|
205
|
+
"jan": "January",
|
|
206
|
+
"feb": "February",
|
|
207
|
+
"mar": "March",
|
|
208
|
+
"apr": "April",
|
|
209
|
+
"may": "May",
|
|
210
|
+
"jun": "June",
|
|
211
|
+
"jul": "July",
|
|
212
|
+
"aug": "August",
|
|
213
|
+
"sep": "September",
|
|
214
|
+
"oct": "October",
|
|
215
|
+
"nov": "November",
|
|
216
|
+
"dec": "December",
|
|
217
|
+
"mon": "Mon",
|
|
218
|
+
"tue": "Tue",
|
|
219
|
+
"wed": "Wed",
|
|
220
|
+
"thu": "Thu",
|
|
221
|
+
"fri": "Fri",
|
|
222
|
+
"sat": "Sat",
|
|
223
|
+
"sun": "Sun",
|
|
224
|
+
"showLunar": "Show Lunar Calendar",
|
|
225
|
+
"newYear": "New Year's Day",
|
|
226
|
+
"valentine": "Valentine's Day",
|
|
227
|
+
"womenDay": "International Women's Day",
|
|
228
|
+
"liberationDay": "Liberation Day",
|
|
229
|
+
"laborDay": "Internation Labor's Day",
|
|
230
|
+
"childrenDay": "International Labor's Day",
|
|
231
|
+
"nationalDay": "National Day",
|
|
232
|
+
"womenDayVN": "Vietnamese Women's Day",
|
|
233
|
+
"teacherDay": "Teacher's Day",
|
|
234
|
+
"christmasEve": "Christmas Eve",
|
|
235
|
+
"christmas": "Christmas Day",
|
|
236
|
+
"lunarNewYear": "Lunar New Year",
|
|
237
|
+
"hungKingDay": "Hung Kings' Festival",
|
|
238
|
+
"balance": "Wallet Balance",
|
|
239
|
+
"chooseDate": "Choose date",
|
|
240
|
+
"year": "year",
|
|
241
|
+
"hour": "hour",
|
|
242
|
+
"minute": "minute",
|
|
243
|
+
"from": "From",
|
|
244
|
+
"to": "To",
|
|
245
|
+
"connected": "Connected",
|
|
246
|
+
"disconnected": "Disconnected",
|
|
247
|
+
"hide": "Hide",
|
|
248
|
+
"viewAllTitle": "View all",
|
|
249
|
+
"headerTitle": "Transaction history",
|
|
250
|
+
"SHORTEN": "SHORTEN",
|
|
251
|
+
"viewMoreBank": "VIEW MORE (${otherItemCount} banks)",
|
|
252
|
+
"transaction_success": "Success",
|
|
253
|
+
"transaction_fail": "Fail",
|
|
254
|
+
"transaction_processing": "Processing",
|
|
255
|
+
"viewMore": "View more",
|
|
256
|
+
"shorten": "Shorten",
|
|
257
|
+
"Payment": "${serviceName} payment",
|
|
258
|
+
"currencyUnit": "VND",
|
|
259
|
+
"Month": "Month",
|
|
260
|
+
"save": "Save",
|
|
261
|
+
"favoriteIn": "Add to favorite services",
|
|
262
|
+
"favoriteOut": "Remove to favorite services",
|
|
263
|
+
"deviceIn": "Add to device",
|
|
264
|
+
"setting": "Settings",
|
|
265
|
+
"transaction": "Transaction History",
|
|
266
|
+
"share": "Share",
|
|
267
|
+
"information": "Information",
|
|
268
|
+
"tutorial": "Instruction",
|
|
269
|
+
"question": "FAQ",
|
|
270
|
+
"support": "Support center",
|
|
271
|
+
"errorCode": "Error code: ",
|
|
272
|
+
"skip": "Skip",
|
|
273
|
+
"enterPhoneNumber": "Please enter your phone number",
|
|
274
|
+
"invalidPhoneNumber": "Invalid phone number",
|
|
275
|
+
]
|
|
276
|
+
)
|
|
277
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MaxApi.swift
|
|
3
|
+
// MoMoUIKits
|
|
4
|
+
//
|
|
5
|
+
// Swift mirror of the host-app bridge exposed on Kotlin as `vn.momo.maxapi.IMaxApi`
|
|
6
|
+
// (`LocalMaxApi`). `IMaxApi` itself is an external compiled dependency with no
|
|
7
|
+
// source in this repo, so this protocol intentionally exposes only the methods
|
|
8
|
+
// this kit's Kotlin source actually calls (`track`, `dismiss`, `getLanguage`) —
|
|
9
|
+
// not a full guess at IMaxApi's real surface.
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
import Foundation
|
|
13
|
+
|
|
14
|
+
public protocol MaxApi {
|
|
15
|
+
func track(eventName: String, params: [String: Any?])
|
|
16
|
+
func dismiss(completion: (() -> Void)?)
|
|
17
|
+
func getLanguage(callback: @escaping ([String: Any?]?) -> Void)
|
|
18
|
+
}
|
|
@@ -14,9 +14,11 @@ import SwiftUI
|
|
|
14
14
|
public struct NavigationContainer<Initial: View>: View {
|
|
15
15
|
@StateObject private var navigator: Navigator
|
|
16
16
|
@StateObject private var applicationEnvironment: ApplicationEnvironment
|
|
17
|
+
@StateObject private var localize: Localize
|
|
17
18
|
|
|
18
19
|
private let setNavigator: ((Navigator) -> Void)?
|
|
19
20
|
private let composeApi: KitComposeApi?
|
|
21
|
+
private let maxApi: MaxApi?
|
|
20
22
|
|
|
21
23
|
public init(
|
|
22
24
|
initialScreenName: String = "",
|
|
@@ -25,6 +27,8 @@ public struct NavigationContainer<Initial: View>: View {
|
|
|
25
27
|
applicationContext: MiniAppContext? = nil,
|
|
26
28
|
composeApi: KitComposeApi? = nil,
|
|
27
29
|
config: KitConfig? = nil,
|
|
30
|
+
maxApi: MaxApi? = nil,
|
|
31
|
+
localize: Localize? = nil,
|
|
28
32
|
setNavigator: ((Navigator) -> Void)? = nil
|
|
29
33
|
) {
|
|
30
34
|
let nav = Navigator(
|
|
@@ -38,10 +42,13 @@ public struct NavigationContainer<Initial: View>: View {
|
|
|
38
42
|
wrappedValue: ApplicationEnvironment(
|
|
39
43
|
applicationContext: applicationContext,
|
|
40
44
|
composeApi: composeApi,
|
|
41
|
-
config: config
|
|
45
|
+
config: config,
|
|
46
|
+
maxApi: maxApi
|
|
42
47
|
)
|
|
43
48
|
)
|
|
49
|
+
_localize = StateObject(wrappedValue: localize ?? Localize())
|
|
44
50
|
self.composeApi = composeApi
|
|
51
|
+
self.maxApi = maxApi
|
|
45
52
|
self.setNavigator = setNavigator
|
|
46
53
|
}
|
|
47
54
|
|
|
@@ -55,11 +62,13 @@ public struct NavigationContainer<Initial: View>: View {
|
|
|
55
62
|
.environmentObject(navigator)
|
|
56
63
|
.environmentObject(applicationEnvironment)
|
|
57
64
|
.environment(\.applicationEnvironment, applicationEnvironment)
|
|
65
|
+
.environmentObject(localize)
|
|
58
66
|
.fullScreenCover(item: $navigator.presented) { route in
|
|
59
67
|
screenView(forDialog: route)
|
|
60
68
|
.environmentObject(navigator)
|
|
61
69
|
.environmentObject(applicationEnvironment)
|
|
62
70
|
.environment(\.applicationEnvironment, applicationEnvironment)
|
|
71
|
+
.environmentObject(localize)
|
|
63
72
|
}
|
|
64
73
|
.overlay {
|
|
65
74
|
if let item = navigator.overplay {
|
|
@@ -67,6 +76,7 @@ public struct NavigationContainer<Initial: View>: View {
|
|
|
67
76
|
.environmentObject(navigator)
|
|
68
77
|
.environmentObject(applicationEnvironment)
|
|
69
78
|
.environment(\.applicationEnvironment, applicationEnvironment)
|
|
79
|
+
.environmentObject(localize)
|
|
70
80
|
}
|
|
71
81
|
}
|
|
72
82
|
.onAppear {
|
|
@@ -74,12 +84,19 @@ public struct NavigationContainer<Initial: View>: View {
|
|
|
74
84
|
navigator.composeApi = composeApi
|
|
75
85
|
}
|
|
76
86
|
setNavigator?(navigator)
|
|
87
|
+
// Mirrors Compose's LaunchedEffect(maxApi, resolvedLocalize): host-reported
|
|
88
|
+
// language wins over the default "vi" only when it resolves to English.
|
|
89
|
+
maxApi?.getLanguage { data in
|
|
90
|
+
if parseLanguage(data) == Localize.EN {
|
|
91
|
+
localize.changeLanguage(Localize.EN)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
77
94
|
}
|
|
78
95
|
}
|
|
79
96
|
|
|
80
97
|
@ViewBuilder
|
|
81
98
|
private func screenView(for route: DynamicScreenRoute) -> some View {
|
|
82
|
-
if let screen =
|
|
99
|
+
if let screen = navigator.registry.getScreen(id: route.id) {
|
|
83
100
|
ScreenHost(screen: screen, navigator: navigator)
|
|
84
101
|
.navigationBarBackButtonHidden(true)
|
|
85
102
|
} else {
|
|
@@ -89,7 +106,7 @@ public struct NavigationContainer<Initial: View>: View {
|
|
|
89
106
|
|
|
90
107
|
@ViewBuilder
|
|
91
108
|
private func screenView(forDialog route: DynamicDialogRoute) -> some View {
|
|
92
|
-
if let screen =
|
|
109
|
+
if let screen = navigator.registry.getScreen(id: route.id) {
|
|
93
110
|
ScreenHost(screen: screen, navigator: navigator)
|
|
94
111
|
} else {
|
|
95
112
|
EmptyView()
|
|
@@ -128,6 +145,7 @@ private struct ScreenHost: View {
|
|
|
128
145
|
layoutOffset: options.layoutOffset,
|
|
129
146
|
inputSearchProps: options.inputSearchProps,
|
|
130
147
|
fabProps: options.fabProps,
|
|
148
|
+
screenName: screen.name,
|
|
131
149
|
content: { screen.content() }
|
|
132
150
|
)
|
|
133
151
|
}
|
|
@@ -174,3 +192,9 @@ private func safeAreaBottomInset() -> CGFloat {
|
|
|
174
192
|
.compactMap { ($0 as? UIWindowScene)?.keyWindow?.safeAreaInsets.bottom }
|
|
175
193
|
.first ?? 0
|
|
176
194
|
}
|
|
195
|
+
|
|
196
|
+
private func parseLanguage(_ raw: [String: Any?]?) -> String? {
|
|
197
|
+
guard let response = (raw?["response"] as? String)?.trimmingCharacters(in: .whitespaces).lowercased(),
|
|
198
|
+
!response.isEmpty else { return nil }
|
|
199
|
+
return response.hasPrefix(Localize.EN) ? Localize.EN : Localize.VI
|
|
200
|
+
}
|