Trying to extend react-native View component. However I'm having trouble extending props of the View component.
Here is how I extend the Props
import { StyleSheet, View, ViewStyle, ViewProps } from "react-native";
interface Props extends ViewProps {
pb?: keyof Size | number;
pt?: keyof Size | number;
pv?: keyof Size | number;
ph?: keyof Size | number;
}
Here is my custom View component
class WrappedView extends Component<Props> {
render() {
const methods = {};
let { style: attrStyles, children, pb, pt, pv, ph, ...rest } = this.props;
let style = [attrStyles];
// Shorthand prop styles
let propStyles: ViewStyle = {};
propStyles.paddingBottom = pb;
propStyles.paddingTop = pt;
propStyles.paddingVertical = pv;
propStyles.paddingHorizontal = ph;
style.push(propStyles);
return (
<View style={style} {...rest} {...this.state} {...methods}>
{children}
</View>
);
}
}
When I try a test like so
const test = () => {
return <WrappedView pb={"large"} width={"100%"} />;
};
I get the following issue
Type '{ pb: "large"; width: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<WrappedView> & Readonly<Props> & Readonly<{ children?: ReactNode; }>'.
Property 'width' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<WrappedView> & Readonly<Props> & Readonly<{ children?: ReactNode; }>'.
widthis not a prop fromViewProps. Check it here