@momo-kits/native-kits 0.157.1-test.3-debug → 0.157.1-test.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.
@@ -40,7 +40,7 @@ kotlin {
40
40
  }
41
41
 
42
42
  cocoapods {
43
- version = "0.157.1-test.3-debug"
43
+ version = "0.157.1-test.4-debug"
44
44
  summary = "IOS Shared module"
45
45
  homepage = "https://momo.vn"
46
46
  ios.deploymentTarget = "15.0"
@@ -25,6 +25,7 @@ import com.airbnb.lottie.compose.rememberLottieDynamicProperties
25
25
  import com.airbnb.lottie.compose.rememberLottieDynamicProperty
26
26
  import vn.momo.kits.const.AppNavigationBar
27
27
  import vn.momo.kits.const.AppStatusBar
28
+ import vn.momo.kits.utils.readJson
28
29
  import androidx.activity.compose.BackHandler as AndroidBackHandler
29
30
 
30
31
  actual fun getPlatformName(): String = "Android"
@@ -71,9 +72,15 @@ actual fun LottieAnimation(
71
72
  bgColor: Color?,
72
73
  modifier: Modifier
73
74
  ) {
74
- val assetPath = "composeResources/vn.momo.compose.resources/files/${path}.json"
75
+ val json = readJson(path)
76
+
77
+ if (json.isEmpty()) {
78
+ Box(modifier)
79
+ return
80
+ }
81
+
75
82
  val composition by rememberLottieComposition(
76
- LottieCompositionSpec.Asset(assetPath)
83
+ LottieCompositionSpec.JsonString(json)
77
84
  )
78
85
 
79
86
  val colorFilter = PorterDuffColorFilter(
@@ -18,4 +18,45 @@ fun getResource(name: String): DrawableResource {
18
18
  "drawable:$name",
19
19
  setOf(ResourceItem(setOf(), "drawable/$name", -1, -1))
20
20
  )
21
+ }
22
+
23
+ @OptIn(InternalResourceApi::class)
24
+ @Composable
25
+ fun readJson(name: String): String {
26
+ val path = name.plus(".json")
27
+
28
+ val jsonContent by rememberState(path, { "" }) {
29
+ val cached = resourceCache.getOrPut(path) {
30
+ val content = try {
31
+ readResourceBytes(path).decodeToString()
32
+ } catch (_: Exception) {
33
+ ""
34
+ }
35
+ ResourceCache.JSON(content)
36
+ } as ResourceCache.JSON
37
+
38
+ cached.json
39
+ }
40
+
41
+ return jsonContent
42
+ }
43
+
44
+
45
+ private val resourceCache = mutableMapOf<String, ResourceCache>()
46
+
47
+ private sealed interface ResourceCache {
48
+ class JSON(val json: String) : ResourceCache
49
+ }
50
+
51
+ @Composable
52
+ fun <T> rememberState(
53
+ key: Any,
54
+ getDefault: () -> T,
55
+ block: suspend () -> T
56
+ ): MutableState<T> {
57
+ val state = remember(key) { mutableStateOf(getDefault()) }
58
+ LaunchedEffect(key) {
59
+ state.value = block()
60
+ }
61
+ return state
21
62
  }
package/gradle.properties CHANGED
@@ -18,7 +18,7 @@ kotlin.apple.xcodeCompatibility.nowarn=true
18
18
  name="ComposeKits"
19
19
  group=vn.momo.kits
20
20
  artifact.id=kits
21
- version=0.157.1-test.3
21
+ version=0.157.1-test.4
22
22
 
23
23
  repo=GitLab
24
24
  url=https://gitlab.mservice.com.vn/api/v4/projects/5400/packages/maven
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.157.1-test.3-debug",
3
+ "version": "0.157.1-test.4-debug",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},