From 003e4ffb4a2a1a80b4ad2e51e696b33c8318472f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=BCcahit?= <76880536+mucahitdev@users.noreply.github.com> Date: Sun, 15 Oct 2023 01:54:12 +0300 Subject: [PATCH] chore(component): image switch textinput --- src/customizers/image.tsx | 17 +++++++++++++++++ src/customizers/switch.tsx | 17 +++++++++++++++++ src/customizers/textInput.tsx | 17 +++++++++++++++++ src/index.tsx | 14 +++++++++++++- 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/customizers/image.tsx create mode 100644 src/customizers/switch.tsx create mode 100644 src/customizers/textInput.tsx diff --git a/src/customizers/image.tsx b/src/customizers/image.tsx new file mode 100644 index 0000000..aaba1c8 --- /dev/null +++ b/src/customizers/image.tsx @@ -0,0 +1,17 @@ +import { Image, type ImageProps } from 'react-native'; + +export const customizeImage = (customProps: ImageProps) => { + const TextRender = (Image as any).render; + if (!TextRender) { + (Image as any).defaultProps = customProps; + return; + } + (Image as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + style: [customProps.style, props.style], + }; + return TextRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/switch.tsx b/src/customizers/switch.tsx new file mode 100644 index 0000000..7576f4e --- /dev/null +++ b/src/customizers/switch.tsx @@ -0,0 +1,17 @@ +import { Switch, type SwitchProps } from 'react-native'; + +export const customizeTextSwitch = (customProps: SwitchProps) => { + const TextRender = (Switch as any).render; + if (!TextRender) { + (Switch as any).defaultProps = customProps; + return; + } + (Switch as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + style: [customProps.style, props.style], + }; + return TextRender.call(this, props, ref); + }; +}; diff --git a/src/customizers/textInput.tsx b/src/customizers/textInput.tsx new file mode 100644 index 0000000..82df1e0 --- /dev/null +++ b/src/customizers/textInput.tsx @@ -0,0 +1,17 @@ +import { TextInput, type TextInputProps } from 'react-native'; + +export const customizeTextInput = (customProps: TextInputProps) => { + const TextRender = (TextInput as any).render; + if (!TextRender) { + (TextInput as any).defaultProps = customProps; + return; + } + (TextInput as any).render = (props: any, ref: any) => { + props = { + ...customProps, + ...props, + style: [customProps.style, props.style], + }; + return TextRender.call(this, props, ref); + }; +}; diff --git a/src/index.tsx b/src/index.tsx index 6e0aa41..33d9ba6 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,11 +1,23 @@ import { customizeView } from './customizers/view'; import { customizeText } from './customizers/text'; +import { customizeImage } from './customizers/image'; +import { customizeTextInput } from './customizers/textInput'; +import { customizeTextSwitch } from './customizers/switch'; const Customizer = { Text: customizeText, View: customizeView, + Image: customizeImage, + TextInput: customizeTextInput, + Switch: customizeTextSwitch, }; -export { customizeText, customizeView }; +export { + customizeText, + customizeView, + customizeImage, + customizeTextInput, + customizeTextSwitch, +}; export default Customizer;