mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-24 22:17:06 +08:00
[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`).
This commit is contained in:
8
types/react-native/index.d.ts
vendored
8
types/react-native/index.d.ts
vendored
@@ -8970,11 +8970,13 @@ export interface ComponentInterface<P> {
|
||||
* 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<P>(
|
||||
export function requireNativeComponent<P, NP = {}>(
|
||||
viewName: string,
|
||||
componentInterface?: ComponentInterface<P>,
|
||||
extraConfig?: { nativeOnly?: any }
|
||||
): React.ComponentClass<PropTypes.InferProps<PropTypes.ValidationMap<P>>>;
|
||||
extraConfig?: { nativeOnly?: NP }
|
||||
): React.ComponentClass<
|
||||
Partial<PropTypes.InferProps<PropTypes.ValidationMap<P>>> & { [K in keyof NP]?: any}
|
||||
>;
|
||||
|
||||
export function findNodeHandle(
|
||||
componentOrHandle: null | number | React.Component<any, any> | React.ComponentClass<any>
|
||||
|
||||
@@ -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 <NativeBridgedComponent {...this.props} nativeProp="test" />;
|
||||
}
|
||||
}
|
||||
|
||||
const NativeBridgedComponent = requireNativeComponent("NativeBridgedComponent", BridgedComponentTest, {
|
||||
nativeOnly: {
|
||||
nativeProp: true,
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user