@@ -18,6 +18,7 @@ struct ExperimentalViewConfiguration {
1818 let bindData : ExperimentalBindData
1919}
2020
21+ @MainActor
2122class RiveReactNativeView : UIView {
2223 private var riveUIView : RiveUIView ?
2324 private var riveInstance : RiveRuntime . Rive ?
@@ -39,6 +40,7 @@ class RiveReactNativeView: UIView {
3940 }
4041
4142 func configure( _ config: ExperimentalViewConfiguration , dataBindingChanged: Bool = false , reload: Bool = false , initialUpdate: Bool = false ) {
43+ dispatchPrecondition ( condition: . onQueue( . main) )
4244 RCTLog ( " [RiveReactNativeView] configure called - reload: \( reload) , dataBindingChanged: \( dataBindingChanged) , initialUpdate: \( initialUpdate) " )
4345
4446 if reload {
@@ -47,11 +49,8 @@ class RiveReactNativeView: UIView {
4749
4850 if reload || dataBindingChanged || initialUpdate {
4951 configTask? . cancel ( )
50- configTask = Task { @MainActor [ weak self] in
51- guard let self else {
52- RCTLogError ( " [RiveReactNativeView] self is nil in config task " )
53- return
54- }
52+ configTask = Task { [ weak self] in
53+ guard let self else { return }
5554 do {
5655 RCTLog ( " [RiveReactNativeView] Creating artboard: \( config. artboardName ?? " default " ) " )
5756 let artboard = try await config. file. createArtboard ( config. artboardName)
@@ -79,7 +78,8 @@ class RiveReactNativeView: UIView {
7978 let vmi = try await config. file. createViewModelInstance ( . name( name, from: . name( vmInfo. viewModelName) ) )
8079 dataBind = . instance( vmi)
8180 }
82- RCTLog ( " [RiveReactNativeView] DataBind set to: \( dataBind) " )
81+
82+ guard !Task. isCancelled else { return }
8383
8484 RCTLog ( " [RiveReactNativeView] Creating Rive instance... " )
8585 let rive = try await RiveRuntime . Rive (
@@ -88,8 +88,10 @@ class RiveReactNativeView: UIView {
8888 stateMachine: stateMachine,
8989 dataBind: dataBind
9090 )
91- RCTLog ( " [RiveReactNativeView] Rive instance created successfully " )
9291
92+ guard !Task. isCancelled else { return }
93+
94+ RCTLog ( " [RiveReactNativeView] Rive instance created successfully " )
9395 self . riveInstance = rive
9496 RCTLog ( " [RiveReactNativeView] Setting up RiveUIView... " )
9597 self . setupRiveUIView ( with: rive)
@@ -127,17 +129,14 @@ class RiveReactNativeView: UIView {
127129 return riveInstance? . viewModelInstance
128130 }
129131
130- @MainActor
131132 func play( ) {
132133 isPaused = false
133134 }
134135
135- @MainActor
136136 func pause( ) {
137137 isPaused = true
138138 }
139139
140- @MainActor
141140 func reset( ) {
142141 isPaused = true
143142 }
@@ -206,6 +205,7 @@ class RiveReactNativeView: UIView {
206205 }
207206
208207 private func cleanup( ) {
208+ dispatchPrecondition ( condition: . onQueue( . main) )
209209 configTask? . cancel ( )
210210 configTask = nil
211211 riveUIView? . removeFromSuperview ( )
@@ -214,6 +214,8 @@ class RiveReactNativeView: UIView {
214214 }
215215
216216 deinit {
217- cleanup ( )
217+ MainActor . assumeIsolated {
218+ cleanup ( )
219+ }
218220 }
219221}
0 commit comments