refactor(ios): shared property listener implementation#55
Merged
Conversation
mfazekas
previously approved these changes
Nov 29, 2025
| func removeListeners() throws { | ||
| for id in listenerIds { | ||
| property.removeListener(id) | ||
| helper.trackListener { property in |
Collaborator
There was a problem hiding this comment.
Nice!
Btw can't we make a helper.addListener?! that does call trackListener and property.addListener?!
Contributor
Author
There was a problem hiding this comment.
I'm cleaning this up!
HayesGordon
commented
Dec 1, 2025
| } | ||
|
|
||
| /// Automatic addListener() ONLY when ListenerValueType == ValueType (no conversion needed) | ||
| extension ValuedPropertyProtocol where PropertyType.ListenerValueType == ValueType { |
Contributor
Author
There was a problem hiding this comment.
We now automatically also handle adding a listener if the native type and the converted type is the same. If not, you have to provide the addListener implementation.
HayesGordon
commented
Dec 1, 2025
| extension ColorPropertyType: RivePropertyWithListeners { | ||
| typealias ListenerValueType = UIColor // Native: UIColor → Double (needs conversion) | ||
| } | ||
| // Note: TriggerProperty doesn't fit the pattern - it has () -> Void listeners, not (Void) -> Void |
Contributor
Author
There was a problem hiding this comment.
For some classes we won't be able to make use of this abstraction. But I think that is okay, we'll have 80% shared code, and things like Triggers and Lists will need to be custom.
mfazekas
approved these changes
Dec 1, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This might be overkill. But I noticed in this PR, how much nicer the Kotlin code is.
I tried back in the day to abstract the Swift code but the properties don't inherit from the same base. This is another attempt by adding protocol extensions + composition with a helper class.