@momo-kits/native-kits 0.162.13-debug → 0.162.14-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/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +3 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +17 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +3 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +22 -21
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -32
- package/gradle.properties +1 -1
- package/ios/Application/ApplicationEnvironment.swift +0 -1
- package/ios/Typography/Text.swift +7 -12
- package/ios/Typography/Typography.swift +9 -14
- package/package.json +1 -1
- package/ios/Application/FontScaleStore.swift +0 -59
package/compose/build.gradle.kts
CHANGED
|
@@ -28,7 +28,7 @@ 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
|
|
31
|
+
val scaleSizeMaxRate: Float? = null,
|
|
32
32
|
) {
|
|
33
33
|
companion object {
|
|
34
34
|
|
|
@@ -60,7 +60,7 @@ data class MiniAppContext(
|
|
|
60
60
|
providerId = parent.providerId.ifBlank { child.providerId },
|
|
61
61
|
permissions = if (!parent.permissions.isNullOrEmpty()) parent.permissions else child.permissions,
|
|
62
62
|
features = mergeFeatureFlags(parent.features, child.features),
|
|
63
|
-
|
|
63
|
+
scaleSizeMaxRate = parent.scaleSizeMaxRate ?: child.scaleSizeMaxRate,
|
|
64
64
|
)
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -98,11 +98,4 @@ val LocalComponentInformation = staticCompositionLocalOf<ComponentInformation?>
|
|
|
98
98
|
null
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
data class FontScaleConfig(
|
|
103
|
-
val useOSFontScale: Boolean = true,
|
|
104
|
-
val userScaleRate: Float? = null,
|
|
105
|
-
val osFontScale: Float? = null,
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
val LocalFontScaleConfig = staticCompositionLocalOf { FontScaleConfig() }
|
|
101
|
+
val ScaleSizeMaxRate = staticCompositionLocalOf<Float?> { null }
|
|
@@ -0,0 +1,17 @@
|
|
|
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.ScaleSizeMaxRate
|
|
6
|
+
|
|
7
|
+
@Composable
|
|
8
|
+
fun ScaleSizeScope(
|
|
9
|
+
scaleSizeMaxRate: Float? = null,
|
|
10
|
+
content: @Composable () -> Unit
|
|
11
|
+
) {
|
|
12
|
+
CompositionLocalProvider(
|
|
13
|
+
ScaleSizeMaxRate provides scaleSizeMaxRate,
|
|
14
|
+
) {
|
|
15
|
+
content()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -36,7 +36,6 @@ fun Text(
|
|
|
36
36
|
softWrap: Boolean = true,
|
|
37
37
|
accessibilityId: String? = null,
|
|
38
38
|
inlineContent: Map<String, InlineTextContent> = mapOf(),
|
|
39
|
-
userScaleRate: Float? = null,
|
|
40
39
|
) {
|
|
41
40
|
Text(
|
|
42
41
|
text = AnnotatedString(text),
|
|
@@ -53,8 +52,7 @@ fun Text(
|
|
|
53
52
|
letterSpacing = letterSpacing,
|
|
54
53
|
softWrap = softWrap,
|
|
55
54
|
accessibilityId = accessibilityId,
|
|
56
|
-
inlineContent = inlineContent
|
|
57
|
-
userScaleRate = userScaleRate
|
|
55
|
+
inlineContent = inlineContent
|
|
58
56
|
)
|
|
59
57
|
}
|
|
60
58
|
|
|
@@ -76,14 +74,13 @@ fun Text(
|
|
|
76
74
|
softWrap: Boolean = true,
|
|
77
75
|
accessibilityId: String? = null,
|
|
78
76
|
inlineContent: Map<String, InlineTextContent> = mapOf(),
|
|
79
|
-
userScaleRate: Float? = null,
|
|
80
77
|
) {
|
|
81
78
|
// Cache theme access to avoid repeated lookups
|
|
82
79
|
val theme = AppTheme.current
|
|
83
80
|
|
|
84
81
|
// Call @Composable functions directly in composable context
|
|
85
|
-
val scaledFontSize = scaleSize(style.fontSize
|
|
86
|
-
val scaledLineHeight = scaleSize(style.lineHeight
|
|
82
|
+
val scaledFontSize = scaleSize(style.fontSize)
|
|
83
|
+
val scaledLineHeight = scaleSize(style.lineHeight)
|
|
87
84
|
val fontFamilyResult = getFontFamily(fontFamily ?: theme.font, style.fontWeight)
|
|
88
85
|
|
|
89
86
|
// Now memoize the results
|
|
@@ -11,7 +11,7 @@ import androidx.compose.ui.unit.*
|
|
|
11
11
|
import org.jetbrains.compose.resources.Font
|
|
12
12
|
import org.jetbrains.compose.resources.FontResource
|
|
13
13
|
import org.jetbrains.compose.resources.InternalResourceApi
|
|
14
|
-
import vn.momo.kits.application.
|
|
14
|
+
import vn.momo.kits.application.ScaleSizeMaxRate
|
|
15
15
|
import vn.momo.kits.platform.getScreenDimensions
|
|
16
16
|
import vn.momo.uikits.resources.*
|
|
17
17
|
import kotlin.math.max
|
|
@@ -22,58 +22,59 @@ const val MAX_FONT_SCALE = 1.5f
|
|
|
22
22
|
const val MAX_DEVICE_SCALE = 5
|
|
23
23
|
|
|
24
24
|
@Composable
|
|
25
|
-
fun scaleSize(size: Float
|
|
26
|
-
val
|
|
27
|
-
val
|
|
28
|
-
val
|
|
25
|
+
fun scaleSize(size: Float): Float {
|
|
26
|
+
val scaleSizeMaxRate: Float = ScaleSizeMaxRate.current ?: MAX_FONT_SCALE
|
|
27
|
+
val deviceWidth = getScreenDimensions().width
|
|
28
|
+
val deviceScale = deviceWidth / DEFAULT_SCREEN_SIZE
|
|
29
29
|
|
|
30
|
-
val
|
|
31
|
-
val fontScale =
|
|
32
|
-
|
|
33
|
-
if (!useOSFontScale) {
|
|
34
|
-
return if (customRate > 1f) customRate * size else size
|
|
35
|
-
}
|
|
30
|
+
val density = LocalDensity.current
|
|
31
|
+
val fontScale = density.fontScale
|
|
36
32
|
|
|
37
33
|
var fontSizeScaleDevice = size
|
|
38
34
|
var fontSizeScaleOS = size
|
|
35
|
+
|
|
39
36
|
if (deviceScale > 1) {
|
|
40
37
|
fontSizeScaleDevice =
|
|
41
38
|
min(deviceScale * fontSizeScaleDevice, fontSizeScaleDevice + MAX_DEVICE_SCALE)
|
|
42
39
|
}
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
|
|
41
|
+
if (fontScale > 1) {
|
|
42
|
+
fontSizeScaleOS = min(fontScale * fontSizeScaleOS, fontSizeScaleOS * scaleSizeMaxRate)
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
return max(
|
|
45
|
+
return max(
|
|
46
|
+
fontSizeScaleDevice,
|
|
47
|
+
fontSizeScaleOS
|
|
48
|
+
)
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
@Composable
|
|
51
|
-
fun scaleSize(size: TextUnit
|
|
52
|
+
fun scaleSize(size: TextUnit): TextUnit {
|
|
52
53
|
if (!size.isSp) return size
|
|
53
54
|
|
|
54
55
|
val density = LocalDensity.current
|
|
55
56
|
|
|
56
|
-
val scaled = scaleSize(size.value
|
|
57
|
+
val scaled = scaleSize(size.value)
|
|
57
58
|
val spValue = scaled / density.fontScale
|
|
58
59
|
|
|
59
60
|
return TextUnit(value = spValue, type = TextUnitType.Sp)
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
@Composable
|
|
63
|
-
fun scaleSize(size: Dp
|
|
64
|
-
return scaleSize(size.value
|
|
64
|
+
fun scaleSize(size: Dp): Dp {
|
|
65
|
+
return scaleSize(size.value).dp
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
@Composable
|
|
68
|
-
fun scaleSize(textStyle: TextStyle
|
|
69
|
+
fun scaleSize(textStyle: TextStyle): TextStyle {
|
|
69
70
|
return textStyle.copy(
|
|
70
71
|
fontSize = if (textStyle.fontSize != TextUnit.Unspecified)
|
|
71
|
-
scaleSize(textStyle.fontSize
|
|
72
|
+
scaleSize(textStyle.fontSize)
|
|
72
73
|
else
|
|
73
74
|
TextUnit.Unspecified,
|
|
74
75
|
|
|
75
76
|
lineHeight = if (textStyle.lineHeight != TextUnit.Unspecified)
|
|
76
|
-
scaleSize(textStyle.lineHeight
|
|
77
|
+
scaleSize(textStyle.lineHeight)
|
|
77
78
|
else
|
|
78
79
|
TextUnit.Unspecified,
|
|
79
80
|
)
|
|
@@ -42,7 +42,6 @@ fun NavigationContainer(
|
|
|
42
42
|
|
|
43
43
|
val resolvedLocalize = localize ?: fallbackLocalize
|
|
44
44
|
|
|
45
|
-
var observerFontScaleConfig by remember { mutableStateOf(mergedContext?.fontScaleConfig) }
|
|
46
45
|
LaunchedEffect(maxApi, resolvedLocalize) {
|
|
47
46
|
val api = maxApi ?: return@LaunchedEffect
|
|
48
47
|
runCatching {
|
|
@@ -51,9 +50,6 @@ fun NavigationContainer(
|
|
|
51
50
|
resolvedLocalize.changeLanguage(Localize.EN)
|
|
52
51
|
}
|
|
53
52
|
})
|
|
54
|
-
api.observer(FONT_SCALE_OBSERVER_KEY).collect { data ->
|
|
55
|
-
observerFontScaleConfig = parseFontScaleConfig(data)
|
|
56
|
-
}
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
55
|
|
|
@@ -71,7 +67,6 @@ fun NavigationContainer(
|
|
|
71
67
|
AppNavigationBar provides navigationBarHeight,
|
|
72
68
|
LocalContext provides mergedContext,
|
|
73
69
|
LocalLocalize provides resolvedLocalize,
|
|
74
|
-
LocalFontScaleConfig provides (observerFontScaleConfig ?: LocalFontScaleConfig.current),
|
|
75
70
|
) {
|
|
76
71
|
LaunchedEffect(Unit) {
|
|
77
72
|
setNavigator?.invoke(navigator)
|
|
@@ -151,36 +146,9 @@ val LocalMaxApi = staticCompositionLocalOf<IMaxApi?> {
|
|
|
151
146
|
error("No MaxApi provided")
|
|
152
147
|
}
|
|
153
148
|
|
|
154
|
-
private const val FONT_SCALE_OBSERVER_KEY = "font_scale_config"
|
|
155
|
-
|
|
156
149
|
private fun parseLanguage(raw: Map<String, Any?>?): String? {
|
|
157
150
|
val code = (raw?.get("response") as? String)?.trim()?.lowercase()
|
|
158
151
|
if (code.isNullOrEmpty()) return null
|
|
159
152
|
return if (code.startsWith(Localize.EN)) Localize.EN else Localize.VI
|
|
160
153
|
}
|
|
161
154
|
|
|
162
|
-
private fun parseFontScaleConfig(raw: Map<String, Any?>?): FontScaleConfig? {
|
|
163
|
-
if (raw.isNullOrEmpty()) return null
|
|
164
|
-
@Suppress("UNCHECKED_CAST")
|
|
165
|
-
val data = (raw["response"] as? Map<String, Any?>)
|
|
166
|
-
?: (raw["data"] as? Map<String, Any?>)
|
|
167
|
-
?: raw
|
|
168
|
-
if (!data.containsKey("useOSFontScale") && !data.containsKey("userScaleRate")) return null
|
|
169
|
-
val useOS = when (val v = data["useOSFontScale"]) {
|
|
170
|
-
is Boolean -> v
|
|
171
|
-
is String -> v.equals("true", ignoreCase = true)
|
|
172
|
-
is Number -> v.toInt() != 0
|
|
173
|
-
else -> true
|
|
174
|
-
}
|
|
175
|
-
val rate = when (val v = data["userScaleRate"]) {
|
|
176
|
-
is Number -> v.toFloat()
|
|
177
|
-
is String -> v.toFloatOrNull()
|
|
178
|
-
else -> null
|
|
179
|
-
}
|
|
180
|
-
val osScale = when (val v = data["osFontScale"]) {
|
|
181
|
-
is Number -> v.toFloat()
|
|
182
|
-
is String -> v.toFloatOrNull()
|
|
183
|
-
else -> null
|
|
184
|
-
}
|
|
185
|
-
return FontScaleConfig(useOSFontScale = useOS, userScaleRate = rate, osFontScale = osScale)
|
|
186
|
-
}
|
package/gradle.properties
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
import SwiftUI
|
|
2
2
|
|
|
3
3
|
public func scaleSize(_ size: CGFloat, _ scaleRate: CGFloat? = nil) -> CGFloat {
|
|
4
|
-
let config = FontScaleStore.shared.config
|
|
5
4
|
let defaultScreenSize: CGFloat = 375
|
|
6
5
|
let maxFontScale: CGFloat = scaleRate ?? 1.5
|
|
7
6
|
let maxDeviceScale: CGFloat = 5
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return customRate > 1 ? size * customRate : size
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let deviceScale = UIScreen.main.bounds.width / defaultScreenSize
|
|
8
|
+
let deviceWidth = UIScreen.main.bounds.width
|
|
9
|
+
let deviceScale = deviceWidth / defaultScreenSize
|
|
15
10
|
|
|
16
11
|
let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
|
|
17
12
|
let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
|
|
18
|
-
let
|
|
13
|
+
let fontScale = scaledFont.pointSize / defaultFont.pointSize
|
|
19
14
|
|
|
20
15
|
var fontSizeDeviceScale = size
|
|
21
16
|
var fontSizeOSScale = size
|
|
22
17
|
|
|
18
|
+
|
|
23
19
|
if deviceScale > 1 {
|
|
24
20
|
fontSizeDeviceScale = min(fontSizeDeviceScale * deviceScale, fontSizeDeviceScale + maxDeviceScale)
|
|
25
21
|
}
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
|
|
23
|
+
if fontScale > 1 {
|
|
24
|
+
fontSizeOSScale = min(fontSizeOSScale * fontScale, fontSizeOSScale * maxFontScale)
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
return max(fontSizeDeviceScale, fontSizeOSScale)
|
|
@@ -121,7 +118,6 @@ public struct MomoText: View {
|
|
|
121
118
|
private let content: String
|
|
122
119
|
private let typography: TypographyStyle
|
|
123
120
|
private let color: Color
|
|
124
|
-
@ObservedObject private var fontScale = FontScaleStore.shared
|
|
125
121
|
|
|
126
122
|
public init(
|
|
127
123
|
_ content: String,
|
|
@@ -134,7 +130,6 @@ public struct MomoText: View {
|
|
|
134
130
|
}
|
|
135
131
|
|
|
136
132
|
public var body: some View {
|
|
137
|
-
_ = fontScale.config
|
|
138
133
|
let text = SwiftUI.Text(content)
|
|
139
134
|
.font(.system(size: scaleSize(typography.fontSize), weight: typography.fontWeight))
|
|
140
135
|
.foregroundColor(color)
|
|
@@ -11,35 +11,30 @@ public extension View {
|
|
|
11
11
|
|
|
12
12
|
public extension Font {
|
|
13
13
|
static func appFont(size: CGFloat) -> Font {
|
|
14
|
-
let config = FontScaleStore.shared.config
|
|
15
14
|
let defaultScreenSize: CGFloat = 375
|
|
16
15
|
let maxFontScale: CGFloat = 1.5
|
|
17
16
|
let maxDeviceScale: CGFloat = 5
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let scaled = customRate > 1 ? size * customRate : size
|
|
22
|
-
return Font.system(size: scaled)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let deviceScale = UIScreen.main.bounds.width / defaultScreenSize
|
|
18
|
+
let deviceWidth = UIScreen.main.bounds.width
|
|
19
|
+
let deviceScale = deviceWidth / defaultScreenSize
|
|
26
20
|
|
|
27
21
|
let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
|
|
28
22
|
let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
|
|
29
|
-
let
|
|
23
|
+
let fontScale = scaledFont.pointSize / defaultFont.pointSize
|
|
30
24
|
|
|
31
25
|
var fontSize = size
|
|
32
26
|
|
|
33
27
|
if deviceScale > 1 {
|
|
34
28
|
fontSize = min(fontSize * deviceScale, fontSize + maxDeviceScale)
|
|
35
29
|
}
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
|
|
31
|
+
if fontScale > 1 {
|
|
32
|
+
fontSize = min(fontSize * fontScale, fontSize * maxFontScale)
|
|
38
33
|
}
|
|
39
34
|
|
|
40
35
|
return Font.system(size: fontSize)
|
|
41
36
|
}
|
|
42
|
-
|
|
37
|
+
|
|
43
38
|
// New supported typography styles
|
|
44
39
|
static let headline_default_bold = appFont(size: 24).weight(.bold)
|
|
45
40
|
static let header_m_bold = appFont(size: 18).weight(.bold)
|
|
@@ -57,7 +52,7 @@ public extension Font {
|
|
|
57
52
|
static let action_s_bold = appFont(size: 14).weight(.bold)
|
|
58
53
|
static let action_xs_bold = appFont(size: 12).weight(.bold)
|
|
59
54
|
static let action_xxs_bold = appFont(size: 10).weight(.bold)
|
|
60
|
-
|
|
55
|
+
|
|
61
56
|
// Legacy styles
|
|
62
57
|
static let headline_default = appFont(size: 28).weight(.semibold)
|
|
63
58
|
static let headline_s = appFont(size: 24).weight(.semibold)
|
|
@@ -82,7 +77,7 @@ public extension Font {
|
|
|
82
77
|
static let action_xxs = appFont(size: 10).weight(.bold)
|
|
83
78
|
static let action_xs = appFont(size: 12).weight(.bold)
|
|
84
79
|
static let action_s = appFont(size: 15).weight(.bold)
|
|
85
|
-
|
|
80
|
+
|
|
86
81
|
// deprecated
|
|
87
82
|
static let h1 = appFont(size: 36).weight(.semibold) //headline_xl
|
|
88
83
|
static let h2 = appFont(size: 32).weight(.semibold)
|
package/package.json
CHANGED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import SwiftUI
|
|
2
|
-
|
|
3
|
-
public struct FontScaleConfig {
|
|
4
|
-
public var useOSFontScale: Bool
|
|
5
|
-
public var userScaleRate: CGFloat?
|
|
6
|
-
|
|
7
|
-
public init(useOSFontScale: Bool = true, userScaleRate: CGFloat? = nil) {
|
|
8
|
-
self.useOSFontScale = useOSFontScale
|
|
9
|
-
self.userScaleRate = userScaleRate
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public final class FontScaleStore: ObservableObject {
|
|
14
|
-
public static let shared = FontScaleStore()
|
|
15
|
-
|
|
16
|
-
@Published public private(set) var config = FontScaleConfig()
|
|
17
|
-
|
|
18
|
-
private var didBind = false
|
|
19
|
-
private var observerId: String?
|
|
20
|
-
|
|
21
|
-
private init() {}
|
|
22
|
-
|
|
23
|
-
public func update(_ newConfig: FontScaleConfig) {
|
|
24
|
-
if Thread.isMainThread {
|
|
25
|
-
config = newConfig
|
|
26
|
-
} else {
|
|
27
|
-
DispatchQueue.main.async { [weak self] in self?.config = newConfig }
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public func bind(_ api: KitComposeApi?) {
|
|
32
|
-
guard let api = api, !didBind else { return }
|
|
33
|
-
didBind = true
|
|
34
|
-
|
|
35
|
-
apply(api.request(funcName: "getFontScaleConfig", params: nil))
|
|
36
|
-
observerId = api.request(funcName: "observer", params: ["font_scale_config"]) { [weak self] response in
|
|
37
|
-
self?.apply(response)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
private func apply(_ response: String) {
|
|
42
|
-
guard let parsed = FontScaleStore.parse(response) else { return }
|
|
43
|
-
update(parsed)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static func parse(_ response: String) -> FontScaleConfig? {
|
|
47
|
-
guard
|
|
48
|
-
let data = response.data(using: .utf8),
|
|
49
|
-
let json = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any]
|
|
50
|
-
else { return nil }
|
|
51
|
-
|
|
52
|
-
let obj = (json["response"] as? [String: Any]) ?? (json["data"] as? [String: Any]) ?? json
|
|
53
|
-
guard obj["useOSFontScale"] != nil || obj["userScaleRate"] != nil else { return nil }
|
|
54
|
-
|
|
55
|
-
let useOS = (obj["useOSFontScale"] as? Bool) ?? true
|
|
56
|
-
let rate = (obj["userScaleRate"] as? NSNumber).map { CGFloat($0.doubleValue) }
|
|
57
|
-
return FontScaleConfig(useOSFontScale: useOS, userScaleRate: rate)
|
|
58
|
-
}
|
|
59
|
-
}
|