@momo-kits/native-kits 0.118.0-beta.1 → 0.118.0-beta.5

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,7 +2,6 @@ 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
@@ -13,42 +12,28 @@ import org.jetbrains.compose.resources.FontResource
13
12
  import org.jetbrains.compose.resources.InternalResourceApi
14
13
  import org.jetbrains.compose.resources.ResourceItem
15
14
  import vn.momo.kits.platform.getScreenDimensions
16
- import kotlin.math.min
17
15
 
18
16
  const val DEFAULT_SCREEN_SIZE = 375f
19
- const val MAX_FONT_SCALE = 1.2f
20
- const val MAX_DEVICE_SCALE = 5
21
17
 
22
18
  @Composable
23
19
  fun scaleSize(size: Float): Float {
24
20
  val deviceWidth = getScreenDimensions().width
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)
21
+ val scaleRate = deviceWidth / DEFAULT_SCREEN_SIZE
22
+ if (scaleRate > 1) {
23
+ return if ((scaleRate * size) > (size + 5)) size + 5 else scaleRate * size
34
24
  }
35
-
36
- if (fontScale > 1) {
37
- fontSize = min(fontScale * fontSize, fontSize * MAX_FONT_SCALE)
38
- }
39
-
40
- return fontSize
25
+ return size
41
26
  }
42
27
 
43
28
  @OptIn(InternalResourceApi::class)
44
29
  @Composable
45
30
  fun getFont(font: String): FontFamily {
46
31
  val fontResource = FontResource(
47
- "font:${font.substringBeforeLast(".")}",
32
+ "font:${font.substringBeforeLast("-")}",
48
33
  setOf(
49
34
  ResourceItem(
50
35
  setOf(),
51
- "font/${font.substringBeforeLast(".")}.${font.substringAfterLast(".")}",
36
+ "composeResources/vn.momo.compose.resources/font/${font.substringBeforeLast(".")}.${font.substringAfterLast(".")}",
52
37
  -1,
53
38
  -1
54
39
  )
@@ -2,28 +2,7 @@ import SwiftUI
2
2
 
3
3
  public extension Font {
4
4
  static func appFont(size: CGFloat) -> Font {
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)
5
+ return Font.system(size: size)
27
6
  }
28
7
 
29
8
  // New supported typography styles
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.118.0-beta.1",
3
+ "version": "0.118.0-beta.5",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},