Skip to content

Commit f550cfb

Browse files
SaadnajmiCopilot
andauthored
fix: support Swift builds that use an Objective-C bridging header (#4364)
* fix: support Swift builds that use an Objective-C bridging header Hosts can compile FURN's Swift sources against React Native through an Objective-C bridging header instead of a `React` clang module. - Import `React` in the Avatar and NativeDatePicker iOS Swift sources only when the module is available. - Implement the macOS Paper Callout `focusWindow` and `blurWindow` commands in Swift and declare them with `RCT_EXTERN_METHOD`, so FRNCalloutManager.m no longer imports the generated FRNNativeCore-Swift.h. With a bridging header, that generated header also declares the internal RCTCalloutManager class, which duplicates the `RCT_EXTERN_MODULE` interface. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ea215348-486c-45ef-8205-2a81a1dd75a7 * fix: import React Native headers with the <React/...> form in iOS sources FRNAppearanceAdditions.m and FRNDatePickerManager.m included RCTUIManager.h and RCTBridgeModule.h by bare name, which only resolves in hosts that also expose React Native headers without the React/ prefix. Use the canonical <React/...> form, which the rest of these files and CocoaPods already use. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ea215348-486c-45ef-8205-2a81a1dd75a7 * fix(native-core): import RCTI18nUtil.h with the <React/...> form in FocusZone The macOS FocusZone implementation included "RCTi18nUtil.h" by bare name and with different capitalization from React Native's React/Modules/RCTI18nUtil.h, so it only resolved through a case-insensitive bare-name header map. Use the canonical <React/RCTI18nUtil.h> form. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ea215348-486c-45ef-8205-2a81a1dd75a7 * fix(native-core): silence unused block parameter warnings in macOS FocusZone Mark the unused `index` and `stop` parameters of the indexOfObjectPassingTest: block in RCTFocusZone.m as `__unused` so the file compiles cleanly when -Wunused-parameter is treated as an error. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d7aea072-fc8e-4a8d-890a-81311025130d --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ea215348-486c-45ef-8205-2a81a1dd75a7 Copilot-Session: d7aea072-fc8e-4a8d-890a-81311025130d
1 parent 877c84f commit f550cfb

15 files changed

Lines changed: 71 additions & 31 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fluentui-react-native/native-core': patch
3+
---
4+
5+
Import `RCTI18nUtil.h` in the macOS FocusZone implementation with the canonical `<React/RCTI18nUtil.h>` form instead of by bare, differently cased header name.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fluentui-react-native/native-core': patch
3+
---
4+
5+
Mark the unused block parameters in the macOS FocusZone traversal as `__unused` so the file compiles cleanly with `-Wunused-parameter` treated as an error.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@fluentui-react-native/experimental-avatar': patch
3+
'@fluentui-react-native/experimental-native-date-picker': patch
4+
---
5+
6+
Import `React` in iOS Swift sources only when the module is available, so hosts can provide React Native headers through an Objective-C bridging header.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@fluentui-react-native/experimental-appearance-additions': patch
3+
'@fluentui-react-native/experimental-native-date-picker': patch
4+
---
5+
6+
Import React Native headers in iOS Objective-C sources with the canonical `<React/...>` form instead of by bare header name.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fluentui-react-native/native-core': patch
3+
---
4+
5+
Implement the macOS Paper Callout `focusWindow` and `blurWindow` commands in Swift so the Objective-C manager no longer imports the generated Swift header, which duplicates the manager's interface when hosts compile Swift with an Objective-C bridging header.

‎packages/agentic/native-core/README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ to use its host-provided `RCTCallout` and `RCTFocusZone`.
4040

4141
The macOS module-named header at `macos/shared/FRNNativeCore.h` is required by
4242
the generated `FRNNativeCore-Swift.h`; keep it aligned with the pod's
43-
`module_name` when changing native ownership.
43+
`module_name` when changing native ownership. Only Fabric adapters import the
44+
generated header. Hosts that compile the Swift sources with an Objective-C
45+
bridging header also get internal Swift classes declared there, duplicating
46+
Paper `RCT_EXTERN_MODULE` interfaces, so implement Paper manager methods in
47+
Swift and declare them with `RCT_EXTERN_METHOD`.
4448

4549
## Public entrypoints
4650

‎packages/agentic/native-core/macos/components/Callout/paper/CalloutManager.swift‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,19 @@ class CalloutManager: RCTViewManager {
1313
override class func requiresMainQueueSetup() -> Bool {
1414
return true
1515
}
16+
17+
// React Native calls these on the module's method queue; views can only be looked up on the main queue.
18+
@objc func focusWindow(_ viewTag: NSNumber) {
19+
nonisolated(unsafe) let manager = self
20+
DispatchQueue.main.async {
21+
(manager.bridge?.uiManager?.view(forReactTag: viewTag) as? CalloutView)?.focusWindow()
22+
}
23+
}
24+
25+
@objc func blurWindow(_ viewTag: NSNumber) {
26+
nonisolated(unsafe) let manager = self
27+
DispatchQueue.main.async {
28+
(manager.bridge?.uiManager?.view(forReactTag: viewTag) as? CalloutView)?.blurWindow()
29+
}
30+
}
1631
}

‎packages/agentic/native-core/macos/components/Callout/paper/FRNCalloutManager.m‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#import "FRNCalloutManager.h"
22

3-
#import "FRNNativeCore-Swift.h"
4-
53
@implementation RCTConvert (FRNCalloutAdditions)
64

75
// RCTConvert does not properly convert a JS screenRect into a native CGRect/NSRect,
@@ -39,27 +37,9 @@ + (NSRect)screenRect:(id)json
3937

4038
@interface RCT_EXTERN_MODULE(RCTCalloutManager, RCTViewManager)
4139

42-
RCT_EXPORT_METHOD(focusWindow : (nonnull NSNumber *)viewTag)
43-
{
44-
dispatch_async(dispatch_get_main_queue(), ^{
45-
NSView *view = [self.bridge.uiManager viewForReactTag:viewTag];
46-
47-
if ([view isKindOfClass:[FRNCalloutView class]]) {
48-
[(FRNCalloutView *)view focusWindow];
49-
}
50-
});
51-
}
40+
RCT_EXTERN_METHOD(focusWindow : (nonnull NSNumber *)viewTag)
5241

53-
RCT_EXPORT_METHOD(blurWindow : (nonnull NSNumber *)viewTag)
54-
{
55-
dispatch_async(dispatch_get_main_queue(), ^{
56-
NSView *view = [self.bridge.uiManager viewForReactTag:viewTag];
57-
58-
if ([view isKindOfClass:[FRNCalloutView class]]) {
59-
[(FRNCalloutView *)view blurWindow];
60-
}
61-
});
62-
}
42+
RCT_EXTERN_METHOD(blurWindow : (nonnull NSNumber *)viewTag)
6343

6444
RCT_EXPORT_VIEW_PROPERTY(target, NSNumber)
6545

‎packages/agentic/native-core/macos/components/FocusZone/shared/RCTFocusZone.m‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#import "KeyCodes.h"
22
#import <React/RCTBaseTextInputView.h>
33
#import "RCTFocusZone.h"
4-
#import "RCTi18nUtil.h"
4+
#import <React/RCTI18nUtil.h>
55

66
typedef enum {
77
FocusZoneActionNone,
@@ -560,7 +560,7 @@ - (NSView *)nextViewToFocusInHierarchyForAction:(FocusZoneAction)action
560560
AppendFocusableViewsWithin(self, focusableViews);
561561

562562
NSView *firstResponder = GetFirstResponder([self window]);
563-
NSUInteger currentIndex = [focusableViews indexOfObjectPassingTest:^BOOL(NSView *candidateView, NSUInteger index, BOOL *stop) {
563+
NSUInteger currentIndex = [focusableViews indexOfObjectPassingTest:^BOOL(NSView *candidateView, __unused NSUInteger index, __unused BOOL *stop) {
564564
return candidateView == firstResponder
565565
|| [candidateView isDescendantOf:firstResponder]
566566
|| [firstResponder isDescendantOf:candidateView];

‎packages/agentic/native-core/tests/native-ownership.test.mjs‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,18 @@ test('macOS Swift interoperability uses the consolidated pod module name', async
5353
assert.equal(moduleName, 'FRNNativeCore');
5454
await readFile(new URL(`macos/shared/${moduleName}.h`, packageRoot), 'utf8');
5555

56-
for (const adapter of ['fabric/RCTCalloutComponentView.mm', 'paper/FRNCalloutManager.m']) {
57-
const source = await readFile(new URL(`macos/components/Callout/${adapter}`, packageRoot), 'utf8');
58-
assert.ok(source.includes(`#import "${moduleName}-Swift.h"`));
59-
assert.doesNotMatch(source, /FRNCallout-Swift\.h/);
56+
const fabric = await readFile(new URL('macos/components/Callout/fabric/RCTCalloutComponentView.mm', packageRoot), 'utf8');
57+
assert.ok(fabric.includes(`#import "${moduleName}-Swift.h"`));
58+
assert.doesNotMatch(fabric, /FRNCallout-Swift\.h/);
59+
60+
// Bridging-header builds also declare internal Swift classes in the generated header, duplicating the Paper
61+
// manager's RCT_EXTERN_MODULE interface, so Paper commands are implemented in Swift instead.
62+
const paper = await readFile(new URL('macos/components/Callout/paper/FRNCalloutManager.m', packageRoot), 'utf8');
63+
const manager = await readFile(new URL('macos/components/Callout/paper/CalloutManager.swift', packageRoot), 'utf8');
64+
assert.doesNotMatch(paper, /-Swift\.h/);
65+
for (const command of ['focusWindow', 'blurWindow']) {
66+
assert.match(paper, new RegExp(`RCT_EXTERN_METHOD\\(${command} : \\(nonnull NSNumber \\*\\)viewTag\\)`));
67+
assert.match(manager, new RegExp(`@objc func ${command}\\(_ viewTag: NSNumber\\)`));
6068
}
6169
});
6270

0 commit comments

Comments
 (0)