Skip to content

Commit a0cef2c

Browse files
committed
Define HostInstance type for React Native
1 parent 2d16326 commit a0cef2c

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

packages/react-native-renderer/src/ReactNativeTypes.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,32 @@ export interface INativeMethods {
112112
measure(callback: MeasureOnSuccessCallback): void;
113113
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
114114
measureLayout(
115-
relativeToNativeNode: number | ElementRef<HostComponent<mixed>>,
115+
relativeToNativeNode: number | HostInstance,
116116
onSuccess: MeasureLayoutOnSuccessCallback,
117117
onFail?: () => void,
118118
): void;
119119
setNativeProps(nativeProps: {...}): void;
120120
}
121121

122-
export type NativeMethods = $ReadOnly<{|
122+
export type NativeMethods = $ReadOnly<{
123123
blur(): void,
124124
focus(): void,
125125
measure(callback: MeasureOnSuccessCallback): void,
126126
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void,
127127
measureLayout(
128-
relativeToNativeNode: number | ElementRef<HostComponent<mixed>>,
128+
relativeToNativeNode: number | HostInstance,
129129
onSuccess: MeasureLayoutOnSuccessCallback,
130130
onFail?: () => void,
131131
): void,
132132
setNativeProps(nativeProps: {...}): void,
133-
|}>;
133+
}>;
134134

135135
// This validates that INativeMethods and NativeMethods stay in sync using Flow!
136136
declare const ensureNativeMethodsAreSynced: NativeMethods;
137137
(ensureNativeMethodsAreSynced: INativeMethods);
138138

139-
export type HostComponent<T> = AbstractComponent<T, $ReadOnly<NativeMethods>>;
139+
export type HostInstance = NativeMethods;
140+
export type HostComponent<Config> = AbstractComponent<Config, HostInstance>;
140141

141142
type SecretInternalsType = {
142143
computeComponentStackForErrorReporting(tag: number): string,
@@ -209,7 +210,7 @@ export type RenderRootOptions = {
209210
export type ReactNativeType = {
210211
findHostInstance_DEPRECATED<TElementType: ElementType>(
211212
componentOrHandle: ?(ElementRef<TElementType> | number),
212-
): ?ElementRef<HostComponent<mixed>>,
213+
): ?HostInstance,
213214
findNodeHandle<TElementType: ElementType>(
214215
componentOrHandle: ?(ElementRef<TElementType> | number),
215216
): ?number,
@@ -218,14 +219,11 @@ export type ReactNativeType = {
218219
child: PublicInstance | HostComponent<mixed>,
219220
): boolean,
220221
dispatchCommand(
221-
handle: ElementRef<HostComponent<mixed>>,
222+
handle: HostInstance,
222223
command: string,
223224
args: Array<mixed>,
224225
): void,
225-
sendAccessibilityEvent(
226-
handle: ElementRef<HostComponent<mixed>>,
227-
eventType: string,
228-
): void,
226+
sendAccessibilityEvent(handle: HostInstance, eventType: string): void,
229227
render(
230228
element: MixedElement,
231229
containerTag: number,
@@ -247,20 +245,17 @@ type PublicTextInstance = mixed;
247245
export type ReactFabricType = {
248246
findHostInstance_DEPRECATED<TElementType: ElementType>(
249247
componentOrHandle: ?(ElementRef<TElementType> | number),
250-
): ?ElementRef<HostComponent<mixed>>,
248+
): ?HostInstance,
251249
findNodeHandle<TElementType: ElementType>(
252250
componentOrHandle: ?(ElementRef<TElementType> | number),
253251
): ?number,
254252
dispatchCommand(
255-
handle: ElementRef<HostComponent<mixed>>,
253+
handle: HostInstance,
256254
command: string,
257255
args: Array<mixed>,
258256
): void,
259257
isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
260-
sendAccessibilityEvent(
261-
handle: ElementRef<HostComponent<mixed>>,
262-
eventType: string,
263-
): void,
258+
sendAccessibilityEvent(handle: HostInstance, eventType: string): void,
264259
render(
265260
element: MixedElement,
266261
containerTag: number,

0 commit comments

Comments
 (0)