@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.
package/compose/build.gradle.kts
CHANGED
|
@@ -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
|
|
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.
|
|
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