Skip to content

Commit

Permalink
chore(component): image switch textinput
Browse files Browse the repository at this point in the history
  • Loading branch information
mucahitdev committed Oct 14, 2023
1 parent dfeabd5 commit 003e4ff
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/customizers/image.tsx
Original file line number Diff line number Diff line change
@@ -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);
};
};
17 changes: 17 additions & 0 deletions src/customizers/switch.tsx
Original file line number Diff line number Diff line change
@@ -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);
};
};
17 changes: 17 additions & 0 deletions src/customizers/textInput.tsx
Original file line number Diff line number Diff line change
@@ -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);
};
};
14 changes: 13 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 003e4ff

Please sign in to comment.