File tree 7 files changed +31
-51
lines changed
react-native-renderer/src
7 files changed +31
-51
lines changed Original file line number Diff line number Diff line change @@ -90,15 +90,6 @@ function findHostInstance_DEPRECATED<TElementType: ElementType>(
90
90
hostInstance = findHostInstance ( componentOrHandle ) ;
91
91
}
92
92
93
- if (hostInstance == null) {
94
- return hostInstance ;
95
- }
96
- if ((hostInstance: any).canonical) {
97
- // Fabric
98
- return ( hostInstance : any ) . canonical ;
99
- }
100
- // $FlowFixMe[incompatible-return]
101
- // $FlowFixMe[incompatible-exact]
102
93
return hostInstance;
103
94
}
104
95
@@ -146,12 +137,7 @@ function findNodeHandle(componentOrHandle: any): ?number {
146
137
if (hostInstance == null) {
147
138
return hostInstance ;
148
139
}
149
- // TODO: the code is right but the types here are wrong.
150
- // https://github.com/facebook/react/pull/12863
151
- if ((hostInstance: any).canonical) {
152
- // Fabric
153
- return ( hostInstance : any ) . canonical . _nativeTag ;
154
- }
140
+
155
141
return hostInstance._nativeTag;
156
142
}
157
143
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ if (registerEventHandler) {
110
110
/**
111
111
* This is used for refs on host components.
112
112
*/
113
- class ReactFabricHostComponent {
113
+ class ReactFabricHostComponent implements NativeMethods {
114
114
_nativeTag : number ;
115
115
viewConfig : ViewConfig ;
116
116
currentProps : Props ;
@@ -215,10 +215,6 @@ class ReactFabricHostComponent {
215
215
}
216
216
}
217
217
218
- // $FlowFixMe[class-object-subtyping] found when upgrading Flow
219
- // $FlowFixMe[method-unbinding] found when upgrading Flow
220
- ( ReactFabricHostComponent . prototype : $ReadOnly < { ...NativeMethods , ...} > ) ;
221
-
222
218
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoMutation' ;
223
219
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoHydration' ;
224
220
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoScopes' ;
@@ -342,8 +338,17 @@ export function getChildHostContext(
342
338
}
343
339
}
344
340
345
- export function getPublicInstance ( instance : Instance ) : * {
346
- return instance . canonical ;
341
+ export function getPublicInstance ( instance : Instance ) : null | PublicInstance {
342
+ if ( instance . canonical ) {
343
+ return instance . canonical ;
344
+ }
345
+
346
+ // For compatibility with Paper
347
+ if ( instance . _nativeTag != null ) {
348
+ return instance ;
349
+ }
350
+
351
+ return null ;
347
352
}
348
353
349
354
export function prepareForCommit ( containerInfo : Container ) : null | Object {
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ import {
30
30
warnForStyleProps ,
31
31
} from './NativeMethodsMixinUtils' ;
32
32
33
- class ReactNativeFiberHostComponent {
33
+ class ReactNativeFiberHostComponent implements NativeMethods {
34
34
_children : Array < Instance | number > ;
35
35
_nativeTag : number ;
36
36
_internalFiberInstanceHandleDEV : Object ;
@@ -127,8 +127,4 @@ class ReactNativeFiberHostComponent {
127
127
}
128
128
}
129
129
130
- // $FlowFixMe[class-object-subtyping] found when upgrading Flow
131
- // $FlowFixMe[method-unbinding] found when upgrading Flow
132
- ( ReactNativeFiberHostComponent . prototype : $ReadOnly < { ...NativeMethods , ...} > ) ;
133
-
134
130
export default ReactNativeFiberHostComponent ;
Original file line number Diff line number Diff line change @@ -217,6 +217,11 @@ export function getChildHostContext(
217
217
}
218
218
219
219
export function getPublicInstance ( instance : Instance ) : * {
220
+ // $FlowExpectedError[prop-missing] For compatibility with Fabric
221
+ if ( instance . canonical ) {
222
+ return instance . canonical ;
223
+ }
224
+
220
225
return instance ;
221
226
}
222
227
Original file line number Diff line number Diff line change @@ -89,15 +89,6 @@ function findHostInstance_DEPRECATED(
89
89
hostInstance = findHostInstance ( componentOrHandle ) ;
90
90
}
91
91
92
- if ( hostInstance == null ) {
93
- return hostInstance ;
94
- }
95
- if ( ( hostInstance : any ) . canonical ) {
96
- // Fabric
97
- return ( hostInstance : any ) . canonical ;
98
- }
99
- // $FlowFixMe[incompatible-return]
100
- // $FlowFixMe[incompatible-exact]
101
92
return hostInstance ;
102
93
}
103
94
@@ -145,10 +136,7 @@ function findNodeHandle(componentOrHandle: any): ?number {
145
136
if ( hostInstance == null ) {
146
137
return hostInstance ;
147
138
}
148
- if ( ( hostInstance : any ) . canonical ) {
149
- // Fabric
150
- return ( hostInstance : any ) . canonical . _nativeTag ;
151
- }
139
+
152
140
return hostInstance . _nativeTag ;
153
141
}
154
142
Original file line number Diff line number Diff line change @@ -95,18 +95,18 @@ export type PartialViewConfig = $ReadOnly<{
95
95
validAttributes ?: PartialAttributeConfiguration ,
96
96
} > ;
97
97
98
- export type NativeMethods = $ReadOnly < {
99
- blur ( ) : void ,
100
- focus ( ) : void ,
101
- measure ( callback : MeasureOnSuccessCallback ) : void ,
102
- measureInWindow ( callback : MeasureInWindowOnSuccessCallback ) : void ,
98
+ export interface NativeMethods {
99
+ blur ( ) : void ;
100
+ focus ( ) : void ;
101
+ measure ( callback : MeasureOnSuccessCallback ) : void ;
102
+ measureInWindow ( callback : MeasureInWindowOnSuccessCallback ) : void ;
103
103
measureLayout (
104
104
relativeToNativeNode : number | ElementRef < HostComponent < mixed >> ,
105
105
onSuccess : MeasureLayoutOnSuccessCallback ,
106
106
onFail ?: ( ) => void ,
107
- ) : void ,
108
- setNativeProps ( nativeProps : { ...} ) : void ,
109
- } > ;
107
+ ) : void ;
108
+ setNativeProps ( nativeProps : { ...} ) : void ;
109
+ }
110
110
111
111
export type HostComponent < T > = AbstractComponent < T , $ReadOnly < NativeMethods >> ;
112
112
Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ function findHostInstance(component: Object): PublicInstance | null {
175
175
if ( hostFiber === null ) {
176
176
return null ;
177
177
}
178
- return hostFiber . stateNode ;
178
+ return getPublicInstance ( hostFiber . stateNode ) ;
179
179
}
180
180
181
181
function findHostInstanceWithWarning (
@@ -240,7 +240,7 @@ function findHostInstanceWithWarning(
240
240
}
241
241
}
242
242
}
243
- return hostFiber . stateNode ;
243
+ return getPublicInstance ( hostFiber . stateNode ) ;
244
244
}
245
245
return findHostInstance ( component ) ;
246
246
}
@@ -524,7 +524,7 @@ export function findHostInstanceWithNoPortals(
524
524
if ( hostFiber === null ) {
525
525
return null ;
526
526
}
527
- return hostFiber . stateNode ;
527
+ return getPublicInstance ( hostFiber . stateNode ) ;
528
528
}
529
529
530
530
let shouldErrorImpl : Fiber => ?boolean = fiber => null ;
You can’t perform that action at this time.
0 commit comments