Skip to content

Commit

Permalink
feat: add Android implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRogue76 committed Apr 12, 2024
1 parent a2ba511 commit 016cea0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Expand Up @@ -29,6 +29,18 @@ internal object LottieAnimationViewManagerImpl {
}
}

@JvmStatic
fun sendOnAnimationLoadStartEvent(view: LottieAnimationView) {
val screenContext = view.context as ThemedReactContext
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(screenContext, view.id)
eventDispatcher?.dispatchEvent(
OnAnimationLoadStartEvent(
screenContext.surfaceId,
view.id
)
)
}

@JvmStatic
fun sendOnAnimationFinishEvent(view: LottieAnimationView, isCancelled: Boolean) {
val screenContext = view.context as ThemedReactContext
Expand Down
@@ -0,0 +1,19 @@
package com.airbnb.android.react.lottie

import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.WritableMap
import com.facebook.react.uimanager.events.Event

class OnAnimationLoadStartEvent constructor(surfaceId: Int, viewId: Int) :
Event<OnAnimationLoadStartEvent>(surfaceId, viewId) {
override fun getEventName(): String {
return EVENT_NAME
}

override fun getEventData(): WritableMap? {
return Arguments.createMap()
}
companion object {
const val EVENT_NAME = "topAnimationLoadStart"
}
}
Expand Up @@ -124,21 +124,25 @@ class LottieAnimationViewManager :

@ReactProp(name = "sourceName")
override fun setSourceName(view: LottieAnimationView, name: String?) {
LottieAnimationViewManagerImpl.sendOnAnimationLoadStartEvent(view)
setSourceName(name, getOrCreatePropertyManager(view))
}

@ReactProp(name = "sourceJson")
override fun setSourceJson(view: LottieAnimationView, json: String?) {
LottieAnimationViewManagerImpl.sendOnAnimationLoadStartEvent(view)
setSourceJson(json, getOrCreatePropertyManager(view))
}

@ReactProp(name = "sourceURL")
override fun setSourceURL(view: LottieAnimationView, urlString: String?) {
LottieAnimationViewManagerImpl.sendOnAnimationLoadStartEvent(view)
setSourceURL(urlString, getOrCreatePropertyManager(view))
}

@ReactProp(name = "sourceDotLottieURI")
override fun setSourceDotLottieURI(view: LottieAnimationView, urlString: String?) {
LottieAnimationViewManagerImpl.sendOnAnimationLoadStartEvent(view)
setSourceDotLottieURI(urlString, getOrCreatePropertyManager(view))
}

Expand Down
Expand Up @@ -102,16 +102,19 @@ class LottieAnimationViewManager : SimpleViewManager<LottieAnimationView>() {

@ReactProp(name = "sourceName")
fun setSourceName(view: LottieAnimationView, name: String?) {
LottieAnimationViewManagerImpl.sendOnAnimationLoadStartEvent(view)
setSourceName(name, getOrCreatePropertyManager(view))
}

@ReactProp(name = "sourceJson")
fun setSourceJson(view: LottieAnimationView, json: String?) {
LottieAnimationViewManagerImpl.sendOnAnimationLoadStartEvent(view)
setSourceJson(json, getOrCreatePropertyManager(view))
}

@ReactProp(name = "sourceURL")
fun setSourceURL(view: LottieAnimationView, urlString: String?) {
LottieAnimationViewManagerImpl.sendOnAnimationLoadStartEvent(view)
setSourceURL(urlString, getOrCreatePropertyManager(view))
}

Expand Down Expand Up @@ -180,6 +183,7 @@ class LottieAnimationViewManager : SimpleViewManager<LottieAnimationView>() {

@ReactProp(name = "sourceDotLottieURI")
fun setSourceDotLottie(view: LottieAnimationView, uri: String?) {
LottieAnimationViewManagerImpl.sendOnAnimationLoadStartEvent(view)
setSourceDotLottieURI(uri, getOrCreatePropertyManager(view))
}

Expand Down

0 comments on commit 016cea0

Please sign in to comment.