-
Notifications
You must be signed in to change notification settings - Fork 47.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add HostComponent type to ReactNative #16898
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import type { | |
MeasureInWindowOnSuccessCallback, | ||
MeasureLayoutOnSuccessCallback, | ||
MeasureOnSuccessCallback, | ||
NativeMethodsMixinType, | ||
NativeMethods, | ||
ReactNativeBaseComponentViewConfig, | ||
ReactNativeResponderEvent, | ||
ReactNativeResponderContext, | ||
|
@@ -151,9 +151,9 @@ class ReactFabricHostComponent { | |
} | ||
|
||
measureLayout( | ||
relativeToNativeNode: number | Object, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yay! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize it's not part of this change, but should the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warningWithoutStack internally has a dev check and is a no-op in dev. |
||
relativeToNativeNode: number | ReactFabricHostComponent, | ||
onSuccess: MeasureLayoutOnSuccessCallback, | ||
onFail: () => void /* currently unused */, | ||
onFail?: () => void /* currently unused */, | ||
) { | ||
if ( | ||
typeof relativeToNativeNode === 'number' || | ||
|
@@ -186,7 +186,7 @@ class ReactFabricHostComponent { | |
} | ||
|
||
// eslint-disable-next-line no-unused-expressions | ||
(ReactFabricHostComponent.prototype: NativeMethodsMixinType); | ||
(ReactFabricHostComponent.prototype: NativeMethods); | ||
|
||
export * from 'shared/HostConfigWithNoMutation'; | ||
export * from 'shared/HostConfigWithNoHydration'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import type { | |
MeasureInWindowOnSuccessCallback, | ||
MeasureLayoutOnSuccessCallback, | ||
MeasureOnSuccessCallback, | ||
NativeMethodsMixinType, | ||
NativeMethods, | ||
ReactNativeBaseComponentViewConfig, | ||
} from './ReactNativeTypes'; | ||
import type {Instance} from './ReactNativeHostConfig'; | ||
|
@@ -72,21 +72,25 @@ class ReactNativeFiberHostComponent { | |
} | ||
|
||
measureLayout( | ||
relativeToNativeNode: number | Object, | ||
relativeToNativeNode: number | ReactNativeFiberHostComponent, | ||
onSuccess: MeasureLayoutOnSuccessCallback, | ||
onFail: () => void /* currently unused */, | ||
onFail?: () => void /* currently unused */, | ||
) { | ||
let relativeNode; | ||
let relativeNode: ?number; | ||
|
||
if (typeof relativeToNativeNode === 'number') { | ||
// Already a node handle | ||
relativeNode = relativeToNativeNode; | ||
} else if (relativeToNativeNode._nativeTag) { | ||
relativeNode = relativeToNativeNode._nativeTag; | ||
} else if ( | ||
/* $FlowFixMe canonical doesn't exist on the node. | ||
I think this branch is dead and will remove it in a followup */ | ||
relativeToNativeNode.canonical && | ||
relativeToNativeNode.canonical._nativeTag | ||
) { | ||
/* $FlowFixMe canonical doesn't exist on the node. | ||
I think this branch is dead and will remove it in a followup */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering if the change from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. When I added this option I wrote tests that called this with createClass, ReactNativeNativeComponent and a host component. Nothing triggers this branch. That's why I think this is dead. Worst case, nothing except some of our Fabric screens are using this API yet and we'll get quick signal if I'm wrong once we delete it. But it's unrelated to this type change. |
||
relativeNode = relativeToNativeNode.canonical._nativeTag; | ||
} | ||
|
||
|
@@ -137,6 +141,6 @@ class ReactNativeFiberHostComponent { | |
} | ||
|
||
// eslint-disable-next-line no-unused-expressions | ||
(ReactNativeFiberHostComponent.prototype: NativeMethodsMixinType); | ||
(ReactNativeFiberHostComponent.prototype: NativeMethods); | ||
|
||
export default ReactNativeFiberHostComponent; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
* @flow | ||
*/ | ||
|
||
import React from 'react'; | ||
import * as React from 'react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed because we are now importing types from React. |
||
|
||
export type MeasureOnSuccessCallback = ( | ||
x: number, | ||
|
@@ -96,23 +96,34 @@ class ReactNativeComponent<Props> extends React.Component<Props> { | |
setNativeProps(nativeProps: Object): void {} | ||
} | ||
|
||
// This type is only used for FlowTests. It shouldn't be imported directly | ||
export type _InternalReactNativeComponentClass<Props> = Class< | ||
ReactNativeComponent<Props>, | ||
>; | ||
|
||
/** | ||
* This type keeps ReactNativeFiberHostComponent and NativeMethodsMixin in sync. | ||
* It can also provide types for ReactNative applications that use NMM or refs. | ||
*/ | ||
export type NativeMethodsMixinType = { | ||
export type NativeMethods = { | ||
blur(): void, | ||
focus(): void, | ||
measure(callback: MeasureOnSuccessCallback): void, | ||
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void, | ||
measureLayout( | ||
relativeToNativeNode: number | Object, | ||
relativeToNativeNode: number | React.ElementRef<HostComponent<mixed>>, | ||
onSuccess: MeasureLayoutOnSuccessCallback, | ||
onFail: () => void, | ||
onFail?: () => void, | ||
): void, | ||
setNativeProps(nativeProps: Object): void, | ||
}; | ||
|
||
export type NativeMethodsMixinType = NativeMethods; | ||
export type HostComponent<T> = React.AbstractComponent< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So simple. So clean. |
||
T, | ||
$ReadOnly<$Exact<NativeMethods>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think I understand the purpose of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From @jbrown215:
|
||
>; | ||
|
||
type SecretInternalsType = { | ||
NativeMethodsMixin: NativeMethodsMixinType, | ||
computeComponentStackForErrorReporting(tag: number): string, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was always optional in the types used in React Native, but because the two types are duplicated in
ReactNativeTypes
, they must have fallen out of sync.