Skip to content

Commit 62c426b

Browse files
committed
fix(ios): make onMainSync provide @mainactor isolation, fix infinite recursion
1 parent 5b09da0 commit 62c426b

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

ios/new/HybridRiveView.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class HybridRiveView: HybridRiveViewSpec {
7575
}
7676

7777
func playIfNeeded() {
78-
onMainSync {
79-
try? self.getRiveView().playIfNeeded()
78+
try? onMainSync {
79+
try self.getRiveView().playIfNeeded()
8080
}
8181
}
8282

@@ -263,14 +263,19 @@ class HybridRiveView: HybridRiveViewSpec {
263263
}
264264

265265
extension HybridRiveView {
266-
/// Runs a closure on the main thread. If already on main, executes directly
267-
/// to avoid deadlocking with DispatchQueue.main.sync.
268-
func onMainSync<T>(_ work: () throws -> T) rethrows -> T {
266+
/// Runs a @MainActor-isolated closure on the main thread.
267+
/// If already on main, uses assumeIsolated directly.
268+
/// If on another thread, dispatches synchronously to main first.
269+
func onMainSync<T>(_ work: @MainActor () throws -> T) throws -> T {
269270
if Thread.isMainThread {
270-
return try work()
271+
return try MainActor.assumeIsolated {
272+
try work()
273+
}
271274
}
272-
return try onMainSync {
273-
try work()
275+
return try DispatchQueue.main.sync {
276+
MainActor.assumeIsolated {
277+
try work()
278+
}
274279
}
275280
}
276281

0 commit comments

Comments
 (0)