Skip to content

Commit

Permalink
fix: update some versions & make changes for rive2.0 & add initializa…
Browse files Browse the repository at this point in the history
…tionprovider
  • Loading branch information
mjtalbot authored and zplata committed Feb 22, 2022
1 parent 6673618 commit 2e77b8e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
6 changes: 4 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "com.android.tools.build:gradle:4.0.1"
// noinspection DifferentKotlinGradleVersion
"org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Expand Down Expand Up @@ -136,6 +136,8 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'
implementation 'app.rive:rive-android:0.2.16'
implementation 'app.rive:rive-android:2.0.18'
implementation "androidx.startup:startup-runtime:1.1.0"
// implementation files("/Users/maxwelltalbot/development/rive/rive-android/kotlin/build/outputs/aar/kotlin-release.aar")
implementation 'com.android.volley:volley:1.2.0'
}
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RiveReactNative_kotlinVersion=1.4.32
RiveReactNative_kotlinVersion=1.5.20
RiveReactNative_compileSdkVersion=29
RiveReactNative_buildToolsVersion=29.0.2
RiveReactNative_targetSdkVersion=29
20 changes: 17 additions & 3 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rivereactnative">

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.rivereactnative">
<application>
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<meta-data
android:name="app.rive.runtime.kotlin.RiveInitializer"
android:value="androidx.startup"
tools:node="replace"
/>
</provider>
</application>
</manifest>
26 changes: 12 additions & 14 deletions android/src/main/java/com/rivereactnative/RiveReactNativeView.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.rivereactnative

import android.widget.FrameLayout
import androidx.startup.AppInitializer
import app.rive.runtime.kotlin.RiveAnimationView
import app.rive.runtime.kotlin.RiveDrawable
import app.rive.runtime.kotlin.RiveArtboardRenderer
import app.rive.runtime.kotlin.core.*
import app.rive.runtime.kotlin.core.errors.*
import com.android.volley.NetworkResponse
Expand Down Expand Up @@ -45,7 +46,7 @@ class RiveReactNativeView(private val context: ThemedReactContext) : FrameLayout
init {
riveAnimationView = RiveAnimationView(context)
exceptionManager = (context as ReactContext).getNativeModule(ExceptionsManagerModule::class.java)
val listener = object : RiveDrawable.Listener {
val listener = object : RiveArtboardRenderer.Listener {
override fun notifyLoop(animation: PlayableInstance) {
if (animation is LinearAnimationInstance) {
onLoopEnd(animation.animation.name, RNLoopMode.mapToRNLoopMode(animation.loop))
Expand Down Expand Up @@ -185,7 +186,7 @@ class RiveReactNativeView(private val context: ThemedReactContext) : FrameLayout
fun reset() {
url?.let {
if (resId == -1) {
riveAnimationView.drawable.reset()
riveAnimationView.renderer.reset()
}
} ?: run {
if (resId != -1) {
Expand Down Expand Up @@ -214,13 +215,11 @@ class RiveReactNativeView(private val context: ThemedReactContext) : FrameLayout
fun setFit(rnFit: RNFit) {
val riveFit = RNFit.mapToRiveFit(rnFit)
riveAnimationView.fit = riveFit
riveAnimationView.drawable.invalidateSelf() // TODO: probably it should be a responsibility of rive-android itself
}

fun setAlignment(rnAlignment: RNAlignment) {
val riveAlignment = RNAlignment.mapToRiveAlignment(rnAlignment)
riveAnimationView.alignment = riveAlignment
riveAnimationView.drawable.invalidateSelf() // TODO: probably it should be a responsibility of rive-android itself
}

fun setAutoplay(autoplay: Boolean) {
Expand Down Expand Up @@ -249,8 +248,8 @@ class RiveReactNativeView(private val context: ThemedReactContext) : FrameLayout
fit = riveAnimationView.fit,
alignment = riveAnimationView.alignment,
autoplay = false,
stateMachineName = riveAnimationView.drawable.stateMachineName,
animationName = riveAnimationView.drawable.animationName,
stateMachineName = riveAnimationView.renderer.stateMachineName,
animationName = riveAnimationView.renderer.animationName,
artboardName = riveAnimationView.artboardName
)
url = null
Expand Down Expand Up @@ -279,8 +278,8 @@ class RiveReactNativeView(private val context: ThemedReactContext) : FrameLayout
fit = riveAnimationView.fit,
alignment = riveAnimationView.alignment,
autoplay = riveAnimationView.autoplay,
stateMachineName = riveAnimationView.drawable.stateMachineName,
animationName = riveAnimationView.drawable.animationName,
stateMachineName = riveAnimationView.renderer.stateMachineName,
animationName = riveAnimationView.renderer.animationName,
artboardName = riveAnimationView.artboardName
)
url = null
Expand All @@ -306,8 +305,8 @@ class RiveReactNativeView(private val context: ThemedReactContext) : FrameLayout
fit = riveAnimationView.fit,
alignment = riveAnimationView.alignment,
autoplay = autoplay,
stateMachineName = riveAnimationView.drawable.stateMachineName,
animationName = riveAnimationView.drawable.animationName,
stateMachineName = riveAnimationView.renderer.stateMachineName,
animationName = riveAnimationView.renderer.animationName,
artboardName = riveAnimationView.artboardName
)
} catch (ex: RiveException) {
Expand All @@ -329,19 +328,18 @@ class RiveReactNativeView(private val context: ThemedReactContext) : FrameLayout
fun setArtboardName(artboardName: String) {
try {
riveAnimationView.artboardName = artboardName // it causes reloading
riveAnimationView.drawable.invalidateSelf()
} catch (ex: RiveException) {
handleRiveException(ex)
}
}

fun setAnimationName(animationName: String) {
riveAnimationView.drawable.animationName = animationName
riveAnimationView.renderer.animationName = animationName
shouldBeReloaded = true
}

fun setStateMachineName(stateMachineName: String) {
riveAnimationView.drawable.stateMachineName = stateMachineName
riveAnimationView.renderer.stateMachineName = stateMachineName
shouldBeReloaded = true
}

Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ buildscript {
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
kotlinVersion = "1.4.32"
kotlinVersion = "1.5.20"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.5.3")
classpath "com.android.tools.build:gradle:4.0.1"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit 2e77b8e

Please sign in to comment.