@momo-kits/native-kits 0.118.0-rc.5 → 0.118.1-beta.2
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.
|
@@ -2,6 +2,7 @@ package vn.momo.kits.const
|
|
|
2
2
|
|
|
3
3
|
import androidx.compose.runtime.Composable
|
|
4
4
|
import androidx.compose.runtime.Immutable
|
|
5
|
+
import androidx.compose.ui.platform.LocalDensity
|
|
5
6
|
import androidx.compose.ui.text.TextStyle
|
|
6
7
|
import androidx.compose.ui.text.font.FontFamily
|
|
7
8
|
import androidx.compose.ui.text.font.FontWeight
|
|
@@ -12,17 +13,31 @@ import org.jetbrains.compose.resources.FontResource
|
|
|
12
13
|
import org.jetbrains.compose.resources.InternalResourceApi
|
|
13
14
|
import org.jetbrains.compose.resources.ResourceItem
|
|
14
15
|
import vn.momo.kits.platform.getScreenDimensions
|
|
16
|
+
import kotlin.math.min
|
|
15
17
|
|
|
16
18
|
const val DEFAULT_SCREEN_SIZE = 375f
|
|
19
|
+
const val MAX_FONT_SCALE = 1.2f
|
|
20
|
+
const val MAX_DEVICE_SCALE = 5
|
|
17
21
|
|
|
18
22
|
@Composable
|
|
19
23
|
fun scaleSize(size: Float): Float {
|
|
20
24
|
val deviceWidth = getScreenDimensions().width
|
|
21
|
-
val
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
val deviceScale = deviceWidth / DEFAULT_SCREEN_SIZE
|
|
26
|
+
|
|
27
|
+
val density = LocalDensity.current
|
|
28
|
+
val fontScale = density.fontScale
|
|
29
|
+
|
|
30
|
+
var fontSize = size / fontScale //To ignore OS scale
|
|
31
|
+
|
|
32
|
+
if (deviceScale > 1) {
|
|
33
|
+
fontSize = min(deviceScale * fontSize, fontSize + MAX_DEVICE_SCALE)
|
|
24
34
|
}
|
|
25
|
-
|
|
35
|
+
|
|
36
|
+
if (fontScale > 1) {
|
|
37
|
+
fontSize = min(fontScale * fontSize, fontSize * MAX_FONT_SCALE)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return fontSize
|
|
26
41
|
}
|
|
27
42
|
|
|
28
43
|
@OptIn(InternalResourceApi::class)
|
|
@@ -46,15 +61,15 @@ fun getFont(font: String): FontFamily {
|
|
|
46
61
|
fun getFontFamily(fontFamily: String, fontWeight: FontWeight? = FontWeight.Normal): FontFamily {
|
|
47
62
|
val key = "$fontFamily-${fontWeight?.weight}"
|
|
48
63
|
val fontMap = mapOf(
|
|
49
|
-
"SFProText-100" to "sfprotext_thin.
|
|
50
|
-
"SFProText-200" to "sfprotext_ultralight.
|
|
64
|
+
"SFProText-100" to "sfprotext_thin.otf",
|
|
65
|
+
"SFProText-200" to "sfprotext_ultralight.otf",
|
|
51
66
|
"SFProText-300" to "sfprotext_light.ttf",
|
|
52
67
|
"SFProText-400" to "sfprotext_regular.ttf",
|
|
53
68
|
"SFProText-500" to "sfprotext_medium.ttf",
|
|
54
69
|
"SFProText-600" to "sfprotext_semibold.ttf",
|
|
55
70
|
"SFProText-700" to "sfprotext_bold.ttf",
|
|
56
71
|
"SFProText-800" to "sfprotext_heavy.ttf",
|
|
57
|
-
"SFProText-900" to "sfprotext_black.
|
|
72
|
+
"SFProText-900" to "sfprotext_black.otf",
|
|
58
73
|
|
|
59
74
|
"MoMoSignature-100" to "momosignature.otf",
|
|
60
75
|
"MoMoSignature-200" to "momosignature.otf",
|
|
@@ -2,7 +2,28 @@ import SwiftUI
|
|
|
2
2
|
|
|
3
3
|
public extension Font {
|
|
4
4
|
static func appFont(size: CGFloat) -> Font {
|
|
5
|
-
|
|
5
|
+
let defaultScreenSize: CGFloat = 375
|
|
6
|
+
let maxFontScale: CGFloat = 1.2
|
|
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)
|
|
6
27
|
}
|
|
7
28
|
|
|
8
29
|
// New supported typography styles
|
package/local.properties
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
# Location of the SDK. This is only used by Gradle.
|
|
5
5
|
# For customization when using a Version Control System, please read the
|
|
6
6
|
# header note.
|
|
7
|
-
#
|
|
8
|
-
sdk.dir=/Users/
|
|
7
|
+
#Tue Apr 08 11:13:31 ICT 2025
|
|
8
|
+
sdk.dir=/Users/sonnguyen/Library/Android/sdk
|