Skip to content

Commit

Permalink
feat(component): view and text
Browse files Browse the repository at this point in the history
  • Loading branch information
mucahitdev committed Oct 14, 2023
1 parent 65715fe commit 8f31a95
Show file tree
Hide file tree
Showing 6 changed files with 18,282 additions and 12 deletions.
6 changes: 3 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"expo": "~49.0.13",
"expo-status-bar": "~1.6.0",
"react": "18.2.0",
"react-native": "0.72.5",
"react-dom": "18.2.0",
"react-native": "0.72.5",
"react-native-web": "~0.19.6"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"babel-plugin-module-resolver": "^5.0.0",
"@expo/webpack-config": "^18.0.1",
"babel-loader": "^8.1.0"
"babel-loader": "^8.1.0",
"babel-plugin-module-resolver": "^5.0.0"
},
"private": true
}
19 changes: 13 additions & 6 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import * as React from 'react';

import { StyleSheet, View, Text } from 'react-native';
import { multiply } from 'react-native-reset-css';
import Customizer, { customizeView } from 'react-native-reset-css';

export default function App() {
const [result, setResult] = React.useState<number | undefined>();
Customizer.Text({
style: {
backgroundColor: 'yellow',
},
});

React.useEffect(() => {
multiply(3, 7).then(setResult);
}, []);
customizeView({
style: {
backgroundColor: 'blue',
},
});

return (
<View style={styles.container}>
<Text>Result: {result}</Text>
<Text style={{ backgroundColor: 'green' }}>Result:</Text>

Check warning on line 21 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Inline style: { backgroundColor: 'green' }
<Text style={{ color: 'pink' }}>Result:</Text>

Check warning on line 22 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Inline style: { color: 'pink' }
</View>
);
}
Expand Down
17 changes: 17 additions & 0 deletions src/customizers/text.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Text, type TextProps } from 'react-native';

export const customizeText = (customProps: TextProps) => {
const TextRender = (Text as any).render;
if (!TextRender) {
(Text as any).defaultProps = customProps;
return;
}
(Text 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/view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { View, type ViewProps } from 'react-native';

export const customizeView = (customProps: ViewProps) => {
const TextRender = (View as any).render;
if (!TextRender) {
(View as any).defaultProps = customProps;
return;
}
(View as any).render = (props: any, ref: any) => {
props = {
...customProps,
...props,
style: [customProps.style, props.style],
};
return TextRender.call(this, props, ref);
};
};
14 changes: 11 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export function multiply(a: number, b: number): Promise<number> {
return Promise.resolve(a * b);
}
import { customizeView } from './customizers/view';
import { customizeText } from './customizers/text';

const Customizer = {
Text: customizeText,
View: customizeView,
};

export { customizeText, customizeView };

export default Customizer;
Loading

0 comments on commit 8f31a95

Please sign in to comment.