Skip to content

Commit

Permalink
chore: upgrade android lottie to 6.1.0 (#1060)
Browse files Browse the repository at this point in the history
* chore: upgrade android lottie to 6.1.0

* remove redundant import
  • Loading branch information
matinzd committed Jul 24, 2023
1 parent f6b56ad commit f00907b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion apps/paper/src/LottieAnimatedExample.tsx
Expand Up @@ -100,7 +100,7 @@ const LottieAnimatedExample = () => {
onAnimationFinish={onAnimationFinish}
enableMergePathsAndroidForKitKatAndAbove
renderMode={renderMode}
resizeMode={'cover'}
resizeMode={'contain'}
/>
</View>
<View style={{paddingBottom: 20, paddingHorizontal: 10}}>
Expand Down
3 changes: 1 addition & 2 deletions packages/core/android/build.gradle
Expand Up @@ -118,12 +118,11 @@ def kotlin_version = getExtOrDefault('kotlinVersion', project.properties['lottie

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'

//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules

implementation "com.airbnb.android:lottie:6.0.0"
implementation "com.airbnb.android:lottie:6.1.0"
}

if (isNewArchitectureEnabled()) {
Expand Down
Expand Up @@ -12,11 +12,6 @@ import com.facebook.react.bridge.ReadableArray
import com.facebook.react.common.MapBuilder
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.util.RNLog
import kotlinx.coroutines.*
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.URL

internal object LottieAnimationViewManagerImpl {
const val REACT_CLASS = "LottieAnimationView"
Expand Down Expand Up @@ -141,32 +136,19 @@ internal object LottieAnimationViewManagerImpl {
@JvmStatic
fun setSourceJson(
json: String?,
propManagersMap: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager
) {
propManagersMap.animationJson = json
propManagersMap.commitChanges()
viewManager.animationJson = json
viewManager.commitChanges()
}

@JvmStatic
fun setSourceURL(
urlString: String?,
propManagersMap: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager
) {
CoroutineScope(Dispatchers.Main).launch {
try {
val jsonString = withContext(Dispatchers.IO) {
URL(urlString).openStream().use {
BufferedReader(InputStreamReader(it)).useLines { lines ->
lines.joinToString("\n")
}
}
}
propManagersMap.animationJson = jsonString
propManagersMap.commitChanges()
} catch (e: Exception) {
RNLog.l("Error while loading animation from URL")
}
}
viewManager.animationURL = urlString
viewManager.commitChanges()
}

@JvmStatic
Expand Down
Expand Up @@ -46,6 +46,7 @@ class LottieAnimationViewPropertyManager(view: LottieAnimationView) {
var renderMode: RenderMode? = null
var layerType: Int? = null
var animationJson: String? = null
var animationURL: String? = null
var progress: Float? = null
var loop: Boolean? = null
var autoPlay: Boolean? = null
Expand Down Expand Up @@ -84,6 +85,11 @@ class LottieAnimationViewPropertyManager(view: LottieAnimationView) {
animationJson = null
}

animationURL?.let {
view.setAnimationFromUrl(it, it.hashCode().toString())
animationURL = null
}

if (animationNameDirty) {
view.setAnimation(animationName)
animationNameDirty = false
Expand All @@ -103,7 +109,6 @@ class LottieAnimationViewPropertyManager(view: LottieAnimationView) {
if (it && !view.isAnimating) {
view.playAnimation()
}
autoPlay = null
}

speed?.let {
Expand Down

0 comments on commit f00907b

Please sign in to comment.