diff --git a/src/customizers/button.tsx b/src/customizers/button.tsx new file mode 100644 index 0000000..bd6621b --- /dev/null +++ b/src/customizers/button.tsx @@ -0,0 +1,16 @@ +import { Button, type ButtonProps } from 'react-native'; + +export const customizeButton = (customProps: ButtonProps) => { + const ButtonRender = (Button as any).render; + if (!ButtonRender) { + (Button as any).defaultProps = customProps; + return; + } + (Button as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + }; + return ButtonRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/flatList.tsx b/src/customizers/flatList.tsx new file mode 100644 index 0000000..11380fb --- /dev/null +++ b/src/customizers/flatList.tsx @@ -0,0 +1,16 @@ +import { FlatList, type FlatListProps } from 'react-native'; + +export const customizeFlatList = (customProps: FlatListProps) => { + const FlatListRender = (FlatList as any).render; + if (!FlatListRender) { + (FlatList as any).defaultProps = customProps; + return; + } + (FlatList as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + }; + return FlatListRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/image.tsx b/src/customizers/image.tsx index aaba1c8..a17413d 100644 --- a/src/customizers/image.tsx +++ b/src/customizers/image.tsx @@ -1,8 +1,8 @@ import { Image, type ImageProps } from 'react-native'; export const customizeImage = (customProps: ImageProps) => { - const TextRender = (Image as any).render; - if (!TextRender) { + const ImageRender = (Image as any).render; + if (!ImageRender) { (Image as any).defaultProps = customProps; return; } @@ -12,6 +12,6 @@ export const customizeImage = (customProps: ImageProps) => { ...props, style: [customProps.style, props.style], }; - return TextRender.call(this, props, ref); + return ImageRender.call(this, props, ref); }; }; diff --git a/src/customizers/imageBackground.tsx b/src/customizers/imageBackground.tsx new file mode 100644 index 0000000..42bc48a --- /dev/null +++ b/src/customizers/imageBackground.tsx @@ -0,0 +1,17 @@ +import { ImageBackground, type ImageBackgroundProps } from 'react-native'; + +export const customizeImageBackground = (customProps: ImageBackgroundProps) => { + const ImageBackgroundRender = (ImageBackground as any).render; + if (!ImageBackgroundRender) { + (ImageBackground as any).defaultProps = customProps; + return; + } + (ImageBackground as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + style: [customProps.style, props.style], + }; + return ImageBackgroundRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/keyboardAvoidingView.tsx b/src/customizers/keyboardAvoidingView.tsx new file mode 100644 index 0000000..a087da2 --- /dev/null +++ b/src/customizers/keyboardAvoidingView.tsx @@ -0,0 +1,21 @@ +import { + KeyboardAvoidingView, + type KeyboardAvoidingViewProps, +} from 'react-native'; + +export const customizeKeyboardAvoidingView = ( + customProps: KeyboardAvoidingViewProps +) => { + const KeyboardAvoidingViewRender = (KeyboardAvoidingView as any).render; + if (!KeyboardAvoidingViewRender) { + (KeyboardAvoidingView as any).defaultProps = customProps; + return; + } + (KeyboardAvoidingView as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + }; + return KeyboardAvoidingViewRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/modal.tsx b/src/customizers/modal.tsx new file mode 100644 index 0000000..653166a --- /dev/null +++ b/src/customizers/modal.tsx @@ -0,0 +1,17 @@ +import { Modal, type ModalProps } from 'react-native'; + +export const customizeModal = (customProps: ModalProps) => { + const ModalRender = (Modal as any).render; + if (!ModalRender) { + (Modal as any).defaultProps = customProps; + return; + } + (Modal as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + style: [customProps.style, props.style], + }; + return ModalRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/pressable.tsx b/src/customizers/pressable.tsx new file mode 100644 index 0000000..1c864ba --- /dev/null +++ b/src/customizers/pressable.tsx @@ -0,0 +1,17 @@ +import { Pressable, type PressableProps } from 'react-native'; + +export const customizePressable = (customProps: PressableProps) => { + const PressableRender = (Pressable as any).render; + if (!PressableRender) { + (Pressable as any).defaultProps = customProps; + return; + } + (Pressable as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + style: [customProps.style, props.style], + }; + return PressableRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/refreshControl.tsx b/src/customizers/refreshControl.tsx new file mode 100644 index 0000000..5b1ace0 --- /dev/null +++ b/src/customizers/refreshControl.tsx @@ -0,0 +1,16 @@ +import { RefreshControl, type RefreshControlProps } from 'react-native'; + +export const customizeRefreshControl = (customProps: RefreshControlProps) => { + const RefreshControlRender = (RefreshControl as any).render; + if (!RefreshControlRender) { + (RefreshControl as any).defaultProps = customProps; + return; + } + (RefreshControl as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + }; + return RefreshControlRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/scrollView.tsx b/src/customizers/scrollView.tsx new file mode 100644 index 0000000..834470a --- /dev/null +++ b/src/customizers/scrollView.tsx @@ -0,0 +1,16 @@ +import { ScrollView, type ScrollViewProps } from 'react-native'; + +export const customizeScrollView = (customProps: ScrollViewProps) => { + const ScrollViewRender = (ScrollView as any).render; + if (!ScrollViewRender) { + (ScrollView as any).defaultProps = customProps; + return; + } + (ScrollView as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + }; + return ScrollViewRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/sectionList.tsx b/src/customizers/sectionList.tsx new file mode 100644 index 0000000..8500b2e --- /dev/null +++ b/src/customizers/sectionList.tsx @@ -0,0 +1,16 @@ +import { SectionList, type SectionListProps } from 'react-native'; + +export const customizeSectionList = (customProps: SectionListProps) => { + const SectionListRender = (SectionList as any).render; + if (!SectionListRender) { + (SectionList as any).defaultProps = customProps; + return; + } + (SectionList as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + }; + return SectionListRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/statusBar.tsx b/src/customizers/statusBar.tsx new file mode 100644 index 0000000..c2100a3 --- /dev/null +++ b/src/customizers/statusBar.tsx @@ -0,0 +1,16 @@ +import { StatusBar, type StatusBarProps } from 'react-native'; + +export const customizeStatusBar = (customProps: StatusBarProps) => { + const StatusBarRender = (StatusBar as any).render; + if (!StatusBarRender) { + (StatusBar as any).defaultProps = customProps; + return; + } + (StatusBar as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + }; + return StatusBarRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/switch.tsx b/src/customizers/switch.tsx index 7576f4e..daa54f3 100644 --- a/src/customizers/switch.tsx +++ b/src/customizers/switch.tsx @@ -1,8 +1,8 @@ import { Switch, type SwitchProps } from 'react-native'; export const customizeTextSwitch = (customProps: SwitchProps) => { - const TextRender = (Switch as any).render; - if (!TextRender) { + const SwitchRender = (Switch as any).render; + if (!SwitchRender) { (Switch as any).defaultProps = customProps; return; } @@ -12,6 +12,6 @@ export const customizeTextSwitch = (customProps: SwitchProps) => { ...props, style: [customProps.style, props.style], }; - return TextRender.call(this, props, ref); + return SwitchRender.call(this, props, ref); }; }; diff --git a/src/customizers/textInput.tsx b/src/customizers/textInput.tsx index 82df1e0..49900e7 100644 --- a/src/customizers/textInput.tsx +++ b/src/customizers/textInput.tsx @@ -1,8 +1,8 @@ import { TextInput, type TextInputProps } from 'react-native'; export const customizeTextInput = (customProps: TextInputProps) => { - const TextRender = (TextInput as any).render; - if (!TextRender) { + const TextInputRender = (TextInput as any).render; + if (!TextInputRender) { (TextInput as any).defaultProps = customProps; return; } @@ -12,6 +12,6 @@ export const customizeTextInput = (customProps: TextInputProps) => { ...props, style: [customProps.style, props.style], }; - return TextRender.call(this, props, ref); + return TextInputRender.call(this, props, ref); }; }; diff --git a/src/customizers/touchable.tsx b/src/customizers/touchable.tsx new file mode 100644 index 0000000..4188991 --- /dev/null +++ b/src/customizers/touchable.tsx @@ -0,0 +1,83 @@ +import { + TouchableHighlight, + TouchableNativeFeedback, + TouchableWithoutFeedback, + TouchableOpacity, + type TouchableHighlightProps, + type TouchableNativeFeedbackProps, + type TouchableWithoutFeedbackProps, + type TouchableOpacityProps, +} from 'react-native'; + +export const customizeTouchableHighlight = ( + customProps: TouchableHighlightProps +) => { + const TouchableHighlightRender = (TouchableHighlight as any).render; + if (!TouchableHighlightRender) { + (TouchableHighlight as any).defaultProps = customProps; + return; + } + (TouchableHighlight as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + style: [customProps.style, props.style], + }; + return TouchableHighlightRender.call(this, props, ref); + }; +}; + +export const customizeTouchableNativeFeedback = ( + customProps: TouchableNativeFeedbackProps +) => { + const TouchableNativeFeedbackRender = (TouchableNativeFeedback as any).render; + if (!TouchableNativeFeedbackRender) { + (TouchableNativeFeedback as any).defaultProps = customProps; + return; + } + (TouchableNativeFeedback as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + style: [customProps.style, props.style], + }; + return TouchableNativeFeedbackRender.call(this, props, ref); + }; +}; + +export const customizeTouchableWithoutFeedback = ( + customProps: TouchableWithoutFeedbackProps +) => { + const TouchableWithoutFeedbackRender = (TouchableWithoutFeedback as any) + .render; + if (!TouchableWithoutFeedbackRender) { + (TouchableWithoutFeedback as any).defaultProps = customProps; + return; + } + (TouchableWithoutFeedback as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + style: [customProps.style, props.style], + }; + return TouchableWithoutFeedbackRender.call(this, props, ref); + }; +}; + +export const customizeTouchableOpacity = ( + customProps: TouchableOpacityProps +) => { + const TouchableOpacityRender = (TouchableOpacity as any).render; + if (!TouchableOpacityRender) { + (TouchableOpacity as any).defaultProps = customProps; + return; + } + (TouchableOpacity as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + style: [customProps.style, props.style], + }; + return TouchableOpacityRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/view.tsx b/src/customizers/view.tsx index 4666b1d..47a2b15 100644 --- a/src/customizers/view.tsx +++ b/src/customizers/view.tsx @@ -1,8 +1,8 @@ import { View, type ViewProps } from 'react-native'; export const customizeView = (customProps: ViewProps) => { - const TextRender = (View as any).render; - if (!TextRender) { + const ViewRender = (View as any).render; + if (!ViewRender) { (View as any).defaultProps = customProps; return; } @@ -12,6 +12,6 @@ export const customizeView = (customProps: ViewProps) => { ...props, style: [customProps.style, props.style], }; - return TextRender.call(this, props, ref); + return ViewRender.call(this, props, ref); }; }; diff --git a/src/index.tsx b/src/index.tsx index 33d9ba6..d911089 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -3,6 +3,22 @@ import { customizeText } from './customizers/text'; import { customizeImage } from './customizers/image'; import { customizeTextInput } from './customizers/textInput'; import { customizeTextSwitch } from './customizers/switch'; +import { customizeModal } from './customizers/modal'; +import { customizePressable } from './customizers/pressable'; +import { customizeStatusBar } from './customizers/statusBar'; +import { customizeButton } from './customizers/button'; +import { customizeImageBackground } from './customizers/imageBackground'; +import { customizeKeyboardAvoidingView } from './customizers/keyboardAvoidingView'; +import { customizeRefreshControl } from './customizers/refreshControl'; +import { customizeScrollView } from './customizers/scrollView'; +import { customizeFlatList } from './customizers/flatList'; +import { customizeSectionList } from './customizers/sectionList'; +import { + customizeTouchableHighlight, + customizeTouchableNativeFeedback, + customizeTouchableWithoutFeedback, + customizeTouchableOpacity, +} from './customizers/touchable'; const Customizer = { Text: customizeText, @@ -10,6 +26,20 @@ const Customizer = { Image: customizeImage, TextInput: customizeTextInput, Switch: customizeTextSwitch, + Modal: customizeModal, + Pressable: customizePressable, + StatusBar: customizeStatusBar, + Button: customizeButton, + ImageBackground: customizeImageBackground, + KeyboardAvoidingView: customizeKeyboardAvoidingView, + RefreshControl: customizeRefreshControl, + ScrollView: customizeScrollView, + FlatList: customizeFlatList, + SectionList: customizeSectionList, + TouchableHighlight: customizeTouchableHighlight, + TouchableNativeFeedback: customizeTouchableNativeFeedback, + TouchableWithoutFeedback: customizeTouchableWithoutFeedback, + TouchableOpacity: customizeTouchableOpacity, }; export { @@ -18,6 +48,20 @@ export { customizeImage, customizeTextInput, customizeTextSwitch, + customizeModal, + customizePressable, + customizeStatusBar, + customizeButton, + customizeImageBackground, + customizeKeyboardAvoidingView, + customizeRefreshControl, + customizeScrollView, + customizeFlatList, + customizeSectionList, + customizeTouchableHighlight, + customizeTouchableNativeFeedback, + customizeTouchableWithoutFeedback, + customizeTouchableOpacity, }; export default Customizer;