Skip to content

Commit ebae210

Browse files
committed
Make FocusZone a TurboModule
1 parent 3fc95f6 commit ebae210

File tree

10 files changed

+69
-1503
lines changed

10 files changed

+69
-1503
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import AppKit
5+
import Foundation
6+
#if USE_REACT_AS_MODULE
7+
import React
8+
#endif // USE_REACT_AS_MODULE
9+
10+
@objc(FocusZoneViewManager)
11+
class FocusZoneViewManager: RCTViewManager {
12+
13+
override func view() -> NSView! {
14+
return RCTFocusZone()
15+
}
16+
17+
override class func requiresMainQueueSetup() -> Bool {
18+
return true
19+
}
20+
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
#pragma once
2-
3-
#import <React/RCTViewManager.h>
4-
5-
@interface RCTFocusZoneManager : RCTViewManager
6-
@end
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.

packages/components/FocusZone/macos/RCTFocusZoneManager.m

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
14
#import "RCTFocusZone.h"
2-
#import "RCTFocusZoneManager.h"
35
#import <React/RCTConvert.h>
46
#import <React/RCTUIManager.h>
7+
#import <React/RCTViewManager.h>
58

6-
@implementation RCTFocusZoneManager
7-
8-
RCT_EXPORT_MODULE()
9+
@interface RCT_EXTERN_MODULE(FocusZoneViewManager, RCTViewManager)
910

1011
RCT_EXPORT_VIEW_PROPERTY(disabled, BOOL)
1112

@@ -50,9 +51,4 @@ @implementation RCTFocusZoneManager
5051
[view setDefaultResponder:defaultResponder];
5152
}
5253

53-
- (RCTView *)view
54-
{
55-
return [RCTFocusZone new];
56-
}
57-
5854
@end

packages/components/FocusZone/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
},
3535
"dependencies": {
3636
"@fluentui-react-native/adapters": "workspace:*",
37-
"@fluentui-react-native/interactive-hooks": "workspace:*",
38-
"@uifabricshared/foundation-composable": "workspace:*",
39-
"@uifabricshared/foundation-settings": "workspace:*"
37+
"@fluentui-react-native/framework": "workspace:*",
38+
"@fluentui-react-native/interactive-hooks": "workspace:*"
4039
},
4140
"devDependencies": {
4241
"@babel/core": "catalog:",

packages/components/FocusZone/src/FocusZone.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@
77
import * as React from 'react';
88
import { findNodeHandle } from 'react-native';
99

10+
import type { UseSlots } from '@fluentui-react-native/framework';
11+
import { compose, mergeProps } from '@fluentui-react-native/framework';
1012
import { useViewCommandFocus } from '@fluentui-react-native/interactive-hooks';
11-
import type { IUseStyling } from '@uifabricshared/foundation-composable';
12-
import { composable } from '@uifabricshared/foundation-composable';
13-
import { mergeSettings } from '@uifabricshared/foundation-settings';
1413

15-
import type { FocusZoneProps, FocusZoneSlotProps, FocusZoneType } from './FocusZone.types';
14+
import type { FocusZoneProps, FocusZoneState, FocusZoneTokens } from './FocusZone.types';
15+
import { focusZoneName } from './FocusZone.types';
1616
import RCTFocusZone from './FocusZoneNativeComponent';
17-
18-
const filterOutComponentRef = (propName) => propName !== 'componentRef';
19-
20-
export const FocusZone = composable<FocusZoneType>({
21-
usePrepareProps: (userProps: FocusZoneProps, useStyling: IUseStyling<FocusZoneType>) => {
17+
import type { NativeProps } from './FocusZoneNativeComponent';
18+
19+
interface FocusZoneTypeInternal {
20+
props: FocusZoneProps;
21+
tokens: FocusZoneTokens;
22+
slotProps: { root: React.PropsWithRef<NativeProps> };
23+
state: FocusZoneState;
24+
}
25+
26+
export const FocusZone = compose<FocusZoneTypeInternal>({
27+
displayName: focusZoneName,
28+
slots: { root: RCTFocusZone },
29+
useRender: (userProps: FocusZoneProps, useSlots: UseSlots<FocusZoneTypeInternal>) => {
2230
const { componentRef, defaultTabbableElement, isCircularNavigation, ...rest } = userProps;
2331

2432
const ftzRef = useViewCommandFocus(componentRef);
@@ -34,18 +42,18 @@ export const FocusZone = composable<FocusZoneType>({
3442
}
3543
}, [defaultTabbableElement]);
3644

37-
return {
38-
slotProps: mergeSettings<FocusZoneSlotProps>(useStyling(userProps), {
39-
root: {
40-
navigateAtEnd: isCircularNavigation ? 'NavigateWrap' : 'NavigateStopAtEnds', // let rest override
41-
...rest,
42-
defaultTabbableElement: targetFirstFocus,
43-
ref: ftzRef,
44-
},
45-
}),
45+
const rootProps = {
46+
navigateAtEnd: isCircularNavigation ? 'NavigateWrap' : 'NavigateStopAtEnds',
47+
...rest,
48+
} as NativeProps;
49+
50+
const Root = useSlots(userProps).root;
51+
return (restProps: FocusZoneProps) => {
52+
return React.createElement(Root, {
53+
...mergeProps(rootProps, restProps as NativeProps),
54+
defaultTabbableElement: targetFirstFocus,
55+
ref: ftzRef,
56+
});
4657
};
4758
},
48-
slots: {
49-
root: { slotType: RCTFocusZone, filter: filterOutComponentRef },
50-
},
5159
});

packages/components/FocusZone/src/FocusZone.types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type * as React from 'react';
22

33
import type { IViewProps } from '@fluentui-react-native/adapters';
44
import type { IFocusable } from '@fluentui-react-native/interactive-hooks';
5-
import type { IRenderData } from '@uifabricshared/foundation-composable';
65

76
export const focusZoneName = 'FocusZone';
87

@@ -113,8 +112,6 @@ export interface FocusZoneSlotProps {
113112
root: NativeProps;
114113
}
115114

116-
export type FocusZoneRenderData = IRenderData<FocusZoneSlotProps, FocusZoneState>;
117-
118115
export interface FocusZoneType {
119116
props: FocusZoneProps;
120117
tokens: FocusZoneTokens;

packages/components/FocusZone/src/FocusZoneNativeComponent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface NativeProps extends ViewProps {
1919
tabKeyNavigation?: WithDefault<'None' | 'NavigateWrap' | 'NavigateStopAtEnds' | 'Normal', 'None'>;
2020
disabled?: boolean;
2121
isTabNavigation?: boolean;
22+
navigationOrderInRenderOrder?: boolean;
2223
}
2324

2425
export default codegenNativeComponent<NativeProps>('RCTFocusZone');

0 commit comments

Comments
 (0)