Skip to content

Commit

Permalink
Update React Native types (#20883)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubennorte committed Feb 25, 2021
1 parent 9209c30 commit 8336f19
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 85 deletions.
19 changes: 12 additions & 7 deletions packages/react-native-renderer/src/ReactFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import type {HostComponent} from './ReactNativeTypes';
import type {ReactNodeList} from 'shared/ReactTypes';
import type {ElementRef} from 'react';
import type {ElementRef, Element, ElementType} from 'react';

import './ReactFabricInjection';

Expand Down Expand Up @@ -47,8 +47,8 @@ import getComponentName from 'shared/getComponentName';

const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;

function findHostInstance_DEPRECATED(
componentOrHandle: any,
function findHostInstance_DEPRECATED<TElementType: ElementType>(
componentOrHandle: ?(ElementRef<TElementType> | number),
): ?ElementRef<HostComponent<mixed>> {
if (__DEV__) {
const owner = ReactCurrentOwner.current;
Expand All @@ -70,10 +70,14 @@ function findHostInstance_DEPRECATED(
if (componentOrHandle == null) {
return null;
}
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
if (componentOrHandle._nativeTag) {
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
return componentOrHandle;
}
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) {
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
return componentOrHandle.canonical;
}
let hostInstance;
Expand Down Expand Up @@ -194,10 +198,10 @@ function sendAccessibilityEvent(handle: any, eventType: string) {
}

function render(
element: React$Element<any>,
containerTag: any,
callback: ?Function,
) {
element: Element<ElementType>,
containerTag: number,
callback: ?() => void,
): ?ElementRef<ElementType> {
let root = roots.get(containerTag);

if (!root) {
Expand All @@ -208,6 +212,7 @@ function render(
}
updateContainer(element, root, null, callback);

// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
return getPublicRootInstance(root);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
NativeMethods,
ReactNativeBaseComponentViewConfig,
ViewConfig,
TouchedViewDataAtPoint,
} from './ReactNativeTypes';

Expand Down Expand Up @@ -111,13 +111,13 @@ if (registerEventHandler) {
*/
class ReactFabricHostComponent {
_nativeTag: number;
viewConfig: ReactNativeBaseComponentViewConfig<>;
viewConfig: ViewConfig;
currentProps: Props;
_internalInstanceHandle: Object;

constructor(
tag: number,
viewConfig: ReactNativeBaseComponentViewConfig<>,
viewConfig: ViewConfig,
props: Props,
internalInstanceHandle: Object,
) {
Expand Down
26 changes: 13 additions & 13 deletions packages/react-native-renderer/src/ReactNativeAttributePayload.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function defaultDiffer(prevProp: mixed, nextProp: mixed): boolean {
function restoreDeletedValuesInNestedArray(
updatePayload: Object,
node: NestedNode,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
) {
if (Array.isArray(node)) {
let i = node.length;
Expand Down Expand Up @@ -107,7 +107,7 @@ function diffNestedArrayProperty(
updatePayload: null | Object,
prevArray: Array<NestedNode>,
nextArray: Array<NestedNode>,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
const minLength =
prevArray.length < nextArray.length ? prevArray.length : nextArray.length;
Expand Down Expand Up @@ -145,7 +145,7 @@ function diffNestedProperty(
updatePayload: null | Object,
prevProp: NestedNode,
nextProp: NestedNode,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
if (!updatePayload && prevProp === nextProp) {
// If no properties have been added, then we can bail out quickly on object
Expand Down Expand Up @@ -206,7 +206,7 @@ function diffNestedProperty(
function addNestedProperty(
updatePayload: null | Object,
nextProp: NestedNode,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
) {
if (!nextProp) {
return updatePayload;
Expand Down Expand Up @@ -236,7 +236,7 @@ function addNestedProperty(
function clearNestedProperty(
updatePayload: null | Object,
prevProp: NestedNode,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
if (!prevProp) {
return updatePayload;
Expand Down Expand Up @@ -268,7 +268,7 @@ function diffProperties(
updatePayload: null | Object,
prevProps: Object,
nextProps: Object,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
let attributeConfig;
let nextProp;
Expand Down Expand Up @@ -369,13 +369,13 @@ function diffProperties(
updatePayload,
prevProp,
nextProp,
((attributeConfig: any): AttributeConfiguration<>),
((attributeConfig: any): AttributeConfiguration),
);
if (removedKeyCount > 0 && updatePayload) {
restoreDeletedValuesInNestedArray(
updatePayload,
nextProp,
((attributeConfig: any): AttributeConfiguration<>),
((attributeConfig: any): AttributeConfiguration),
);
removedKeys = null;
}
Expand Down Expand Up @@ -426,7 +426,7 @@ function diffProperties(
updatePayload = clearNestedProperty(
updatePayload,
prevProp,
((attributeConfig: any): AttributeConfiguration<>),
((attributeConfig: any): AttributeConfiguration),
);
}
}
Expand All @@ -439,7 +439,7 @@ function diffProperties(
function addProperties(
updatePayload: null | Object,
props: Object,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
// TODO: Fast path
return diffProperties(updatePayload, emptyObject, props, validAttributes);
Expand All @@ -452,15 +452,15 @@ function addProperties(
function clearProperties(
updatePayload: null | Object,
prevProps: Object,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
// TODO: Fast path
return diffProperties(updatePayload, prevProps, emptyObject, validAttributes);
}

export function create(
props: Object,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
return addProperties(
null, // updatePayload
Expand All @@ -472,7 +472,7 @@ export function create(
export function diff(
prevProps: Object,
nextProps: Object,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
return diffProperties(
null, // updatePayload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
NativeMethods,
ReactNativeBaseComponentViewConfig,
ViewConfig,
} from './ReactNativeTypes';
import type {Instance} from './ReactNativeHostConfig';

Expand All @@ -34,11 +34,11 @@ class ReactNativeFiberHostComponent {
_children: Array<Instance | number>;
_nativeTag: number;
_internalFiberInstanceHandleDEV: Object;
viewConfig: ReactNativeBaseComponentViewConfig<>;
viewConfig: ViewConfig;

constructor(
tag: number,
viewConfig: ReactNativeBaseComponentViewConfig<>,
viewConfig: ViewConfig,
internalInstanceHandleDEV: Object,
) {
this._nativeTag = tag;
Expand Down
10 changes: 6 additions & 4 deletions packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import type {HostComponent} from './ReactNativeTypes';
import type {ReactNodeList} from 'shared/ReactTypes';
import type {ElementRef, Element, ElementType} from 'react';

import './ReactNativeInjection';

Expand Down Expand Up @@ -193,10 +194,10 @@ function sendAccessibilityEvent(handle: any, eventType: string) {
}

function render(
element: React$Element<any>,
containerTag: any,
callback: ?Function,
) {
element: Element<ElementType>,
containerTag: number,
callback: ?() => void,
): ?ElementRef<ElementType> {
let root = roots.get(containerTag);

if (!root) {
Expand All @@ -207,6 +208,7 @@ function render(
}
updateContainer(element, root, null, callback);

// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
return getPublicRootInstance(root);
}

Expand Down
Loading

0 comments on commit 8336f19

Please sign in to comment.