@momo-kits/native-kits 0.151.2-test.17 → 0.151.2-test.18

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.
@@ -6,6 +6,7 @@ import android.graphics.BlurMaskFilter
6
6
  import android.graphics.PorterDuff
7
7
  import android.graphics.PorterDuffColorFilter
8
8
  import android.os.Build
9
+ import androidx.compose.foundation.layout.Box
9
10
  import androidx.compose.runtime.Composable
10
11
  import androidx.compose.runtime.getValue
11
12
  import androidx.compose.ui.Modifier
@@ -71,8 +72,15 @@ actual fun LottieAnimation(
71
72
  bgColor: Color?,
72
73
  modifier: Modifier
73
74
  ) {
75
+ val json = readJson(path)
76
+
77
+ if (json.isEmpty()) {
78
+ Box(modifier)
79
+ return
80
+ }
81
+
74
82
  val composition by rememberLottieComposition(
75
- LottieCompositionSpec.JsonString(readJson(path))
83
+ LottieCompositionSpec.JsonString(json)
76
84
  )
77
85
 
78
86
  val colorFilter = PorterDuffColorFilter(
@@ -91,7 +99,7 @@ actual fun LottieAnimation(
91
99
  LottieAnimation(
92
100
  composition = composition,
93
101
  iterations = LottieConstants.IterateForever,
94
- dynamicProperties = if (tintColor != null ) dynamicProperties else null,
102
+ dynamicProperties = if (tintColor != null) dynamicProperties else null,
95
103
  modifier = modifier
96
104
  )
97
- }
105
+ }
@@ -27,16 +27,21 @@ fun readJson(name: String): String {
27
27
 
28
28
  val jsonContent by rememberState(path, { "" }) {
29
29
  val cached = resourceCache.getOrPut(path) {
30
- ResourceCache.JSON(
30
+ val content = try {
31
31
  readResourceBytes(path).decodeToString()
32
- )
32
+ } catch (_: Exception) {
33
+ ""
34
+ }
35
+ ResourceCache.JSON(content)
33
36
  } as ResourceCache.JSON
37
+
34
38
  cached.json
35
39
  }
36
40
 
37
41
  return jsonContent
38
42
  }
39
43
 
44
+
40
45
  private val resourceCache = mutableMapOf<String, ResourceCache>()
41
46
 
42
47
  private sealed interface ResourceCache {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.151.2-test.17",
3
+ "version": "0.151.2-test.18",
4
4
  "private": false,
5
5
  "dependencies": {
6
6
  "@momo-platform/native-max-api": "1.0.18"