@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.
- package/compose/compose.podspec +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +6 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +10 -14
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +2 -3
- package/gradle.properties +1 -1
- package/ios/Typography/Text.swift +9 -19
- package/ios/Typography/Typography.swift +22 -6
- package/package.json +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -23
- package/ios/Typography/MomoFontScale.swift +0 -36
package/compose/compose.podspec
CHANGED
|
@@ -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
|
|
32
|
-
val
|
|
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
|
-
|
|
66
|
-
|
|
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
|
|
111
|
+
val LocalUseDeviceFontScale = staticCompositionLocalOf<Boolean> { true }
|
|
114
112
|
|
|
115
|
-
val
|
|
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.
|
|
19
|
-
import vn.momo.kits.application.
|
|
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
|
|
44
|
-
val
|
|
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
|
|
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 (
|
|
61
|
-
// Follow OS font scale (capped). User ratio is ignored in this mode.
|
|
58
|
+
if (useDeviceFontScale) {
|
|
62
59
|
if (fontScale > 1) {
|
|
63
|
-
|
|
60
|
+
fontSizeScaleOS = min(fontScale * fontSizeScaleOS, fontSizeScaleOS * MAX_FONT_SCALE)
|
|
64
61
|
}
|
|
65
|
-
} else
|
|
66
|
-
|
|
67
|
-
fontSizeScaleUser = fontSizeScaleUser * fontSizeRatio
|
|
62
|
+
} else {
|
|
63
|
+
fontSizeScaleOS = size * appFontScale
|
|
68
64
|
}
|
|
69
65
|
|
|
70
66
|
return max(
|
|
71
67
|
fontSizeScaleDevice,
|
|
72
|
-
|
|
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
|
-
|
|
68
|
-
|
|
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
|
@@ -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
|
|
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
|
|
19
|
-
|
|
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,
|
|
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
|
-
|
|
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,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
|
-
}
|