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

feat: begin work on adding Ktlint / Android build step to the repo #1152

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ internal object LottieAnimationViewManagerImpl {

@JvmStatic
val exportedViewConstants: Map<String, Any>
get() = MapBuilder.builder<String, Any>()
.put("VERSION", 1)
.build()
get() =
MapBuilder.builder<String, Any>()
.put("VERSION", 1)
.build()

@JvmStatic
fun createViewInstance(context: ThemedReactContext): LottieAnimationView {
Expand All @@ -30,28 +31,34 @@ internal object LottieAnimationViewManagerImpl {
}

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

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

Expand All @@ -63,7 +70,7 @@ internal object LottieAnimationViewManagerImpl {
OnAnimationLoadedEvent(
screenContext.surfaceId,
view.id,
)
),
)
}

Expand All @@ -80,7 +87,11 @@ internal object LottieAnimationViewManagerImpl {
}

@JvmStatic
fun play(view: LottieAnimationView, startFrame: Int, endFrame: Int) {
fun play(
view: LottieAnimationView,
startFrame: Int,
endFrame: Int,
) {
Handler(Looper.getMainLooper()).post {
if (startFrame != -1 && endFrame != -1) {
if (startFrame > endFrame) {
Expand All @@ -99,19 +110,21 @@ internal object LottieAnimationViewManagerImpl {
view.progress = 0f
view.playAnimation()
} else {
view.addOnAttachStateChangeListener(object : OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View) {
val listenerView = v as LottieAnimationView
listenerView.progress = 0f
listenerView.playAnimation()
listenerView.removeOnAttachStateChangeListener(this)
}

override fun onViewDetachedFromWindow(v: View) {
val listenerView = v as LottieAnimationView
listenerView.removeOnAttachStateChangeListener(this)
}
})
view.addOnAttachStateChangeListener(
object : OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View) {
val listenerView = v as LottieAnimationView
listenerView.progress = 0f
listenerView.playAnimation()
listenerView.removeOnAttachStateChangeListener(this)
}

override fun onViewDetachedFromWindow(v: View) {
val listenerView = v as LottieAnimationView
listenerView.removeOnAttachStateChangeListener(this)
}
},
)
}
}
}
Expand Down Expand Up @@ -147,7 +160,7 @@ internal object LottieAnimationViewManagerImpl {
@JvmStatic
fun setSourceName(
name: String?,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
// To match the behaviour on iOS we expect the source name to be
// extensionless. This means "myAnimation" corresponds to a file
Expand All @@ -165,7 +178,7 @@ internal object LottieAnimationViewManagerImpl {
@JvmStatic
fun setSourceJson(
json: String?,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
viewManager.animationJson = json
viewManager.commitChanges()
Expand All @@ -174,7 +187,7 @@ internal object LottieAnimationViewManagerImpl {
@JvmStatic
fun setSourceURL(
urlString: String?,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
viewManager.animationURL = urlString
viewManager.commitChanges()
Expand All @@ -183,21 +196,24 @@ internal object LottieAnimationViewManagerImpl {
@JvmStatic
fun setSourceDotLottieURI(
uri: String?,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
viewManager.sourceDotLottie = uri
viewManager.commitChanges()
}

@JvmStatic
fun setCacheComposition(view: LottieAnimationView, cacheComposition: Boolean) {
fun setCacheComposition(
view: LottieAnimationView,
cacheComposition: Boolean,
) {
view.setCacheComposition(cacheComposition)
}

@JvmStatic
fun setResizeMode(
resizeMode: String?,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
var mode: ImageView.ScaleType? = null
when (resizeMode) {
Expand All @@ -219,7 +235,7 @@ internal object LottieAnimationViewManagerImpl {
@JvmStatic
fun setRenderMode(
renderMode: String?,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
var mode: RenderMode? = null
when (renderMode) {
Expand All @@ -241,7 +257,7 @@ internal object LottieAnimationViewManagerImpl {
@JvmStatic
fun setHardwareAcceleration(
hardwareAccelerationAndroid: Boolean,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
var layerType: Int? = View.LAYER_TYPE_SOFTWARE
if (hardwareAccelerationAndroid) {
Expand All @@ -253,64 +269,64 @@ internal object LottieAnimationViewManagerImpl {
@JvmStatic
fun setProgress(
progress: Float,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
viewManager.progress = progress
}

@JvmStatic
fun setSpeed(
speed: Double,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
viewManager.speed = speed.toFloat()
}

@JvmStatic
fun setLoop(
loop: Boolean,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
viewManager.loop = loop
}

@JvmStatic
fun setAutoPlay(
autoPlay: Boolean,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
viewManager.autoPlay = autoPlay
}

@JvmStatic
fun setEnableMergePaths(
enableMergePaths: Boolean,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
viewManager.enableMergePaths = enableMergePaths
}

@JvmStatic
fun setImageAssetsFolder(
imageAssetsFolder: String?,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
viewManager.imageAssetsFolder = imageAssetsFolder
}

@JvmStatic
fun setColorFilters(
colorFilters: ReadableArray?,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
viewManager.colorFilters = colorFilters
}

@JvmStatic
fun setTextFilters(
textFilters: ReadableArray?,
viewManager: LottieAnimationViewPropertyManager
viewManager: LottieAnimationViewPropertyManager,
) {
viewManager.textFilters = textFilters
}
}
}
Loading
Loading