Skip to content

Commit

Permalink
fix flow types
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaGross committed Jan 27, 2021
1 parent f35baaf commit bb89265
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/react-native-renderer/src/ReactFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function sendAccessibilityEvent(handle: any, eventType: string) {
if (handle._internalInstanceHandle) {
nativeFabricUIManager.sendAccessibilityEvent(
handle._internalInstanceHandle.stateNode.node,
eventType
eventType,
);
} else {
legacySendAccessibilityEvent(handle._nativeTag, eventType);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function sendAccessibilityEvent(handle: any, eventType: string) {
if (handle._internalInstanceHandle) {
nativeFabricUIManager.sendAccessibilityEvent(
handle._internalInstanceHandle.stateNode.node,
eventType
eventType,
);
} else {
legacySendAccessibilityEvent(handle._nativeTag, eventType);
Expand Down
22 changes: 18 additions & 4 deletions packages/react-native-renderer/src/ReactNativeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,15 @@ export type ReactNativeType = {
componentOrHandle: any,
): ?ElementRef<HostComponent<mixed>>,
findNodeHandle(componentOrHandle: any): ?number,
dispatchCommand(handle: ElementRef<HostComponent<mixed>>, command: string, args: Array<any>): void,
sendAccessibilityEvent(handle: ElementRef<HostComponent<mixed>>, eventType: string): void,
dispatchCommand(
handle: ElementRef<HostComponent<mixed>>,
command: string,
args: Array<any>,
): void,
sendAccessibilityEvent(
handle: ElementRef<HostComponent<mixed>>,
eventType: string,
): void,
render(
element: React$Element<any>,
containerTag: any,
Expand All @@ -169,8 +176,15 @@ export type ReactFabricType = {
componentOrHandle: any,
): ?ElementRef<HostComponent<mixed>>,
findNodeHandle(componentOrHandle: any): ?number,
dispatchCommand(handle: ElementRef<HostComponent<mixed>>, command: string, args: Array<any>): void,
sendAccessibilityEvent(handle: ElementRef<HostComponent<mixed>>, eventType: string): void,
dispatchCommand(
handle: ElementRef<HostComponent<mixed>>,
command: string,
args: Array<any>,
): void,
sendAccessibilityEvent(
handle: ElementRef<HostComponent<mixed>>,
eventType: string,
): void,
render(
element: React$Element<any>,
containerTag: any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ module.exports = {
},
get legacySendAccessibilityEvent() {
return require('./legacySendAccessibilityEvent');
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,13 @@ describe('ReactFabric', () => {

expect(nativeFabricUIManager.sendAccessibilityEvent).not.toBeCalled();
ReactFabric.sendAccessibilityEvent(viewRef, 'focus');
expect(nativeFabricUIManager.sendAccessibilityEvent).toHaveBeenCalledTimes(1);
expect(
nativeFabricUIManager.sendAccessibilityEvent,
).toHaveBeenCalledWith(expect.any(Object), 'focus');
expect(nativeFabricUIManager.sendAccessibilityEvent).toHaveBeenCalledTimes(
1,
);
expect(nativeFabricUIManager.sendAccessibilityEvent).toHaveBeenCalledWith(
expect.any(Object),
'focus',
);
});

it('should warn and no-op if calling sendAccessibilityEvent on non native refs', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ describe('created with ReactFabric called with ReactNative', () => {
ReactNative = require('react-native-renderer');
jest.resetModules();
ReactNativePrivateInterface = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface');
UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface').UIManager;
UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
.UIManager;
jest.mock('shared/ReactFeatureFlags', () =>
require('shared/forks/ReactFeatureFlags.native-oss'),
);

React = require('react');
ReactFabric = require('react-native-renderer/fabric');
createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface').ReactNativeViewConfigRegistry.register;
createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
.ReactNativeViewConfigRegistry.register;
});

it('find Fabric instances with the RN renderer', () => {
Expand Down Expand Up @@ -105,15 +107,17 @@ describe('created with ReactFabric called with ReactNative', () => {
ReactFabric.render(<View title="bar" ref={ref} />, 11);
expect(nativeFabricUIManager.sendAccessibilityEvent).not.toBeCalled();
ReactNative.sendAccessibilityEvent(ref.current, 'focus');
expect(nativeFabricUIManager.sendAccessibilityEvent).toHaveBeenCalledTimes(1);
expect(
nativeFabricUIManager.sendAccessibilityEvent,
).toHaveBeenCalledWith(expect.any(Object), 'focus');
expect(nativeFabricUIManager.sendAccessibilityEvent).toHaveBeenCalledTimes(
1,
);
expect(nativeFabricUIManager.sendAccessibilityEvent).toHaveBeenCalledWith(
expect.any(Object),
'focus',
);
expect(UIManager.sendAccessibilityEvent).not.toBeCalled();
});
});


describe('created with ReactNative called with ReactFabric', () => {
beforeEach(() => {
jest.resetModules();
Expand Down Expand Up @@ -202,14 +206,17 @@ describe('created with ReactNative called with ReactFabric', () => {
const ref = React.createRef();

ReactNative.render(<View title="bar" ref={ref} />, 11);
expect(ReactNativePrivateInterface.legacySendAccessibilityEvent).not.toBeCalled();
expect(
ReactNativePrivateInterface.legacySendAccessibilityEvent,
).not.toBeCalled();
ReactFabric.sendAccessibilityEvent(ref.current, 'focus');
expect(ReactNativePrivateInterface.legacySendAccessibilityEvent).toHaveBeenCalledTimes(1);
expect(
ReactNativePrivateInterface.legacySendAccessibilityEvent,
).toHaveBeenCalledTimes(1);
expect(
ReactNativePrivateInterface.legacySendAccessibilityEvent,
).toHaveBeenCalledWith(expect.any(Number), 'focus');

expect(nativeFabricUIManager.sendAccessibilityEvent).not.toBeCalled();
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ describe('ReactNative', () => {
StrictMode = React.StrictMode;
ReactNative = require('react-native-renderer');
ReactNativePrivateInterface = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface');
UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface').UIManager;
UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
.UIManager;
createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
.ReactNativeViewConfigRegistry.register;
TextInputState = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
Expand Down Expand Up @@ -174,9 +175,13 @@ describe('ReactNative', () => {
11,
);

expect(ReactNativePrivateInterface.legacySendAccessibilityEvent).not.toBeCalled();
expect(
ReactNativePrivateInterface.legacySendAccessibilityEvent,
).not.toBeCalled();
ReactNative.sendAccessibilityEvent(viewRef, 'focus');
expect(ReactNativePrivateInterface.legacySendAccessibilityEvent).toHaveBeenCalledTimes(1);
expect(
ReactNativePrivateInterface.legacySendAccessibilityEvent,
).toHaveBeenCalledTimes(1);
expect(
ReactNativePrivateInterface.legacySendAccessibilityEvent,
).toHaveBeenCalledWith(expect.any(Number), 'focus');
Expand Down
2 changes: 2 additions & 0 deletions scripts/flow/react-native-host-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
) => void,
...
};
declare export var legacySendAccessibilityEvent: (reactTag: number, eventTypeName: string) => void;
declare export var BatchedBridge: {
registerCallableModule: (name: string, module: Object) => void,
...
Expand Down Expand Up @@ -156,6 +157,7 @@ declare var nativeFabricUIManager: {
) => void,

dispatchCommand: (node: Object, command: string, args: Array<any>) => void,
sendAccessibilityEvent: (node: Object, eventTypeName: string) => void,

measure: (node: Node, callback: MeasureOnSuccessCallback) => void,
measureInWindow: (
Expand Down

0 comments on commit bb89265

Please sign in to comment.