From 954567e501374572d2bc830ee884ba23474e503f Mon Sep 17 00:00:00 2001 From: James Ide Date: Mon, 17 Sep 2018 17:38:49 -0700 Subject: [PATCH] [react-native] Account for `nativeOnly` props in `requireNativeComponent` Adjusted the prop types of the returned native component class so that (a) the `nativeOnly` set of props adds to the prop types and (b) not all the props from the JS component are required (using `Partial`). --- types/react-native/index.d.ts | 8 +++++--- types/react-native/test/index.tsx | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 048e34b872..ce80ac64bd 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -8970,11 +8970,13 @@ export interface ComponentInterface

{ * Common types are lined up with the appropriate prop differs with * `TypeToDifferMap`. Non-scalar types not in the map default to `deepDiffer`. */ -export function requireNativeComponent

( +export function requireNativeComponent( viewName: string, componentInterface?: ComponentInterface

, - extraConfig?: { nativeOnly?: any } -): React.ComponentClass>>; + extraConfig?: { nativeOnly?: NP } +): React.ComponentClass< + Partial>> & { [K in keyof NP]?: any} +>; export function findNodeHandle( componentOrHandle: null | number | React.Component | React.ComponentClass diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index a16d6f3e4d..c9696e53d0 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -11,6 +11,7 @@ The content of index.io.js could be something like For a list of complete Typescript examples: check https://github.com/bgrieder/RNTSExplorer */ +import * as PropTypes from "prop-types"; import * as React from "react"; import { Alert, @@ -75,6 +76,7 @@ import { Modal, TimePickerAndroid, ViewPropTypes, + requireNativeComponent, } from "react-native"; declare module "react-native" { @@ -762,3 +764,20 @@ const TimePickerAndroidTest = () => ( mode: 'spinner' }) ) + +class BridgedComponentTest extends React.Component { + static propTypes = { + jsProp: PropTypes.string.isRequired, + ...ViewPropTypes, + } + + render() { + return ; + } +} + +const NativeBridgedComponent = requireNativeComponent("NativeBridgedComponent", BridgedComponentTest, { + nativeOnly: { + nativeProp: true, + } +});