@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.
@@ -40,7 +40,7 @@ kotlin {
40
40
  }
41
41
 
42
42
  cocoapods {
43
- version = "0.161.2-beta.26-debug"
43
+ version = "0.161.2-beta.27-debug"
44
44
  summary = "IOS Shared module"
45
45
  homepage = "https://momo.vn"
46
46
  ios.deploymentTarget = "15.0"
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |spec|
2
2
  spec.name = 'compose'
3
- spec.version = '0.162.1'
3
+ spec.version = '0.161.2-beta.26'
4
4
  spec.homepage = 'https://momo.vn'
5
5
  spec.source = { :http=> ''}
6
6
  spec.authors = ''
@@ -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.LottieAnimation
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.Locale
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 fun setLocale(language: String) {
125
- val locale = Locale(language)
126
- Locale.setDefault(locale)
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?.let { setLocale(it) }
45
- maxApi?.getLanguage { response ->
46
- val lang = response?.get("response") as? String ?: "vi"
47
- setLocale(lang)
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 language,
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
- NavHost(navController, startDestination = startDestination) {
80
- composable<DynamicScreenRoute>(
81
- enterTransition = {
82
- slideInHorizontally(
83
- animationSpec = tween(300),
84
- initialOffsetX = { it }
85
- )
86
- },
87
- exitTransition = null,
88
- popEnterTransition = { fadeIn(animationSpec = tween(0)) },
89
- popExitTransition = {
90
- slideOutHorizontally(
91
- animationSpec = tween(300),
92
- targetOffsetX = { it }
93
- )
94
- }
95
- ) { backStackEntry ->
96
- val route = backStackEntry.toRoute<DynamicScreenRoute>()
97
- val screen = DynamicScreenRegistry.getScreen(route.id)
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
- if (screen != null) {
100
- StackScreen(
101
- id = route.id,
102
- name = screen.name,
103
- content = screen.content,
104
- navigationOptions = screen.options
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
- composable<DynamicDialogRoute>(
110
- enterTransition = {
111
- slideInVertically(
112
- animationSpec = tween(300),
113
- initialOffsetY = { it }
114
- )
115
- },
116
- exitTransition = null,
117
- popEnterTransition = { fadeIn(animationSpec = tween(0)) },
118
- popExitTransition = {
119
- slideOutVertically(
120
- animationSpec = tween(300),
121
- targetOffsetY = { it }
122
- )
123
- }
124
- ) { backStackEntry ->
125
- val route = backStackEntry.toRoute<DynamicDialogRoute>()
126
- val screen = DynamicScreenRegistry.getScreen(route.id)
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
- if (screen != null) {
129
- StackScreen(
130
- id = route.id,
131
- name = screen.name,
132
- content = screen.content,
133
- navigationOptions = screen.options
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
- expect fun setLocale(language: String)
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 fun setLocale(language: String) {
190
- NSUserDefaults.standardUserDefaults.setObject(arrayListOf(language), "AppleLanguages")
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
@@ -18,7 +18,7 @@ kotlin.apple.xcodeCompatibility.nowarn=true
18
18
  name="ComposeKits"
19
19
  group=vn.momo.kits
20
20
  artifact.id=kits
21
- version=0.161.2-beta.26
21
+ version=0.161.2-beta.27
22
22
 
23
23
  repo=GitLab
24
24
  url=https://gitlab.mservice.com.vn/api/v4/projects/5400/packages/maven
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.161.2-beta.26-debug",
3
+ "version": "0.161.2-beta.27-debug",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},