Skip to content

Commit a5a7f01

Browse files
committed
fix(ios): add MainActor.assumeIsolated for calls into @mainactor RiveReactNativeView
1 parent a708e08 commit a5a7f01

1 file changed

Lines changed: 42 additions & 20 deletions

File tree

ios/new/HybridRiveView.swift

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ class HybridRiveView: HybridRiveViewSpec {
7575
}
7676

7777
func playIfNeeded() {
78-
try? self.getRiveView().playIfNeeded()
78+
MainActor.assumeIsolated {
79+
try? self.getRiveView().playIfNeeded()
80+
}
7981
}
8082

8183
// MARK: View Props
@@ -107,15 +109,19 @@ class HybridRiveView: HybridRiveViewSpec {
107109
func bindViewModelInstance(viewModelInstance: (any HybridViewModelInstanceSpec)) throws {
108110
guard let vmi = (viewModelInstance as? HybridViewModelInstance)?.viewModelInstance
109111
else { return }
110-
try getRiveView().bindViewModelInstance(viewModelInstance: vmi)
112+
try MainActor.assumeIsolated {
113+
try getRiveView().bindViewModelInstance(viewModelInstance: vmi)
114+
}
111115
}
112116

113117
func getViewModelInstance() throws -> (any HybridViewModelInstanceSpec)? {
114-
guard let vmi = try getRiveView().getViewModelInstance() else { return nil }
115-
guard let hybridFile = file as? HybridRiveFile, let worker = hybridFile.worker else {
116-
throw RuntimeError.error(withMessage: "No worker available from file")
118+
return try MainActor.assumeIsolated {
119+
guard let vmi = try getRiveView().getViewModelInstance() else { return nil }
120+
guard let hybridFile = file as? HybridRiveFile, let worker = hybridFile.worker else {
121+
throw RuntimeError.error(withMessage: "No worker available from file")
122+
}
123+
return HybridViewModelInstance(viewModelInstance: vmi, worker: worker)
117124
}
118-
return HybridViewModelInstance(viewModelInstance: vmi, worker: worker)
119125
}
120126

121127
func onEventListener(onEvent: @escaping (UnifiedRiveEvent) -> Void) throws {
@@ -127,31 +133,45 @@ class HybridRiveView: HybridRiveViewSpec {
127133
}
128134

129135
func setNumberInputValue(name: String, value: Double, path: String?) throws {
130-
try getRiveView().setNumberInputValue(name: name, value: Float(value), path: path)
136+
try MainActor.assumeIsolated {
137+
try getRiveView().setNumberInputValue(name: name, value: Float(value), path: path)
138+
}
131139
}
132140

133141
func getNumberInputValue(name: String, path: String?) throws -> Double {
134-
return try Double(getRiveView().getNumberInputValue(name: name, path: path))
142+
return try MainActor.assumeIsolated {
143+
try Double(getRiveView().getNumberInputValue(name: name, path: path))
144+
}
135145
}
136146

137147
func setBooleanInputValue(name: String, value: Bool, path: String?) throws {
138-
try getRiveView().setBooleanInputValue(name: name, value: value, path: path)
148+
try MainActor.assumeIsolated {
149+
try getRiveView().setBooleanInputValue(name: name, value: value, path: path)
150+
}
139151
}
140152

141153
func getBooleanInputValue(name: String, path: String?) throws -> Bool {
142-
return try getRiveView().getBooleanInputValue(name: name, path: path)
154+
return try MainActor.assumeIsolated {
155+
try getRiveView().getBooleanInputValue(name: name, path: path)
156+
}
143157
}
144158

145159
func triggerInput(name: String, path: String?) throws {
146-
try getRiveView().triggerInput(name: name, path: path)
160+
try MainActor.assumeIsolated {
161+
try getRiveView().triggerInput(name: name, path: path)
162+
}
147163
}
148164

149165
func setTextRunValue(name: String, value: String, path: String?) throws {
150-
try getRiveView().setTextRunValue(name: name, value: value, path: path)
166+
try MainActor.assumeIsolated {
167+
try getRiveView().setTextRunValue(name: name, value: value, path: path)
168+
}
151169
}
152170

153171
func getTextRunValue(name: String, path: String?) throws -> String {
154-
return try getRiveView().getTextRunValue(name: name, path: path)
172+
return try MainActor.assumeIsolated {
173+
try getRiveView().getTextRunValue(name: name, path: path)
174+
}
155175
}
156176

157177
// MARK: Views
@@ -184,13 +204,15 @@ class HybridRiveView: HybridRiveViewSpec {
184204
bindData: try dataBind.toExperimentalBindData()
185205
)
186206

187-
let riveView = try getRiveView()
188-
riveView.configure(
189-
config, dataBindingChanged: dataBindingChanged, reload: needsReload,
190-
initialUpdate: initialUpdate)
191-
needsReload = false
192-
dataBindingChanged = false
193-
initialUpdate = false
207+
MainActor.assumeIsolated {
208+
let riveView = try getRiveView()
209+
riveView.configure(
210+
config, dataBindingChanged: dataBindingChanged, reload: needsReload,
211+
initialUpdate: initialUpdate)
212+
needsReload = false
213+
dataBindingChanged = false
214+
initialUpdate = false
215+
}
194216
}
195217
}
196218

0 commit comments

Comments
 (0)