Skip to content

Commit b01b9b9

Browse files
committed
feat: add several more NativeWind features to tester app
1 parent c0319d0 commit b01b9b9

File tree

8 files changed

+97
-18
lines changed

8 files changed

+97
-18
lines changed

apps/tester-app/global.css

+19
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,22 @@
55
.custom-style-test {
66
color: mediumpurple;
77
}
8+
9+
.calc-element {
10+
width: calc(var(--my-variable) - (20px + 2rem));
11+
}
12+
13+
:root {
14+
--H: 200;
15+
--S: 50%;
16+
--L: 40%;
17+
--color-values: purple;
18+
}
19+
20+
.color-element {
21+
background-color: hsl(
22+
calc(var(--H) + 20),
23+
calc(var(--S) - 10%),
24+
calc(var(--L) + 30%)
25+
);
26+
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { StyleSheet, Text, View } from 'react-native';
2+
3+
export default function Basic() {
4+
return (
5+
<View className="bg-blue-100 p-5 rounded-full" style={styles.container}>
6+
<Text className="custom-style-test">Colored through CSS!</Text>
7+
</View>
8+
);
9+
}
10+
11+
const styles = StyleSheet.create({
12+
container: {
13+
flex: 1,
14+
alignItems: 'center',
15+
},
16+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Button } from 'react-native';
2+
3+
import { useColorScheme } from 'nativewind';
4+
5+
export default function DarkMode() {
6+
const { setColorScheme } = useColorScheme();
7+
return (
8+
<Button onPress={() => setColorScheme('dark')} title="Toggle dark mode" />
9+
);
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { vars } from 'nativewind';
2+
import { Text, View } from 'react-native';
3+
4+
export default function FuncsDirs() {
5+
return (
6+
<>
7+
<View style={vars({ '--my-custom-color': 'green' })}>
8+
<Text className="text-custom">Custom color</Text>
9+
</View>
10+
<View className="p-2 calc-element color-element">
11+
<Text>Calculated size</Text>
12+
</View>
13+
</>
14+
);
15+
}
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
import { StyleSheet, Text, View } from 'react-native';
1+
import { View } from 'react-native';
2+
import Basic from './Basic.tsx';
23
import ComponentWithVariants from './ComponentWithVariants.tsx';
34
import CustomComponent from './CustomComponent.tsx';
5+
import DarkMode from './DarkMode.tsx';
6+
import FuncsDirs from './FuncsDirs.tsx';
7+
import Responsive from './Responsive.tsx';
48
import Reusables from './Reusables.tsx';
59

610
export function NativeWindView() {
711
return (
812
<View className="gap-4 p-2">
9-
<View
10-
className="bg-blue-100 p-5 rounded-full sm:bg-red-500"
11-
style={styles.container}
12-
>
13-
<Text className="custom-style-test">Colored through CSS!</Text>
14-
</View>
13+
<Basic />
14+
<Responsive />
1515
<CustomComponent className="bg-green-600" />
1616
<ComponentWithVariants variant="primary" className="bg-yellow-500" />
1717
<Reusables />
18+
<DarkMode />
19+
<FuncsDirs />
1820
</View>
1921
);
2022
}
21-
22-
const styles = StyleSheet.create({
23-
container: {
24-
flex: 1,
25-
alignItems: 'center',
26-
},
27-
});

apps/tester-app/src/nativewind/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ This component demonstrates compatibility with different NativeWind features:
99
* custom components styled with className
1010
* components using the variants pattern
1111
* using component libraries (React Native Reusables)
12-
* TODO: themes https://www.nativewind.dev/guides/themes
1312
* responsive design
1413
* dark mode
15-
* functions & directives
14+
* functions & directives
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Text, View } from 'react-native';
2+
3+
export default function Responsive() {
4+
return (
5+
<View className="p-2 bg-orange-500 sm:bg-green-500 md:bg-red-500">
6+
<Text className="text-white">Responsive style based on width!</Text>
7+
</View>
8+
);
9+
}

apps/tester-app/tailwind.config.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
22
module.exports = {
33
content: ['./src/**/*.{js,jsx,ts,tsx}'],
44
presets: [require('nativewind/preset')],
5-
theme: { extend: {} },
5+
theme: {
6+
extend: {
7+
color: {
8+
custom: 'var(--my-custom-color)',
9+
primary: 'rgb(var(--color-values) / <alpha-value>)',
10+
},
11+
},
12+
},
13+
plugins: [
14+
// Set a default value on the `:root` element
15+
({ addBase }) =>
16+
addBase({
17+
':root': {
18+
'--color-values': '255 0 0',
19+
'--color-rgb': 'rgb(255 0 0)',
20+
},
21+
}),
22+
],
623
darkMode: 'class',
7-
plugins: [],
824
};

0 commit comments

Comments
 (0)