@momo-kits/native-kits 0.161.2-beta.26-debug → 0.161.2-beta.27-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/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +19 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +62 -58
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +34 -1
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +16 -2
- package/gradle.properties +1 -1
- package/package.json +1 -1
package/compose/build.gradle.kts
CHANGED
package/compose/compose.podspec
CHANGED
|
@@ -8,25 +8,22 @@ import android.graphics.PorterDuffColorFilter
|
|
|
8
8
|
import android.os.Build
|
|
9
9
|
import androidx.compose.foundation.layout.Box
|
|
10
10
|
import androidx.compose.runtime.Composable
|
|
11
|
+
import androidx.compose.runtime.ProvidedValue
|
|
11
12
|
import androidx.compose.runtime.getValue
|
|
12
13
|
import androidx.compose.ui.Modifier
|
|
13
14
|
import androidx.compose.ui.graphics.Color
|
|
14
15
|
import androidx.compose.ui.graphics.NativePaint
|
|
15
16
|
import androidx.compose.ui.graphics.toArgb
|
|
16
17
|
import androidx.compose.ui.platform.LocalConfiguration
|
|
18
|
+
import androidx.compose.ui.platform.LocalResources
|
|
17
19
|
import androidx.compose.ui.unit.Dp
|
|
18
20
|
import androidx.compose.ui.unit.dp
|
|
19
21
|
import com.airbnb.lottie.LottieProperty
|
|
20
|
-
import com.airbnb.lottie.compose
|
|
21
|
-
import com.airbnb.lottie.compose.LottieCompositionSpec
|
|
22
|
-
import com.airbnb.lottie.compose.LottieConstants
|
|
23
|
-
import com.airbnb.lottie.compose.rememberLottieComposition
|
|
24
|
-
import com.airbnb.lottie.compose.rememberLottieDynamicProperties
|
|
25
|
-
import com.airbnb.lottie.compose.rememberLottieDynamicProperty
|
|
22
|
+
import com.airbnb.lottie.compose.*
|
|
26
23
|
import vn.momo.kits.const.AppNavigationBar
|
|
27
24
|
import vn.momo.kits.const.AppStatusBar
|
|
28
25
|
import vn.momo.kits.utils.readJson
|
|
29
|
-
import java.util
|
|
26
|
+
import java.util.*
|
|
30
27
|
import androidx.activity.compose.BackHandler as AndroidBackHandler
|
|
31
28
|
|
|
32
29
|
actual fun getPlatformName(): String = "Android"
|
|
@@ -121,7 +118,19 @@ actual fun NativePaint.setColor(color: Color){
|
|
|
121
118
|
this.color = color.toArgb()
|
|
122
119
|
}
|
|
123
120
|
|
|
124
|
-
actual
|
|
125
|
-
val
|
|
126
|
-
|
|
121
|
+
actual object LocalAppLocale {
|
|
122
|
+
actual val current: String
|
|
123
|
+
@Composable
|
|
124
|
+
get() = Locale.getDefault().toString()
|
|
125
|
+
|
|
126
|
+
@Composable
|
|
127
|
+
actual infix fun provides(value: String?): ProvidedValue<*> {
|
|
128
|
+
val configuration = LocalConfiguration.current
|
|
129
|
+
val new = Locale(value ?: DEFAULT_LANGUAGE)
|
|
130
|
+
Locale.setDefault(new)
|
|
131
|
+
configuration.setLocale(new)
|
|
132
|
+
val resources = LocalResources.current
|
|
133
|
+
resources.updateConfiguration(configuration, resources.displayMetrics)
|
|
134
|
+
return LocalConfiguration.provides(configuration)
|
|
135
|
+
}
|
|
127
136
|
}
|
|
@@ -11,8 +11,9 @@ import androidx.navigation.compose.rememberNavController
|
|
|
11
11
|
import androidx.navigation.toRoute
|
|
12
12
|
import vn.momo.kits.application.*
|
|
13
13
|
import vn.momo.kits.const.*
|
|
14
|
+
import vn.momo.kits.platform.DEFAULT_LANGUAGE
|
|
15
|
+
import vn.momo.kits.platform.ProvideAppLocale
|
|
14
16
|
import vn.momo.kits.platform.ProvideNavigationEventDispatcherOwner
|
|
15
|
-
import vn.momo.kits.platform.setLocale
|
|
16
17
|
import vn.momo.kits.utils.getAppStatusBarHeight
|
|
17
18
|
import vn.momo.kits.utils.getNavigationBarHeight
|
|
18
19
|
import vn.momo.maxapi.IMaxApi
|
|
@@ -39,12 +40,13 @@ fun NavigationContainer(
|
|
|
39
40
|
val mergedContext = MiniAppContext.merge(parentContext, applicationContext)
|
|
40
41
|
|
|
41
42
|
val theme = remember { mutableStateOf(initialTheme) }
|
|
43
|
+
val appLanguage = remember { mutableStateOf(language ?: DEFAULT_LANGUAGE) }
|
|
42
44
|
|
|
43
45
|
LaunchedEffect(Unit) {
|
|
44
|
-
language
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
if (language == null) {
|
|
47
|
+
maxApi?.getLanguage { response ->
|
|
48
|
+
(response?.get("response") as? String)?.let { appLanguage.value = it }
|
|
49
|
+
}
|
|
48
50
|
}
|
|
49
51
|
val headerBar = config?.headerBar
|
|
50
52
|
if (headerBar != null && theme.value.assets.headerBackground == null) {
|
|
@@ -69,69 +71,71 @@ fun NavigationContainer(
|
|
|
69
71
|
AppNavigationBar provides navigationBarHeight,
|
|
70
72
|
ApplicationContext provides mergedContext,
|
|
71
73
|
AppConfig provides config,
|
|
72
|
-
AppLanguage provides
|
|
74
|
+
AppLanguage provides appLanguage.value,
|
|
73
75
|
ScaleSizeMaxRate provides mergedContext?.scaleSizeMaxRate,
|
|
74
76
|
) {
|
|
75
77
|
LaunchedEffect(Unit) {
|
|
76
78
|
setNavigator?.invoke(navigator)
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
81
|
+
ProvideAppLocale(appLanguage.value) {
|
|
82
|
+
NavHost(navController, startDestination = startDestination) {
|
|
83
|
+
composable<DynamicScreenRoute>(
|
|
84
|
+
enterTransition = {
|
|
85
|
+
slideInHorizontally(
|
|
86
|
+
animationSpec = tween(300),
|
|
87
|
+
initialOffsetX = { it }
|
|
88
|
+
)
|
|
89
|
+
},
|
|
90
|
+
exitTransition = null,
|
|
91
|
+
popEnterTransition = { fadeIn(animationSpec = tween(0)) },
|
|
92
|
+
popExitTransition = {
|
|
93
|
+
slideOutHorizontally(
|
|
94
|
+
animationSpec = tween(300),
|
|
95
|
+
targetOffsetX = { it }
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
) { backStackEntry ->
|
|
99
|
+
val route = backStackEntry.toRoute<DynamicScreenRoute>()
|
|
100
|
+
val screen = DynamicScreenRegistry.getScreen(route.id)
|
|
98
101
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
if (screen != null) {
|
|
103
|
+
StackScreen(
|
|
104
|
+
id = route.id,
|
|
105
|
+
name = screen.name,
|
|
106
|
+
content = screen.content,
|
|
107
|
+
navigationOptions = screen.options
|
|
108
|
+
)
|
|
109
|
+
}
|
|
106
110
|
}
|
|
107
|
-
}
|
|
108
111
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
112
|
+
composable<DynamicDialogRoute>(
|
|
113
|
+
enterTransition = {
|
|
114
|
+
slideInVertically(
|
|
115
|
+
animationSpec = tween(300),
|
|
116
|
+
initialOffsetY = { it }
|
|
117
|
+
)
|
|
118
|
+
},
|
|
119
|
+
exitTransition = null,
|
|
120
|
+
popEnterTransition = { fadeIn(animationSpec = tween(0)) },
|
|
121
|
+
popExitTransition = {
|
|
122
|
+
slideOutVertically(
|
|
123
|
+
animationSpec = tween(300),
|
|
124
|
+
targetOffsetY = { it }
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
) { backStackEntry ->
|
|
128
|
+
val route = backStackEntry.toRoute<DynamicDialogRoute>()
|
|
129
|
+
val screen = DynamicScreenRegistry.getScreen(route.id)
|
|
127
130
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
if (screen != null) {
|
|
132
|
+
StackScreen(
|
|
133
|
+
id = route.id,
|
|
134
|
+
name = screen.name,
|
|
135
|
+
content = screen.content,
|
|
136
|
+
navigationOptions = screen.options
|
|
137
|
+
)
|
|
138
|
+
}
|
|
135
139
|
}
|
|
136
140
|
}
|
|
137
141
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
package vn.momo.kits.platform
|
|
2
2
|
|
|
3
3
|
import androidx.compose.runtime.Composable
|
|
4
|
+
import androidx.compose.runtime.CompositionLocalProvider
|
|
5
|
+
import androidx.compose.runtime.ProvidedValue
|
|
6
|
+
import androidx.compose.runtime.key
|
|
4
7
|
import androidx.compose.ui.Modifier
|
|
5
8
|
import androidx.compose.ui.graphics.Color
|
|
6
9
|
import androidx.compose.ui.graphics.NativePaint
|
|
@@ -65,4 +68,34 @@ expect fun NativePaint.setColor(
|
|
|
65
68
|
color: Color = Color.Black
|
|
66
69
|
)
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
/** Ngôn ngữ fallback mặc định của kit khi không xác định được ngôn ngữ: tiếng Việt. */
|
|
72
|
+
const val DEFAULT_LANGUAGE = "vi"
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Platform override cho ngôn ngữ mà Compose Resources (stringResource) sử dụng.
|
|
76
|
+
* Pattern theo tài liệu:
|
|
77
|
+
* https://kotlinlang.org/docs/multiplatform/compose-resource-environment.html
|
|
78
|
+
*/
|
|
79
|
+
expect object LocalAppLocale {
|
|
80
|
+
val current: String
|
|
81
|
+
@Composable get
|
|
82
|
+
|
|
83
|
+
@Composable
|
|
84
|
+
infix fun provides(value: String?): ProvidedValue<*>
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Bọc [content] để ép Compose Resources resolve theo [language].
|
|
89
|
+
*
|
|
90
|
+
* `key(language)` buộc recompose toàn bộ subtree khi ngôn ngữ thay đổi, nhờ đó
|
|
91
|
+
* các lời gọi stringResource() đã render trước đó được resolve lại đúng ngôn ngữ.
|
|
92
|
+
* `language == null` nghĩa là dùng locale mặc định của thiết bị.
|
|
93
|
+
*/
|
|
94
|
+
@Composable
|
|
95
|
+
fun ProvideAppLocale(language: String?, content: @Composable () -> Unit) {
|
|
96
|
+
CompositionLocalProvider(LocalAppLocale provides language) {
|
|
97
|
+
key(language) {
|
|
98
|
+
content()
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -8,10 +8,12 @@ import androidx.compose.foundation.layout.systemBars
|
|
|
8
8
|
import androidx.compose.runtime.Composable
|
|
9
9
|
import androidx.compose.runtime.CompositionLocalProvider
|
|
10
10
|
import androidx.compose.runtime.LaunchedEffect
|
|
11
|
+
import androidx.compose.runtime.ProvidedValue
|
|
11
12
|
import androidx.compose.runtime.getValue
|
|
12
13
|
import androidx.compose.runtime.mutableStateOf
|
|
13
14
|
import androidx.compose.runtime.remember
|
|
14
15
|
import androidx.compose.runtime.setValue
|
|
16
|
+
import androidx.compose.runtime.staticCompositionLocalOf
|
|
15
17
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
|
16
18
|
import androidx.compose.ui.InternalComposeUiApi
|
|
17
19
|
import androidx.compose.ui.Modifier
|
|
@@ -186,6 +188,18 @@ actual fun NativePaint.setColor(color: Color){
|
|
|
186
188
|
this.color = color.toArgb()
|
|
187
189
|
}
|
|
188
190
|
|
|
189
|
-
actual
|
|
190
|
-
|
|
191
|
+
actual object LocalAppLocale {
|
|
192
|
+
private const val LANG_KEY = "AppleLanguages"
|
|
193
|
+
private val localAppLocale = staticCompositionLocalOf { DEFAULT_LANGUAGE }
|
|
194
|
+
|
|
195
|
+
actual val current: String
|
|
196
|
+
@Composable
|
|
197
|
+
get() = localAppLocale.current
|
|
198
|
+
|
|
199
|
+
@Composable
|
|
200
|
+
actual infix fun provides(value: String?): ProvidedValue<*> {
|
|
201
|
+
val new = value ?: DEFAULT_LANGUAGE
|
|
202
|
+
NSUserDefaults.standardUserDefaults.setObject(arrayListOf(new), LANG_KEY)
|
|
203
|
+
return localAppLocale.provides(new)
|
|
204
|
+
}
|
|
191
205
|
}
|
package/gradle.properties
CHANGED