@momo-kits/native-kits 0.162.2-beta.1-debug → 0.162.2-test.1-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.
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |spec|
2
2
  spec.name = 'compose'
3
- spec.version = '0.161.0-debug'
3
+ spec.version = '0.161.2-beta.15'
4
4
  spec.homepage = 'https://momo.vn'
5
5
  spec.source = { :http=> ''}
6
6
  spec.authors = ''
@@ -28,9 +28,8 @@ 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 scaleSizeMaxRate: Float? = null,
32
- val followOSScale: Boolean? = null,
33
- val fontSizeRatio: Float? = null,
31
+ val useDeviceFontScale: Boolean? = null,
32
+ val appFontScale: Float? = null,
34
33
  ) {
35
34
  companion object {
36
35
 
@@ -62,9 +61,8 @@ data class MiniAppContext(
62
61
  providerId = parent.providerId.ifBlank { child.providerId },
63
62
  permissions = if (!parent.permissions.isNullOrEmpty()) parent.permissions else child.permissions,
64
63
  features = mergeFeatureFlags(parent.features, child.features),
65
- scaleSizeMaxRate = parent.scaleSizeMaxRate ?: child.scaleSizeMaxRate,
66
- followOSScale = parent.followOSScale ?: child.followOSScale,
67
- fontSizeRatio = parent.fontSizeRatio ?: child.fontSizeRatio,
64
+ useDeviceFontScale = parent.useDeviceFontScale ?: child.useDeviceFontScale,
65
+ appFontScale = parent.appFontScale ?: child.appFontScale,
68
66
  )
69
67
  }
70
68
 
@@ -110,8 +108,6 @@ val LocalComponentInformation = staticCompositionLocalOf<ComponentInformation?>
110
108
  null
111
109
  }
112
110
 
113
- val ScaleSizeMaxRate = staticCompositionLocalOf<Float?> { null }
111
+ val LocalUseDeviceFontScale = staticCompositionLocalOf<Boolean> { true }
114
112
 
115
- val FollowOSScale = staticCompositionLocalOf<Boolean?> { null }
116
-
117
- val FontSizeRatio = staticCompositionLocalOf<Float?> { null }
113
+ val LocalAppFontScale = staticCompositionLocalOf<Float> { 1f }
@@ -15,9 +15,8 @@ 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.FollowOSScale
19
- import vn.momo.kits.application.FontSizeRatio
20
- import vn.momo.kits.application.ScaleSizeMaxRate
18
+ import vn.momo.kits.application.LocalAppFontScale
19
+ import vn.momo.kits.application.LocalUseDeviceFontScale
21
20
  import vn.momo.kits.platform.getScreenDimensions
22
21
  import vn.momo.uikits.resources.Res
23
22
  import vn.momo.uikits.resources.momosignature
@@ -40,9 +39,8 @@ const val MAX_DEVICE_SCALE = 5
40
39
 
41
40
  @Composable
