diff --git a/Sources/ReactBridge/ReactBridge.swift b/Sources/ReactBridge/ReactBridge.swift index b0a0e79..55c83dc 100644 --- a/Sources/ReactBridge/ReactBridge.swift +++ b/Sources/ReactBridge/ReactBridge.swift @@ -79,7 +79,7 @@ public macro ReactMethod(jsName: String? = nil, isSync: Bool = false) = #externa /// - Parameters: /// - jsName: JavaScript UI component name. If omitted, the JavaScript UI component name will match the class name. /// -@attached(member, names: named(_registerModule), named(moduleName), named(requiresMainQueueSetup)) +@attached(member, names: named(_registerModule), named(moduleName), named(requiresMainQueueSetup), named(methodQueue)) public macro ReactView(jsName: String? = nil) = #externalMacro(module: "ReactBridgeMacros", type: "ReactView") /// The macro exports a property of a native view to JavaScript. diff --git a/Sources/ReactBridgeMacros/ReactModule.swift b/Sources/ReactBridgeMacros/ReactModule.swift index f1ba87d..eacbf2d 100644 --- a/Sources/ReactBridgeMacros/ReactModule.swift +++ b/Sources/ReactBridgeMacros/ReactModule.swift @@ -56,9 +56,9 @@ extension ReactModule: MemberMacro { """ } - private static func methodQueue(queue: String) -> DeclSyntax { + static func methodQueue(queue: String, override: Bool = false) -> DeclSyntax { """ - @objc var methodQueue: DispatchQueue { + @objc \(raw: override ? "override " : "")var methodQueue: DispatchQueue { \(raw: queue) } """ diff --git a/Sources/ReactBridgeMacros/ReactView.swift b/Sources/ReactBridgeMacros/ReactView.swift index adbe99f..8f8eb00 100644 --- a/Sources/ReactBridgeMacros/ReactView.swift +++ b/Sources/ReactBridgeMacros/ReactView.swift @@ -58,6 +58,7 @@ extension ReactView: MemberMacro { ReactModule.registerModule, ReactModule.moduleName(name: jsName, override: true), ReactModule.requiresMainQueueSetup(value: true, override: true), + ReactModule.methodQueue(queue: ".main", override: true) ] } catch let diagnostic as Diagnostic { diff --git a/Tests/ReactBridgeTests/ReactBridgeTests.swift b/Tests/ReactBridgeTests/ReactBridgeTests.swift index 075d11b..d2a8fcf 100644 --- a/Tests/ReactBridgeTests/ReactBridgeTests.swift +++ b/Tests/ReactBridgeTests/ReactBridgeTests.swift @@ -643,6 +643,10 @@ final class ReactViewTests: XCTestCase { @objc override class func requiresMainQueueSetup() -> Bool { true } + + @objc override var methodQueue: DispatchQueue { + .main + } } """, macros: macros @@ -671,6 +675,10 @@ final class ReactViewTests: XCTestCase { @objc override class func requiresMainQueueSetup() -> Bool { true } + + @objc override var methodQueue: DispatchQueue { + .main + } } """, macros: macros diff --git a/Tests/ReactBridgeTests/ReactMockTests.swift b/Tests/ReactBridgeTests/ReactMockTests.swift index 83ad9b7..555eaa8 100644 --- a/Tests/ReactBridgeTests/ReactMockTests.swift +++ b/Tests/ReactBridgeTests/ReactMockTests.swift @@ -14,6 +14,7 @@ protocol RCTBridgeModule { class RCTViewManager: NSObject { class func moduleName() -> String! { "" } class func requiresMainQueueSetup() -> Bool { false } + var methodQueue: DispatchQueue { .main } } class RCTMethodInfo: NSObject {