GeezerVison is showing github.com — Add HostComponent type to ReactNative (#16898) · react/react@db8afe4
File treeExpand file treeCollapse file tree Open diff view settings packages/react-native-renderer/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/NativeMethodsMixin.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -161,7 +161,7 @@ export default function( | 161 | 161 | measureLayout: function( | 162 | 162 | relativeToNativeNode: number | Object, | 163 | 163 | onSuccess: MeasureLayoutOnSuccessCallback, | 164 | | - onFail: () => void /* currently unused */, | | 164 | + onFail?: () => void /* currently unused */, | 165 | 165 | ) { | 166 | 166 | let maybeInstance; | 167 | 167 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFabricHostConfig.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,7 @@ import type { | 11 | 11 | MeasureInWindowOnSuccessCallback, | 12 | 12 | MeasureLayoutOnSuccessCallback, | 13 | 13 | MeasureOnSuccessCallback, | 14 | | - NativeMethodsMixinType, | | 14 | + NativeMethods, | 15 | 15 | ReactNativeBaseComponentViewConfig, | 16 | 16 | ReactNativeResponderEvent, | 17 | 17 | ReactNativeResponderContext, | @@ -151,9 +151,9 @@ class ReactFabricHostComponent { | 151 | 151 | } | 152 | 152 |
| 153 | 153 | measureLayout( | 154 | | - relativeToNativeNode: number | Object, | | 154 | + relativeToNativeNode: number | ReactFabricHostComponent, | 155 | 155 | onSuccess: MeasureLayoutOnSuccessCallback, | 156 | | - onFail: () => void /* currently unused */, | | 156 | + onFail?: () => void /* currently unused */, | 157 | 157 | ) { | 158 | 158 | if ( | 159 | 159 | typeof relativeToNativeNode === 'number' || | @@ -186,7 +186,7 @@ class ReactFabricHostComponent { | 186 | 186 | } | 187 | 187 |
| 188 | 188 | // eslint-disable-next-line no-unused-expressions | 189 | | -(ReactFabricHostComponent.prototype: NativeMethodsMixinType); | | 189 | +(ReactFabricHostComponent.prototype: NativeMethods); | 190 | 190 |
| 191 | 191 | export * from 'shared/HostConfigWithNoMutation'; | 192 | 192 | export * from 'shared/HostConfigWithNoHydration'; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeComponent.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,7 +12,7 @@ import type { | 12 | 12 | MeasureInWindowOnSuccessCallback, | 13 | 13 | MeasureLayoutOnSuccessCallback, | 14 | 14 | MeasureOnSuccessCallback, | 15 | | - NativeMethodsMixinType, | | 15 | + NativeMethods, | 16 | 16 | ReactNativeBaseComponentViewConfig, | 17 | 17 | } from './ReactNativeTypes'; | 18 | 18 |
| @@ -172,7 +172,7 @@ export default function( | 172 | 172 | measureLayout( | 173 | 173 | relativeToNativeNode: number | Object, | 174 | 174 | onSuccess: MeasureLayoutOnSuccessCallback, | 175 | | - onFail: () => void /* currently unused */, | | 175 | + onFail?: () => void /* currently unused */, | 176 | 176 | ): void { | 177 | 177 | let maybeInstance; | 178 | 178 |
| @@ -295,7 +295,7 @@ export default function( | 295 | 295 | } | 296 | 296 |
| 297 | 297 | // eslint-disable-next-line no-unused-expressions | 298 | | - (ReactNativeComponent.prototype: NativeMethodsMixinType); | | 298 | + (ReactNativeComponent.prototype: NativeMethods); | 299 | 299 |
| 300 | 300 | return ReactNativeComponent; | 301 | 301 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeFiberHostComponent.js +9-5Lines changed: 9 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,7 @@ import type { | 11 | 11 | MeasureInWindowOnSuccessCallback, | 12 | 12 | MeasureLayoutOnSuccessCallback, | 13 | 13 | MeasureOnSuccessCallback, | 14 | | - NativeMethodsMixinType, | | 14 | + NativeMethods, | 15 | 15 | ReactNativeBaseComponentViewConfig, | 16 | 16 | } from './ReactNativeTypes'; | 17 | 17 | import type {Instance} from './ReactNativeHostConfig'; | @@ -72,21 +72,25 @@ class ReactNativeFiberHostComponent { | 72 | 72 | } | 73 | 73 |
| 74 | 74 | measureLayout( | 75 | | - relativeToNativeNode: number | Object, | | 75 | + relativeToNativeNode: number | ReactNativeFiberHostComponent, | 76 | 76 | onSuccess: MeasureLayoutOnSuccessCallback, | 77 | | - onFail: () => void /* currently unused */, | | 77 | + onFail?: () => void /* currently unused */, | 78 | 78 | ) { | 79 | | - let relativeNode; | | 79 | + let relativeNode: ?number; | 80 | 80 |
| 81 | 81 | if (typeof relativeToNativeNode === 'number') { | 82 | 82 | // Already a node handle | 83 | 83 | relativeNode = relativeToNativeNode; | 84 | 84 | } else if (relativeToNativeNode._nativeTag) { | 85 | 85 | relativeNode = relativeToNativeNode._nativeTag; | 86 | 86 | } else if ( | | 87 | + /* $FlowFixMe canonical doesn't exist on the node. | | 88 | + I think this branch is dead and will remove it in a followup */ | 87 | 89 | relativeToNativeNode.canonical && | 88 | 90 | relativeToNativeNode.canonical._nativeTag | 89 | 91 | ) { | | 92 | + /* $FlowFixMe canonical doesn't exist on the node. | | 93 | + I think this branch is dead and will remove it in a followup */ | 90 | 94 | relativeNode = relativeToNativeNode.canonical._nativeTag; | 91 | 95 | } | 92 | 96 |
| @@ -137,6 +141,6 @@ class ReactNativeFiberHostComponent { | 137 | 141 | } | 138 | 142 |
| 139 | 143 | // eslint-disable-next-line no-unused-expressions | 140 | | -(ReactNativeFiberHostComponent.prototype: NativeMethodsMixinType); | | 144 | +(ReactNativeFiberHostComponent.prototype: NativeMethods); | 141 | 145 |
| 142 | 146 | export default ReactNativeFiberHostComponent; |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeTypes.js +16-5Lines changed: 16 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | * @flow | 9 | 9 | */ | 10 | 10 |
| 11 | | -import React from 'react'; | | 11 | +import React, {type ElementRef, type AbstractComponent} from 'react'; | 12 | 12 |
| 13 | 13 | export type MeasureOnSuccessCallback = ( | 14 | 14 | x: number, | @@ -89,30 +89,41 @@ class ReactNativeComponent<Props> extends React.Component<Props> { | 89 | 89 | measure(callback: MeasureOnSuccessCallback): void {} | 90 | 90 | measureInWindow(callback: MeasureInWindowOnSuccessCallback): void {} | 91 | 91 | measureLayout( | 92 | | - relativeToNativeNode: number | Object, | | 92 | + relativeToNativeNode: number | ElementRef<HostComponent<mixed>>, | 93 | 93 | onSuccess: MeasureLayoutOnSuccessCallback, | 94 | 94 | onFail?: () => void, | 95 | 95 | ): void {} | 96 | 96 | setNativeProps(nativeProps: Object): void {} | 97 | 97 | } | 98 | 98 |
| | 99 | +// This type is only used for FlowTests. It shouldn't be imported directly | | 100 | +export type _InternalReactNativeComponentClass<Props> = Class< | | 101 | + ReactNativeComponent<Props>, | | 102 | +>; | | 103 | + | 99 | 104 | /** | 100 | 105 | * This type keeps ReactNativeFiberHostComponent and NativeMethodsMixin in sync. | 101 | 106 | * It can also provide types for ReactNative applications that use NMM or refs. | 102 | 107 | */ | 103 | | -export type NativeMethodsMixinType = { | | 108 | +export type NativeMethods = { | 104 | 109 | blur(): void, | 105 | 110 | focus(): void, | 106 | 111 | measure(callback: MeasureOnSuccessCallback): void, | 107 | 112 | measureInWindow(callback: MeasureInWindowOnSuccessCallback): void, | 108 | 113 | measureLayout( | 109 | | - relativeToNativeNode: number | Object, | | 114 | + relativeToNativeNode: number | ElementRef<HostComponent<mixed>>, | 110 | 115 | onSuccess: MeasureLayoutOnSuccessCallback, | 111 | | - onFail: () => void, | | 116 | + onFail?: () => void, | 112 | 117 | ): void, | 113 | 118 | setNativeProps(nativeProps: Object): void, | 114 | 119 | }; | 115 | 120 |
| | 121 | +export type NativeMethodsMixinType = NativeMethods; | | 122 | +export type HostComponent<T> = AbstractComponent< | | 123 | + T, | | 124 | + $ReadOnly<$Exact<NativeMethods>>, | | 125 | +>; | | 126 | + | 116 | 127 | type SecretInternalsType = { | 117 | 128 | NativeMethodsMixin: NativeMethodsMixinType, | 118 | 129 | computeComponentStackForErrorReporting(tag: number): string, | |
|