From 6a8df1f8041ad73f17f42b8fc21dfb7150f47b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Krzy=C5=BCowski?= Date: Mon, 24 May 2021 12:55:19 +0200 Subject: [PATCH] feat: added animationName, stateMachineName and artboardName prop on iOS (#39) --- ios/RiveReactNativeView.swift | 30 +++++++++++++++++++++++++++--- ios/RiveReactNativeViewManager.m | 3 +++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/ios/RiveReactNativeView.swift b/ios/RiveReactNativeView.swift index 5d26edb..a8cc34f 100644 --- a/ios/RiveReactNativeView.swift +++ b/ios/RiveReactNativeView.swift @@ -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 + } } } @@ -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!") } diff --git a/ios/RiveReactNativeViewManager.m b/ios/RiveReactNativeViewManager.m index e795634..5871d50 100644 --- a/ios/RiveReactNativeViewManager.m +++ b/ios/RiveReactNativeViewManager.m @@ -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)