@momo-kits/native-kits 0.159.1-beta.3-debug → 0.159.1-beta.4-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
CHANGED
|
@@ -2,21 +2,16 @@ 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
|
|
6
5
|
import androidx.compose.ui.text.TextStyle
|
|
7
6
|
import androidx.compose.ui.text.font.FontFamily
|
|
8
7
|
import androidx.compose.ui.text.font.FontWeight
|
|
9
8
|
import androidx.compose.ui.text.style.TextDecoration
|
|
10
9
|
import androidx.compose.ui.unit.Dp
|
|
11
10
|
import androidx.compose.ui.unit.TextUnit
|
|
12
|
-
import androidx.compose.ui.unit.TextUnitType
|
|
13
|
-
import androidx.compose.ui.unit.dp
|
|
14
11
|
import androidx.compose.ui.unit.sp
|
|
15
12
|
import org.jetbrains.compose.resources.Font
|
|
16
13
|
import org.jetbrains.compose.resources.FontResource
|
|
17
14
|
import org.jetbrains.compose.resources.InternalResourceApi
|
|
18
|
-
import vn.momo.kits.application.ScaleSizeMaxRate
|
|
19
|
-
import vn.momo.kits.platform.getScreenDimensions
|
|
20
15
|
import vn.momo.uikits.resources.Res
|
|
21
16
|
import vn.momo.uikits.resources.momosignature
|
|
22
17
|
import vn.momo.uikits.resources.momotrustdisplay
|
|
@@ -29,70 +24,25 @@ import vn.momo.uikits.resources.sfprotext_regular
|
|
|
29
24
|
import vn.momo.uikits.resources.sfprotext_semibold
|
|
30
25
|
import vn.momo.uikits.resources.sfprotext_thin
|
|
31
26
|
import vn.momo.uikits.resources.sfprotext_ultralight
|
|
32
|
-
import kotlin.math.max
|
|
33
|
-
import kotlin.math.min
|
|
34
|
-
|
|
35
|
-
const val DEFAULT_SCREEN_SIZE = 375f
|
|
36
|
-
const val MAX_FONT_SCALE = 1.2f
|
|
37
|
-
const val MAX_DEVICE_SCALE = 5
|
|
38
27
|
|
|
39
28
|
@Composable
|
|
40
29
|
fun scaleSize(size: Float): Float {
|
|
41
|
-
|
|
42
|
-
val deviceWidth = getScreenDimensions().width
|
|
43
|
-
val deviceScale = deviceWidth / DEFAULT_SCREEN_SIZE
|
|
44
|
-
|
|
45
|
-
val density = LocalDensity.current
|
|
46
|
-
val fontScale = density.fontScale
|
|
47
|
-
|
|
48
|
-
var fontSizeScaleDevice = size
|
|
49
|
-
var fontSizeScaleOS = size
|
|
50
|
-
|
|
51
|
-
if (deviceScale > 1) {
|
|
52
|
-
fontSizeScaleDevice =
|
|
53
|
-
min(deviceScale * fontSizeScaleDevice, fontSizeScaleDevice + MAX_DEVICE_SCALE)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (fontScale > 1) {
|
|
57
|
-
fontSizeScaleOS = min(fontScale * fontSizeScaleOS, fontSizeScaleOS * scaleSizeMaxRate)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return max(
|
|
61
|
-
fontSizeScaleDevice,
|
|
62
|
-
fontSizeScaleOS
|
|
63
|
-
)
|
|
30
|
+
return size
|
|
64
31
|
}
|
|
65
32
|
|
|
66
33
|
@Composable
|
|
67
34
|
fun scaleSize(size: TextUnit): TextUnit {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
val density = LocalDensity.current
|
|
71
|
-
|
|
72
|
-
val scaled = scaleSize(size.value)
|
|
73
|
-
val spValue = scaled / density.fontScale
|
|
74
|
-
|
|
75
|
-
return TextUnit(value = spValue, type = TextUnitType.Sp)
|
|
35
|
+
return size
|
|
76
36
|
}
|
|
77
37
|
|
|
78
38
|
@Composable
|
|
79
39
|
fun scaleSize(size: Dp): Dp {
|
|
80
|
-
return
|
|
40
|
+
return size
|
|
81
41
|
}
|
|
82
42
|
|
|
83
43
|
@Composable
|
|
84
44
|
fun scaleSize(textStyle: TextStyle): TextStyle {
|
|
85
|
-
return textStyle
|
|
86
|
-
fontSize = if (textStyle.fontSize != TextUnit.Unspecified)
|
|
87
|
-
scaleSize(textStyle.fontSize)
|
|
88
|
-
else
|
|
89
|
-
TextUnit.Unspecified,
|
|
90
|
-
|
|
91
|
-
lineHeight = if (textStyle.lineHeight != TextUnit.Unspecified)
|
|
92
|
-
scaleSize(textStyle.lineHeight)
|
|
93
|
-
else
|
|
94
|
-
TextUnit.Unspecified,
|
|
95
|
-
)
|
|
45
|
+
return textStyle
|
|
96
46
|
}
|
|
97
47
|
|
|
98
48
|
|
package/gradle.properties
CHANGED
|
@@ -1,30 +1,7 @@
|
|
|
1
1
|
import SwiftUI
|
|
2
2
|
|
|
3
3
|
public func scaleSize(_ size: CGFloat, _ scaleRate: CGFloat? = nil) -> CGFloat {
|
|
4
|
-
|
|
5
|
-
let maxFontScale: CGFloat = scaleRate ?? 1.2
|
|
6
|
-
let maxDeviceScale: CGFloat = 5
|
|
7
|
-
|
|
8
|
-
let deviceWidth = UIScreen.main.bounds.width
|
|
9
|
-
let deviceScale = deviceWidth / defaultScreenSize
|
|
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
|
-
|
|
15
|
-
var fontSizeDeviceScale = size
|
|
16
|
-
var fontSizeOSScale = size
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if deviceScale > 1 {
|
|
20
|
-
fontSizeDeviceScale = min(fontSizeDeviceScale * deviceScale, fontSizeDeviceScale + maxDeviceScale)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if fontScale > 1 {
|
|
24
|
-
fontSizeOSScale = min(fontSizeOSScale * fontScale, fontSizeOSScale * maxFontScale)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return max(fontSizeDeviceScale, fontSizeOSScale)
|
|
4
|
+
return size
|
|
28
5
|
}
|
|
29
6
|
|
|
30
7
|
public enum TypographyStyle {
|