@momo-kits/native-kits 0.162.2-test.1-debug → 0.162.2-test.2-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.
@@ -28,8 +28,6 @@ data class MiniAppContext(
28
28
  val providerId: String = "",
29
29
  val permissions: List<Map<String, Any>>? = emptyList(),
30
30
  val features: FeatureFlags? = null,
31
- val useDeviceFontScale: Boolean? = null,
32
- val appFontScale: Float? = null,
33
31
  ) {
34
32
  companion object {
35
33
 
@@ -61,8 +59,6 @@ data class MiniAppContext(
61
59
  providerId = parent.providerId.ifBlank { child.providerId },
62
60
  permissions = if (!parent.permissions.isNullOrEmpty()) parent.permissions else child.permissions,
63
61
  features = mergeFeatureFlags(parent.features, child.features),
64
- useDeviceFontScale = parent.useDeviceFontScale ?: child.useDeviceFontScale,
65
- appFontScale = parent.appFontScale ?: child.appFontScale,
66
62
  )
67
63
  }
68
64
 
@@ -106,8 +102,4 @@ val AppLanguage = staticCompositionLocalOf<String?> {
106
102
 
107
103
  val LocalComponentInformation = staticCompositionLocalOf<ComponentInformation?> {
108
104
  null
109
- }
110
-
111
- val LocalUseDeviceFontScale = staticCompositionLocalOf<Boolean> { true }
112
-
113
- val LocalAppFontScale = staticCompositionLocalOf<Float> { 1f }
105
+ }
@@ -0,0 +1,77 @@
1
+ package vn.momo.kits.application
2
+
3
+ import androidx.compose.runtime.getValue
4
+ import androidx.compose.runtime.mutableStateOf
5
+ import androidx.compose.runtime.setValue
6
+ import kotlinx.coroutines.CoroutineScope
7
+ import kotlinx.coroutines.Dispatchers
8
+ import kotlinx.coroutines.SupervisorJob
9
+ import kotlinx.coroutines.launch
10
+ import vn.momo.maxapi.IMaxApi
11
+
12
+ const val KEY_USE_DEVICE_FONT_SCALE = "use_device_font_scale"
13
+ const val KEY_APP_FONT_SCALE = "app_font_scale"
14
+
15
+ /**
16
+ * Single in-memory mirror of the Observer Storage font-scale source of truth
17
+ * (keys [KEY_USE_DEVICE_FONT_SCALE] + [KEY_APP_FONT_SCALE]).
18
+ *
19
+ * scaleSize() reads this holder directly, so every Compose subtree across all
20
+ * NavigationContainer roots reacts to a change at once — no per-root wiring.
21
+ *
22
+ * The subscription is started once (the first NavigationContainer that receives
23
+ * a non-null [IMaxApi]) and lives on its own scope, independent of any screen
24
+ * lifecycle, so it survives navigation between roots.
25
+ */
26
+ object FontScaleStore {
27
+
28
+ var useDeviceFontScale by mutableStateOf(true)
29
+ private set
30
+ var appFontScale by mutableStateOf(1f)
31
+ private set
32
+
33
+ private var started = false
34
+ private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
35
+
36
+ fun start(maxApi: IMaxApi) {
37
+ if (started) return
38
+ started = true
39
+
40
+ // Seed the current persisted value first: the observer signal flow has no
41
+ // replay, so a fresh subscriber would otherwise stay at defaults until the
42
+ // next change (wrong scale on first paint).
43
+ maxApi.getDataObserver(KEY_USE_DEVICE_FONT_SCALE) { map ->
44
+ parseBool(map)?.let { useDeviceFontScale = it }
45
+ }
46
+ maxApi.getDataObserver(KEY_APP_FONT_SCALE) { map ->
47
+ parseFloat(map)?.let { appFontScale = it }
48
+ }
49
+
50
+ // Live updates.
51
+ scope.launch {
52
+ maxApi.observer(KEY_USE_DEVICE_FONT_SCALE).collect { map ->
53
+ parseBool(map)?.let { useDeviceFontScale = it }
54
+ }
55
+ }
56
+ scope.launch {
57
+ maxApi.observer(KEY_APP_FONT_SCALE).collect { map ->
58
+ parseFloat(map)?.let { appFontScale = it }
59
+ }
60
+ }
61
+ }
62
+
63
+ private fun response(map: Map<String, Any?>?): Any? = map?.get("response")
64
+
65
+ private fun parseBool(map: Map<String, Any?>?): Boolean? = when (val v = response(map)) {
66
+ is Boolean -> v
67
+ is String -> v.toBooleanStrictOrNull() ?: v.equals("true", ignoreCase = true)
68
+ is Number -> v.toInt() != 0
69
+ else -> null
70
+ }
71
+
72
+ private fun parseFloat(map: Map<String, Any?>?): Float? = when (val v = response(map)) {
73
+ is Number -> v.toFloat()
74
+ is String -> v.toFloatOrNull()
75
+ else -> null
76
+ }
77
+ }
@@ -15,8 +15,7 @@ import androidx.compose.ui.unit.sp
15
15
  import org.jetbrains.compose.resources.Font
16
16
  import org.jetbrains.compose.resources.FontResource
17
17
  import org.jetbrains.compose.resources.InternalResourceApi
18
- import vn.momo.kits.application.LocalAppFontScale
19
- import vn.momo.kits.application.LocalUseDeviceFontScale
18
+ import vn.momo.kits.application.FontScaleStore
20
19
  import vn.momo.kits.platform.getScreenDimensions
21
20
  import vn.momo.uikits.resources.Res
22
21
  import vn.momo.uikits.resources.momosignature
@@ -39,8 +38,8 @@ const val MAX_DEVICE_SCALE = 5
39
38
 
40
39
  @Composable
41
40
  fun scaleSize(size: Float): Float {
42
- val useDeviceFontScale = LocalUseDeviceFontScale.current
43
- val appFontScale = LocalAppFontScale.current
41
+ val useDeviceFontScale = FontScaleStore.useDeviceFontScale
42
+ val appFontScale = FontScaleStore.appFontScale
44
43
  val deviceWidth = getScreenDimensions().width
45
44
  val deviceScale = deviceWidth / DEFAULT_SCREEN_SIZE
46
45
 
@@ -37,6 +37,10 @@ fun NavigationContainer(
37
37
  val parentContext = ApplicationContext.current
38
38
  val mergedContext = MiniAppContext.merge(parentContext, applicationContext)
39
39
 
40
+ LaunchedEffect(maxApi) {
41
+ maxApi?.let { FontScaleStore.start(it) }
42
+ }
43
+
40
44
  val theme = remember { mutableStateOf(initialTheme) }
41
45
 
42
46
  LaunchedEffect(Unit) {
@@ -64,8 +68,6 @@ fun NavigationContainer(
64
68
  ApplicationContext provides mergedContext,
65
69
  AppConfig provides config,
66
70
  AppLanguage provides language,
67
- LocalUseDeviceFontScale provides (mergedContext?.useDeviceFontScale ?: true),
68
- LocalAppFontScale provides (mergedContext?.appFontScale ?: 1f),
69
71
  ) {
70
72
  LaunchedEffect(Unit) {
71
73
  setNavigator?.invoke(navigator)
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.162.2-test.1
21
+ version=0.162.2-test.2
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.162.2-test.1-debug",
3
+ "version": "0.162.2-test.2-debug",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},