Skip to content

Commit a446a38

Browse files
elicwhitefacebook-github-bot
authored andcommitted
Add HostComponent to the public API of React Native
Summary: In React Native there are three types of "Native" components. ``` createReactClass with NativeMethodsMixin ``` ``` class MyComponent extends ReactNative.NativeComponent ``` ``` requireNativeComponent('RCTView') ``` The implementation for how to handle all three of these exists in the React Native Renderer. Refs attached to components created via these methods provide a set of functions such as ``` .measure .measureInWindow .measureLayout .setNativeProps ``` These methods have been used for our core components in the repo to provide a consistent API. Many of the APIs in React Native require a `reactTag` to a host component. This is acquired by calling `findNodeHandle` with any component. `findNodeHandle` works with the first two approaches. For a lot of our new Fabric APIs, we will require passing a ref to a HostComponent directly instead of relying on `findNodeHandle` to tunnel through the component tree as that behavior isn't safe with React concurrent mode. The goal of this change is to enable us to differentiate between components created with `requireNativeComponent` and the other types. This will be needed to be able to safely type the new APIs. For existing components that should support being a host component but need to use some JS behavior in a wrapper, they should use `forwardRef`. The majority of React Native's core components were migrated to use `forwardRef` last year. Components that can't use forwardRef will need to have a method like `getNativeRef()` to get access to the underlying host component ref. Reviewed By: rickhanlonii Differential Revision: D17563615 fbshipit-source-id: b9e6042805517d502770fcba37301c2c5b6452b6
1 parent 0676ebf commit a446a38

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ import typeof DeprecatedEdgeInsetsPropType from './Libraries/DeprecatedPropTypes
9999
import typeof DeprecatedPointPropType from './Libraries/DeprecatedPropTypes/DeprecatedPointPropType';
100100
import typeof DeprecatedViewPropTypes from './Libraries/DeprecatedPropTypes/DeprecatedViewPropTypes';
101101

102-
import type {HostComponent} from './Libraries/Renderer/shims/ReactNativeTypes';
102+
import type {HostComponent as _HostComponentInternal} from './Libraries/Renderer/shims/ReactNativeTypes';
103+
104+
export type HostComponent<T> = _HostComponentInternal<T>;
103105

104106
const invariant = require('invariant');
105107
const warnOnce = require('./Libraries/Utilities/warnOnce');

0 commit comments

Comments
 (0)