-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add data binding lists support #71
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
Open
mfazekas
wants to merge
10
commits into
main
Choose a base branch
from
mfazekas/data-binding-lists
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e3850ab
feat: add data binding lists support
mfazekas 307dddc
fix: throw error instead of silently ignoring invalid ViewModelInstan…
mfazekas c0a8457
fix(ios): use fully qualified RiveDataBindingViewModel.Instance type
mfazekas 788cbc0
feat: add data binding lists example with list.riv
mfazekas 21ad4d3
refactor: rename list property methods to match iOS SDK and react-hoo…
mfazekas a5e1d33
fix: call playIfNeeded after list modifications, remove unused defaul…
mfazekas 6086a3c
refactor: rename list property methods to match rive-react API
mfazekas c138731
fix: handle swap returning void in native SDKs, fix listeners lambda
mfazekas 90abc54
fix: explicitly type Unit parameter in listeners lambda
mfazekas adbaae6
fix: addListener returns remover function
mfazekas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
android/src/main/java/com/margelo/nitro/rive/HybridViewModelListProperty.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.margelo.nitro.rive | ||
|
|
||
| import androidx.annotation.Keep | ||
| import app.rive.runtime.kotlin.core.ViewModelListProperty | ||
| import com.facebook.proguard.annotations.DoNotStrip | ||
| import kotlinx.coroutines.flow.map | ||
|
|
||
| @Keep | ||
| @DoNotStrip | ||
| class HybridViewModelListProperty(private val listProperty: ViewModelListProperty) : | ||
| HybridViewModelListPropertySpec(), | ||
| BaseHybridViewModelProperty<Unit> by BaseHybridViewModelPropertyImpl() { | ||
| override val length: Double | ||
| get() = listProperty.size.toDouble() | ||
|
|
||
| private fun requireHybridInstance(instance: HybridViewModelInstanceSpec): HybridViewModelInstance { | ||
| return instance as? HybridViewModelInstance | ||
| ?: throw IllegalArgumentException("Expected HybridViewModelInstance but got ${instance::class.simpleName}") | ||
| } | ||
|
|
||
| override fun getInstanceAt(index: Double): HybridViewModelInstanceSpec? { | ||
| val idx = index.toInt() | ||
| if (idx < 0 || idx >= listProperty.size) return null | ||
| return HybridViewModelInstance(listProperty.elementAt(idx)) | ||
| } | ||
|
|
||
| override fun addInstance(instance: HybridViewModelInstanceSpec) { | ||
| val hybridInstance = requireHybridInstance(instance) | ||
| listProperty.add(hybridInstance.viewModelInstance) | ||
| } | ||
|
|
||
| override fun addInstanceAt(instance: HybridViewModelInstanceSpec, index: Double): Boolean { | ||
| val hybridInstance = requireHybridInstance(instance) | ||
| val idx = index.toInt() | ||
| if (idx < 0 || idx > listProperty.size) return false | ||
| listProperty.add(idx, hybridInstance.viewModelInstance) | ||
| return true | ||
| } | ||
|
|
||
| override fun removeInstance(instance: HybridViewModelInstanceSpec) { | ||
| val hybridInstance = requireHybridInstance(instance) | ||
| listProperty.remove(hybridInstance.viewModelInstance) | ||
| } | ||
|
|
||
| override fun removeInstanceAt(index: Double) { | ||
| listProperty.removeAt(index.toInt()) | ||
| } | ||
|
|
||
| override fun swap(index1: Double, index2: Double): Boolean { | ||
| val idx1 = index1.toInt() | ||
| val idx2 = index2.toInt() | ||
| if (idx1 < 0 || idx1 >= listProperty.size || idx2 < 0 || idx2 >= listProperty.size) { | ||
| return false | ||
| } | ||
| listProperty.swap(idx1, idx2) | ||
| return true | ||
| } | ||
|
|
||
| override fun addListener(onChanged: () -> Unit): () -> Unit { | ||
| val remover = addListenerInternal { _ -> onChanged() } | ||
| ensureValueListenerJob(listProperty.valueFlow.map { }) | ||
| return remover | ||
| } | ||
| } |
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! This is what we did from the start. Nice abstration then!