-
Notifications
You must be signed in to change notification settings - Fork 24.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: `HostComponent` is built specifically to differentiate from `ReactNative.NativeComponent`. These tests should ensure that is the case, and help it stay that way. I also expect these tests to be duplicated to DefinitelyTyped to help the team working on the TypeScript types ensure they have things modeled correctly. Reviewed By: cpojer Differential Revision: D17580120 fbshipit-source-id: c14eb18507cbee1b308beeff0092607e18706171
- Loading branch information
1 parent
bcc58bc
commit 79e08f3
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
Libraries/Renderer/__flowtests__/ReactNativeTypes-flowtest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import * as React from 'react'; | ||
import type { | ||
HostComponent, | ||
ReactNativeComponentClass_ForTestsOnly, | ||
} from '../shims/ReactNativeTypes'; | ||
|
||
function takesHostComponentInstance( | ||
instance: React$ElementRef<HostComponent<mixed>> | null, | ||
): void {} | ||
|
||
const MyHostComponent = (('Host': any): HostComponent<mixed>); | ||
|
||
<MyHostComponent | ||
ref={hostComponentRef => { | ||
takesHostComponentInstance(hostComponentRef); | ||
|
||
if (hostComponentRef == null) { | ||
return; | ||
} | ||
|
||
hostComponentRef.measureLayout(hostComponentRef, () => {}); | ||
}} | ||
/>; | ||
|
||
declare var NativeComponent: ReactNativeComponentClass_ForTestsOnly<{}>; | ||
class MyNativeComponent extends NativeComponent {} | ||
|
||
<MyNativeComponent | ||
ref={nativeComponentRef => { | ||
// $FlowExpectedError - NativeComponent cannot be passed as HostComponent. | ||
takesHostComponentInstance(nativeComponentRef); | ||
|
||
if (nativeComponentRef == null) { | ||
return; | ||
} | ||
|
||
// $FlowExpectedError - NativeComponent cannot be passed as HostComponent. | ||
nativeComponentRef.measureLayout(nativeComponentRef, () => {}); | ||
}} | ||
/>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters