NativeBase factory is a function that converts Non-NativeBase components to NativeBase enabled components so you can pass style props to them.
import { Factory } from "native-base";
const Example = () => {
const FactoryView = Factory(View);
return <FactoryView bg="emerald.400" borderRadius={4} size={16} />;
};
const Example = () => {
const FactoryView = Factory(View, {
baseStyle: {
bg: "cyan.300",
borderRadius: "md"
}
});
return <FactoryView height={50} width={50} />;
};
Using mode in component theme
const Example = () => {
const FactoryView = Factory(View, {
baseStyle: props => {
return {
bg: themeTools.mode("rose.500", "cyan.300")(props),
borderRadius: "md"
};
}
});
return <FactoryView height={50} width={50} />;
};
const Example = () => {
const NBInput = Factory(TextInput);
const inputRef = React.useRef(null);
return <Stack space={4}>
<NBInput placeholder="Click on the button" ref={inputRef} p="2" borderWidth="1" borderColor="cyan.400" borderRadius="md" _dark={{
color: "trueGray.200"
}} />
<Button colorScheme="emerald" onPress={() => {
inputRef.current.focus();
}}>
Set Focus
</Button>
</Stack>;
};
Original component to be passed on which NativeBase props have to be applied.
This object can include baseStyle, sizes, variants, defaultProps