Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade android lottie to 6.1.0 #1060

Merged
merged 2 commits into from Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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