Skip to content

Commit

Permalink
feat: added animationName, stateMachineName and artboardName prop on …
Browse files Browse the repository at this point in the history
…iOS (#39)
  • Loading branch information
TMaszko authored May 24, 2021
1 parent d4ad3d8 commit 6a8df1f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
30 changes: 27 additions & 3 deletions ios/RiveReactNativeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,31 @@ class RiveReactNativeView: UIView, PlayDelegate, PauseDelegate, StopDelegate, Lo

@objc var autoplay: Bool { // Bool? cannot be used because objc cannot interop with it
didSet {
shouldBeReloaded = true
shouldBeReloaded = true
}
}

@objc var animationName: String? {
didSet {
if let _ = animationName {
shouldBeReloaded = true
}
}
}

@objc var stateMachineName: String? {
didSet {
if let _ = stateMachineName {
shouldBeReloaded = true
}
}
}

@objc var artboardName: String? {
didSet {
if let _ = artboardName {
shouldBeReloaded = true
}
}
}

Expand Down Expand Up @@ -86,13 +110,13 @@ class RiveReactNativeView: UIView, PlayDelegate, PauseDelegate, StopDelegate, Lo
if(shouldBeReloaded) {
if let safeUrl = url {
if !resourceFromBundle {
riveView.configure(getRiveURLResource(from: safeUrl), andAutoPlay: autoplay)
riveView.configure(getRiveURLResource(from: safeUrl),andArtboard: artboardName ,andAnimation: animationName, andStateMachine: stateMachineName, andAutoPlay: autoplay)
} else {
fatalError("You cannot pass both resourceName and url at the same time")
}
} else {
if resourceFromBundle, let safeResourceName = resourceName {
riveView.configure(getRiveFile(resourceName: safeResourceName), andAutoPlay: autoplay)
riveView.configure(getRiveFile(resourceName: safeResourceName),andArtboard: artboardName, andAnimation: animationName, andStateMachine: stateMachineName, andAutoPlay: autoplay)
} else {
fatalError("You must provide a url or a resourceName!")
}
Expand Down
3 changes: 3 additions & 0 deletions ios/RiveReactNativeViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ @interface RCT_EXTERN_MODULE(RiveReactNativeViewManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(fit, NSString)
RCT_EXPORT_VIEW_PROPERTY(alignment, NSString)
RCT_EXPORT_VIEW_PROPERTY(autoplay, BOOL)
RCT_EXPORT_VIEW_PROPERTY(animationName, NSString)
RCT_EXPORT_VIEW_PROPERTY(artboardName, NSString)
RCT_EXPORT_VIEW_PROPERTY(stateMachineName, NSString)
RCT_EXPORT_VIEW_PROPERTY(onPlay, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPause, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onStop, RCTDirectEventBlock)
Expand Down

0 comments on commit 6a8df1f

Please sign in to comment.