@momo-kits/native-kits 0.162.2-sp.8-debug → 0.162.2-sp.9-debug
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compose/build.gradle.kts +1 -1
- package/compose/compose.podspec +1 -1
- package/gradle.properties +1 -1
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/Home.swift +1 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/LocalizeDemo.swift +188 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +2 -0
- package/package.json +1 -1
package/compose/build.gradle.kts
CHANGED
package/compose/compose.podspec
CHANGED
package/gradle.properties
CHANGED
package/ios/native-kits.podspec
CHANGED
|
@@ -89,6 +89,7 @@ public let ScreenUsages: [ScreenUsage] = [
|
|
|
89
89
|
ScreenUsage(title: "Bottom Tab", destination: AnyView(BottomTabDemo()), icon: getIcon(icon: "Layout")),
|
|
90
90
|
ScreenUsage(title: "Animated Header", destination: AnyView(AnimatedHeaderDemo()), icon: getIcon(icon: "Layout")),
|
|
91
91
|
ScreenUsage(title: "Theme", destination: AnyView(ThemeDemo()), icon: getIcon(icon: "Typography")),
|
|
92
|
+
ScreenUsage(title: "Localize", destination: AnyView(LocalizeDemo()), icon: getIcon(icon: "Typography")),
|
|
92
93
|
]
|
|
93
94
|
|
|
94
95
|
@available(iOS 16.0, *)
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
//
|
|
2
|
+
// LocalizeDemo.swift
|
|
3
|
+
// MoMoUIKitsDemo
|
|
4
|
+
//
|
|
5
|
+
// SwiftUI port of the Compose demo `sample/shared/.../screens/LocalizeUsage.kt`,
|
|
6
|
+
// showcasing the `Localize` i18n port (ios/Application/Localize.swift).
|
|
7
|
+
// Synced from sample/iosApp/iosApp/Demo/LocalizeDemo.swift.
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
import MoMoUIKits
|
|
11
|
+
import SwiftUI
|
|
12
|
+
|
|
13
|
+
// App-specific dictionary. Keys here do NOT exist in the kit defaults, so addTranslations
|
|
14
|
+
// registers them cleanly (addTranslations keeps existing keys on clash, host-default wins).
|
|
15
|
+
private let AppTranslations = LocalizationObject(
|
|
16
|
+
vi: [
|
|
17
|
+
"demo_greeting": "Xin chào MoMo!",
|
|
18
|
+
"demo_cart_title": "Giỏ hàng của bạn",
|
|
19
|
+
],
|
|
20
|
+
en: [
|
|
21
|
+
"demo_greeting": "Hello MoMo!",
|
|
22
|
+
"demo_cart_title": "Your cart",
|
|
23
|
+
]
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
struct LocalizeDemo: View {
|
|
27
|
+
@EnvironmentObject private var localize: Localize
|
|
28
|
+
|
|
29
|
+
private var isEnglish: Bool { localize.currentLanguage == Localize.EN }
|
|
30
|
+
|
|
31
|
+
var body: some View {
|
|
32
|
+
ScrollView {
|
|
33
|
+
VStack(alignment: .leading, spacing: 0) {
|
|
34
|
+
|
|
35
|
+
LocalizeSectionBox(title: "Đổi ngôn ngữ (toàn app)") {
|
|
36
|
+
MomoText(
|
|
37
|
+
"localize.changeLanguage(...) đổi ngôn ngữ cho cả NavigationContainer — mọi màn hình đang đọc translate() sẽ cập nhật theo.",
|
|
38
|
+
typography: .descriptionDefaultRegular
|
|
39
|
+
)
|
|
40
|
+
Switch(
|
|
41
|
+
.constant(isEnglish),
|
|
42
|
+
onChange: { _ in localize.changeLanguage(isEnglish ? Localize.VI : Localize.EN) },
|
|
43
|
+
title: "English"
|
|
44
|
+
)
|
|
45
|
+
MomoText("currentLanguage = \(localize.currentLanguage)", typography: .labelDefaultMedium)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
LocalizeSectionBox(title: "translate(key) — từ điển mặc định của kit") {
|
|
49
|
+
TranslationRow(key: "confirm", value: localize.translate("confirm"))
|
|
50
|
+
TranslationRow(key: "cancel", value: localize.translate("cancel"))
|
|
51
|
+
TranslationRow(key: "done", value: localize.translate("done"))
|
|
52
|
+
TranslationRow(key: "seeMore", value: localize.translate("seeMore"))
|
|
53
|
+
TranslationRow(key: "balance", value: localize.translate("balance"))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
LocalizeSectionBox(title: "Key thiếu → trả về chính key") {
|
|
57
|
+
MomoText(
|
|
58
|
+
"translate() với key không có (hoặc giá trị rỗng) sẽ trả lại đúng key để dễ phát hiện thiếu bản dịch.",
|
|
59
|
+
typography: .descriptionDefaultRegular
|
|
60
|
+
)
|
|
61
|
+
TranslationRow(key: "not_a_real_key", value: localize.translate("not_a_real_key"))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
LocalizeSectionBox(title: "Chèn tham số vào bản dịch") {
|
|
65
|
+
MomoText(
|
|
66
|
+
"Bản port không tự nội suy {placeholder} — tự replace ở nơi dùng.",
|
|
67
|
+
typography: .descriptionDefaultRegular
|
|
68
|
+
)
|
|
69
|
+
TranslationRow(
|
|
70
|
+
key: "voucherRemindHour",
|
|
71
|
+
value: localize.translate("voucherRemindHour").replacingOccurrences(of: "{hours}", with: "3")
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
LocalizeSectionBox(title: "translateData(vi:en:) — dịch nội tuyến") {
|
|
76
|
+
MomoText(
|
|
77
|
+
"Cho chuỗi dùng một lần, không cần khai báo key trong từ điển.",
|
|
78
|
+
typography: .descriptionDefaultRegular
|
|
79
|
+
)
|
|
80
|
+
MomoText(localize.translateData(vi: "Thanh toán ngay", en: "Pay now"), typography: .headerDefaultBold)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
LocalizeSectionBox(title: "translateData(map) — chọn theo ngôn ngữ") {
|
|
84
|
+
MomoText(
|
|
85
|
+
localize.translateData([
|
|
86
|
+
Localize.VI: "Lịch sử giao dịch",
|
|
87
|
+
Localize.EN: "Transaction history",
|
|
88
|
+
]),
|
|
89
|
+
typography: .headerDefaultBold
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
LocalizeSectionBox(title: "addTranslations — từ điển riêng của app") {
|
|
94
|
+
MomoText(
|
|
95
|
+
"Host đăng ký key riêng (đã add khi màn hình xuất hiện), rồi dùng translate() như key mặc định.",
|
|
96
|
+
typography: .descriptionDefaultRegular
|
|
97
|
+
)
|
|
98
|
+
TranslationRow(key: "demo_greeting", value: localize.translate("demo_greeting"))
|
|
99
|
+
TranslationRow(key: "demo_cart_title", value: localize.translate("demo_cart_title"))
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
LocalizeSectionBox(title: "Ví dụ thực tế") {
|
|
103
|
+
// errorCode already ends with a separator ("Mã lỗi: " / "Error code: ").
|
|
104
|
+
MomoText(localize.translate("errorCode") + "E-4097", typography: .bodyDefaultRegular)
|
|
105
|
+
HStack(spacing: Spacing.M) {
|
|
106
|
+
Button(
|
|
107
|
+
title: localize.translate("cancel"),
|
|
108
|
+
action: {},
|
|
109
|
+
type: .outline,
|
|
110
|
+
size: .medium,
|
|
111
|
+
isFull: false
|
|
112
|
+
)
|
|
113
|
+
Button(
|
|
114
|
+
title: localize.translate("confirm"),
|
|
115
|
+
action: {},
|
|
116
|
+
type: .primary,
|
|
117
|
+
size: .medium,
|
|
118
|
+
isFull: false
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
Spacer(minLength: 32)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Registers the app-specific dictionary once per appearance; addTranslations'
|
|
127
|
+
// merge is idempotent, so re-entry (e.g. re-navigating back to this screen) is safe.
|
|
128
|
+
.onAppear {
|
|
129
|
+
localize.addTranslations(AppTranslations)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// MARK: - LocalizeSectionBox
|
|
135
|
+
|
|
136
|
+
/// Titled rounded-card section container, mirroring Compose's `BasicColumnBox`
|
|
137
|
+
/// (title label above a `theme.colors.background.surface` card with `Radius.M` corners).
|
|
138
|
+
private struct LocalizeSectionBox<Content: View>: View {
|
|
139
|
+
@Environment(\.appTheme) private var theme
|
|
140
|
+
let title: String
|
|
141
|
+
@ViewBuilder let content: () -> Content
|
|
142
|
+
|
|
143
|
+
var body: some View {
|
|
144
|
+
VStack(alignment: .leading, spacing: 8) {
|
|
145
|
+
if !title.isEmpty {
|
|
146
|
+
MomoText(title, typography: .headerMBold)
|
|
147
|
+
.padding(.top, 8)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
VStack(alignment: .leading, spacing: 8) {
|
|
151
|
+
content()
|
|
152
|
+
}
|
|
153
|
+
.frame(maxWidth: .infinity, alignment: .leading)
|
|
154
|
+
.padding(12)
|
|
155
|
+
.background(theme.colors.background.surface)
|
|
156
|
+
.clipShape(RoundedRectangle(cornerRadius: Radius.M))
|
|
157
|
+
}
|
|
158
|
+
.padding(12)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// MARK: - TranslationRow
|
|
163
|
+
|
|
164
|
+
private struct TranslationRow: View {
|
|
165
|
+
@Environment(\.appTheme) private var theme
|
|
166
|
+
let key: String
|
|
167
|
+
let value: String
|
|
168
|
+
|
|
169
|
+
var body: some View {
|
|
170
|
+
VStack(alignment: .leading, spacing: 2) {
|
|
171
|
+
MomoText(key, typography: .labelDefaultMedium, color: theme.colors.text.secondary)
|
|
172
|
+
MomoText(value, typography: .bodyDefaultRegular)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// MARK: - Preview
|
|
178
|
+
|
|
179
|
+
#Preview {
|
|
180
|
+
if #available(iOS 16.0, *) {
|
|
181
|
+
NavigationStack {
|
|
182
|
+
LocalizeDemo()
|
|
183
|
+
.environmentObject(Localize())
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
// Fallback on earlier versions
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -23,6 +23,7 @@ struct NavigationDemo: View {
|
|
|
23
23
|
@available(iOS 16.0, *)
|
|
24
24
|
private struct NavigationDemoContent: View {
|
|
25
25
|
@EnvironmentObject private var navigator: Navigator
|
|
26
|
+
@State private var textValue1 = ""
|
|
26
27
|
|
|
27
28
|
var body: some View {
|
|
28
29
|
ScrollView {
|
|
@@ -72,6 +73,7 @@ private struct NavigationDemoContent: View {
|
|
|
72
73
|
row("Show Bottom Sheet") {
|
|
73
74
|
navigator.showBottomSheet({
|
|
74
75
|
VStack(spacing: 12) {
|
|
76
|
+
Input(text: $textValue1, placeholder: "Test Bottom Sheet")
|
|
75
77
|
ForEach(0..<4, id: \.self) { i in
|
|
76
78
|
MomoText("Bottom sheet row \(i + 1)")
|
|
77
79
|
.frame(maxWidth: .infinity, alignment: .leading)
|