42
41
  fun scaleSize(size: Float): Float {
43
- val scaleSizeMaxRate: Float = ScaleSizeMaxRate.current ?: MAX_FONT_SCALE
44
- val followOSScale: Boolean = FollowOSScale.current ?: false
45
- val fontSizeRatio: Float = FontSizeRatio.current ?: 1f
42
+ val useDeviceFontScale = LocalUseDeviceFontScale.current
43
+ val appFontScale = LocalAppFontScale.current
46
44
  val deviceWidth = getScreenDimensions().width
47
45
  val deviceScale = deviceWidth / DEFAULT_SCREEN_SIZE
48
46
 
@@ -50,26 +48,24 @@ fun scaleSize(size: Float): Float {
50
48
  val fontScale = density.fontScale
51
49
 
52
50
  var fontSizeScaleDevice = size
53
- var fontSizeScaleUser = size
51
+ var fontSizeScaleOS = size
54
52
 
55
53
  if (deviceScale > 1) {
56
54
  fontSizeScaleDevice =
57
55
  min(deviceScale * fontSizeScaleDevice, fontSizeScaleDevice + MAX_DEVICE_SCALE)
58
56
  }
59
57
 
60
- if (followOSScale) {
61
- // Follow OS font scale (capped). User ratio is ignored in this mode.
58
+ if (useDeviceFontScale) {
62
59
  if (fontScale > 1) {
63
- fontSizeScaleUser = min(fontScale * fontSizeScaleUser, fontSizeScaleUser * scaleSizeMaxRate)
60
+ fontSizeScaleOS = min(fontScale * fontSizeScaleOS, fontSizeScaleOS * MAX_FONT_SCALE)
64
61
  }
65
- } else if (fontSizeRatio > 1) {
66
- // Custom in-app ratio. OS font scale is ignored.
67
- fontSizeScaleUser = fontSizeScaleUser * fontSizeRatio
62
+ } else {
63
+ fontSizeScaleOS = size * appFontScale
68
64
  }
69
65
 
70
66
  return max(
71
67
  fontSizeScaleDevice,
72
- fontSizeScaleUser
68
+ fontSizeScaleOS
73
69
  )
74
70
  }
75
71
 
@@ -64,9 +64,8 @@ fun NavigationContainer(
64
64
  ApplicationContext provides mergedContext,
65
65
  AppConfig provides config,
66
66
  AppLanguage provides language,
67
- ScaleSizeMaxRate provides mergedContext?.scaleSizeMaxRate,
68
- FollowOSScale provides mergedContext?.followOSScale,
69
- FontSizeRatio provides mergedContext?.fontSizeRatio,
67
+ LocalUseDeviceFontScale provides (mergedContext?.useDeviceFontScale ?: true),
68
+ LocalAppFontScale provides (mergedContext?.appFontScale ?: 1f),
70
69
  ) {
71
70
  LaunchedEffect(Unit) {
72
71
  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-beta.1
21
+ version=0.162.2-test.1
22
22
 
23
23
  repo=GitLab
24
24
  url=https://gitlab.mservice.com.vn/api/v4/projects/5400/packages/maven
@@ -8,30 +8,23 @@ public func scaleSize(_ size: CGFloat, _ scaleRate: CGFloat? = nil) -> CGFloat {
8
8
  let deviceWidth = UIScreen.main.bounds.width
9
9
  let deviceScale = deviceWidth / defaultScreenSize
10
10
 
11
+ let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
12
+ let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
13
+ let fontScale = scaledFont.pointSize / defaultFont.pointSize
14
+
11
15
  var fontSizeDeviceScale = size
12
- var fontSizeUserScale = size
16
+ var fontSizeOSScale = size
17
+
13
18
 
14
19
  if deviceScale > 1 {
15
20
  fontSizeDeviceScale = min(fontSizeDeviceScale * deviceScale, fontSizeDeviceScale + maxDeviceScale)
16
21
  }
17
22
 
18
- if MomoFontScale.shared.followOSScale {
19
- // Follow OS font scale (capped). User ratio is ignored in this mode.
20
- let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
21
- let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
22
- let fontScale = scaledFont.pointSize / defaultFont.pointSize
23
- if fontScale > 1 {
24
- fontSizeUserScale = min(fontSizeUserScale * fontScale, fontSizeUserScale * maxFontScale)
25
- }
26
- } else {
27
- // Custom in-app ratio. OS font scale is ignored.
28
- let ratio = MomoFontScale.shared.ratio
29
- if ratio > 1 {
30
- fontSizeUserScale = fontSizeUserScale * ratio
31
- }
23
+ if fontScale > 1 {
24
+ fontSizeOSScale = min(fontSizeOSScale * fontScale, fontSizeOSScale * maxFontScale)
32
25
  }
33
26
 
34
- return max(fontSizeDeviceScale, fontSizeUserScale)
27
+ return max(fontSizeDeviceScale, fontSizeOSScale)
35
28
  }
36
29
 
37
30
  public enum TypographyStyle {
@@ -125,9 +118,6 @@ public struct MomoText: View {
125
118
  private let content: String
126
119
  private let typography: TypographyStyle
127
120
  private let color: Color
128
- // Observe so the text re-renders immediately when the user changes the
129
- // font-size setting (live update, no app restart).
130
- @ObservedObject private var fontScale = MomoFontScale.shared
131
121
 
132
122
  public init(
133
123
  _ content: String,
@@ -1,13 +1,29 @@
1
1
  import SwiftUI
2
2
 
3
3
  public extension Font {
4
- // Shares the same scaling logic as `scaleSize` so it honors the user's
5
- // font-size preference (follow-OS vs in-app ratio).
6
- // NOTE: the `static let` constants below are evaluated once on first
7
- // access, so they reflect the setting at launch but do not live-update.
8
- // Components that need live updates should use `MomoText` / `scaleSize`.
9
4
  static func appFont(size: CGFloat) -> Font {
10
- return Font.system(size: scaleSize(size))
5
+ let defaultScreenSize: CGFloat = 375
6
+ let maxFontScale: CGFloat = 1.5
7
+ let maxDeviceScale: CGFloat = 5
8
+
9
+ let deviceWidth = UIScreen.main.bounds.width
10
+ let deviceScale = deviceWidth / defaultScreenSize
11
+
12
+ let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
13
+ let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
14
+ let fontScale = scaledFont.pointSize / defaultFont.pointSize
15
+
16
+ var fontSize = size
17
+
18
+ if deviceScale > 1 {
19
+ fontSize = min(fontSize * deviceScale, fontSize + maxDeviceScale)
20
+ }
21
+
22
+ if fontScale > 1 {
23
+ fontSize = min(fontSize * fontScale, fontSize * maxFontScale)
24
+ }
25
+
26
+ return Font.system(size: fontSize)
11
27
  }
12
28
 
13
29
  // New supported typography styles
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.162.2-beta.1-debug",
3
+ "version": "0.162.2-test.1-debug",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},
@@ -1,23 +0,0 @@
1
- package vn.momo.kits.components
2
-
3
- import androidx.compose.runtime.Composable
4
- import androidx.compose.runtime.CompositionLocalProvider
5
- import vn.momo.kits.application.FollowOSScale
6
- import vn.momo.kits.application.FontSizeRatio
7
- import vn.momo.kits.application.ScaleSizeMaxRate
8
-
9
- @Composable
10
- fun ScaleSizeScope(
11
- scaleSizeMaxRate: Float? = null,
12
- followOSScale: Boolean? = null,
13
- fontSizeRatio: Float? = null,
14
- content: @Composable () -> Unit
15
- ) {
16
- CompositionLocalProvider(
17
- ScaleSizeMaxRate provides scaleSizeMaxRate,
18
- FollowOSScale provides followOSScale,
19
- FontSizeRatio provides fontSizeRatio,
20
- ) {
21
- content()
22
- }
23
- }
@@ -1,36 +0,0 @@
1
- import SwiftUI
2
-
3
- /// Process-wide holder for the user's in-app font-size preference.
4
- ///
5
- /// `momo-native-kits` is a UI library; it does not read persistent storage
6
- /// itself. The host app (momo-app) reads the persisted setting from the shared
7
- /// Observable Storage and pushes it here at launch and on every change via
8
- /// `update(followOSScale:ratio:)`. All native typography (`scaleSize`,
9
- /// `Font.appFont`, `MomoText`) reads from this single source so the three
10
- /// render stacks (RN / Compose / SwiftUI) stay in sync.
11
- ///
12
- /// Live update: `MomoText` observes this object, so changing the setting
13
- /// re-renders typed text immediately. Views built from the `Font.appFont`
14
- /// static constants pick up the value at launch (static `let` is evaluated
15
- /// once); making those live would require turning them into functions.
16
- public final class MomoFontScale: ObservableObject {
17
- public static let shared = MomoFontScale()
18
-
19
- /// When true, follow the OS font scale (capped). `ratio` is ignored.
20
- @Published public private(set) var followOSScale: Bool = false
21
-
22
- /// In-app font-size ratio (e.g. 1.0 / 1.1 / 1.2). Ignored when
23
- /// `followOSScale` is true.
24
- @Published public private(set) var ratio: CGFloat = 1
25
-
26
- private init() {}
27
-
28
- public func update(followOSScale: Bool, ratio: CGFloat) {
29
- if self.followOSScale != followOSScale {
30
- self.followOSScale = followOSScale
31
- }
32
- if self.ratio != ratio {
33
- self.ratio = ratio
34
- }
35
- }
36
- }