Skip to content

Commit

Permalink
@reactView: methodQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhvorost committed Oct 10, 2023
1 parent 61b39c9 commit b64d9e5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/ReactBridge/ReactBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions Sources/ReactBridgeMacros/ReactModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
"""
Expand Down
1 change: 1 addition & 0 deletions Sources/ReactBridgeMacros/ReactView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions Tests/ReactBridgeTests/ReactBridgeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,10 @@ final class ReactViewTests: XCTestCase {
@objc override class func requiresMainQueueSetup() -> Bool {
true
}
@objc override var methodQueue: DispatchQueue {
.main
}
}
""",
macros: macros
Expand Down Expand Up @@ -671,6 +675,10 @@ final class ReactViewTests: XCTestCase {
@objc override class func requiresMainQueueSetup() -> Bool {
true
}
@objc override var methodQueue: DispatchQueue {
.main
}
}
""",
macros: macros
Expand Down
1 change: 1 addition & 0 deletions Tests/ReactBridgeTests/ReactMockTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b64d9e5

Please sign in to comment.