-
Notifications
You must be signed in to change notification settings - Fork 59
Single drawable #87
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
Single drawable #87
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,15 +30,10 @@ import java.util.* | |
| */ | ||
| class RiveAnimationView(context: Context, attrs: AttributeSet? = null) : View(context, attrs), | ||
| Observable<RiveDrawable.Listener> { | ||
| // TODO: stop creating an empty drawable to begin with. | ||
| private var _drawable: RiveDrawable = RiveDrawable(); | ||
| private var resourceId: Int? = null; | ||
|
|
||
| var drawable: RiveDrawable | ||
| get() = _drawable | ||
| private set(value) { | ||
| _drawable = value | ||
| } | ||
| // There's always just one drawable associated with an animation view | ||
| val drawable = RiveDrawable() | ||
|
|
||
| private var resourceId: Int? = null | ||
|
|
||
| var fit: Fit | ||
| get() = drawable.fit | ||
|
|
@@ -117,12 +112,12 @@ class RiveAnimationView(context: Context, attrs: AttributeSet? = null) : View(co | |
| animationName = animationName, | ||
| ) | ||
| } else { | ||
| drawable.alignment = Alignment.values()[alignmentIndex]; | ||
| drawable.fit = Fit.values()[fitIndex]; | ||
| drawable.loop = Loop.values()[loopIndex]; | ||
| drawable.autoplay = autoplay; | ||
| drawable.artboardName = artboardName; | ||
| drawable.animationName = animationName; | ||
| drawable.alignment = Alignment.values()[alignmentIndex] | ||
| drawable.fit = Fit.values()[fitIndex] | ||
| drawable.loop = Loop.values()[loopIndex] | ||
| drawable.autoplay = autoplay | ||
| drawable.artboardName = artboardName | ||
| drawable.animationName = animationName | ||
| } | ||
|
|
||
| } finally { | ||
|
|
@@ -295,12 +290,12 @@ class RiveAnimationView(context: Context, attrs: AttributeSet? = null) : View(co | |
| */ | ||
| fun setRiveResource( | ||
| @RawRes resId: Int, | ||
| artboardName: String? = drawable.artboardName, | ||
| animationName: String? = drawable.animationName, | ||
| artboardName: String? = null, | ||
| animationName: String? = null, | ||
| autoplay: Boolean = drawable.autoplay, | ||
| fit: Fit = drawable.fit, | ||
| alignment: Alignment = drawable.alignment, | ||
| loop: Loop = drawable.loop, | ||
| fit: Fit = Fit.CONTAIN, | ||
| alignment: Alignment = Alignment.CENTER, | ||
| loop: Loop = Loop.NONE, | ||
| ) { | ||
| resourceId = resId | ||
| val bytes = resources.openRawResource(resId).readBytes() | ||
|
|
@@ -329,12 +324,12 @@ class RiveAnimationView(context: Context, attrs: AttributeSet? = null) : View(co | |
| */ | ||
| fun setRiveBytes( | ||
| bytes: ByteArray, | ||
| artboardName: String? = drawable.artboardName, | ||
| animationName: String? = drawable.animationName, | ||
| artboardName: String? = null, | ||
| animationName: String? = null, | ||
| autoplay: Boolean = drawable.autoplay, | ||
| fit: Fit = drawable.fit, | ||
| alignment: Alignment = drawable.alignment, | ||
| loop: Loop = drawable.loop, | ||
| fit: Fit = Fit.CONTAIN, | ||
| alignment: Alignment = Alignment.CENTER, | ||
| loop: Loop = Loop.NONE, | ||
| ) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure the way these initialize make sense; if we're setting the Rive file multiple times, it'll reuse the first one's artboard and animation names if they're not specified, which will probably cause new files to explode. Better to have those reset to null so defaults can be chosen? Same wit the other parameters; best to have everything reset to defaults?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah i think so |
||
| val file = File(bytes) | ||
| setRiveFile( | ||
|
|
@@ -360,27 +355,22 @@ class RiveAnimationView(context: Context, attrs: AttributeSet? = null) : View(co | |
| * | ||
| * @throws [RiveException] if [artboardName] or [animationName] are set and do not exist in the file. | ||
| */ | ||
| fun setRiveFile( | ||
| private fun setRiveFile( | ||
| file: File, | ||
| artboardName: String? = drawable.artboardName, | ||
| animationName: String? = drawable.animationName, | ||
| autoplay: Boolean = drawable.autoplay, | ||
| fit: Fit = drawable.fit, | ||
| alignment: Alignment = drawable.alignment, | ||
| loop: Loop = drawable.loop, | ||
| artboardName: String?, | ||
| animationName: String?, | ||
| autoplay: Boolean, | ||
| fit: Fit, | ||
| alignment: Alignment, | ||
| loop: Loop, | ||
| ) { | ||
| drawable.destroy() | ||
|
|
||
| // TODO: we maybe not be cleaning something up here, | ||
| // as we shouldnt have create a new drawable | ||
| drawable = RiveDrawable( | ||
| fit = fit, | ||
| alignment = alignment, | ||
| loop = loop, | ||
| autoplay = autoplay, | ||
| animationName = animationName, | ||
| artboardName = artboardName, | ||
| ) | ||
| drawable.clear() | ||
| drawable.fit = fit | ||
| drawable.alignment = alignment | ||
| drawable.loop = loop | ||
| drawable.autoplay = autoplay | ||
| drawable.animationName = animationName | ||
| drawable.artboardName = artboardName | ||
|
|
||
| drawable.setRiveFile(file) | ||
| background = drawable | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.