You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -10,13 +10,17 @@ Theme based alternative for React Native StyleSheet. (🧪 Highly Experimental)
10
10
11
11
```
12
12
yarn add react-native-sugar-style
13
+
```
13
14
15
+
```
14
16
npm i react-native-sugar-style
15
17
```
16
18
17
19
### Usage
18
20
19
-
**style.tsx** - define a configuration for you theme
21
+
STEP 1: _style.tsx_
22
+
23
+
Define configurations for your theme see [this file](https://github.com/mohit23x/react-native-sugar-style/blob/main/example/style/index.tsx) for a more verbose example
> **NOTE**: if you have a single theme then `useTheme()` hook can be avoided, also if you add `useTheme()` in you navigation screen parent component, then you can avoid using it in child components\*
89
+
90
+
STEP 4: **anotherComponent.tsx** (optional)
91
+
92
+
To change the theme you can call build method and it will swap the theme
93
+
94
+
```javascript
95
+
importReactfrom'react';
96
+
import { View, Button } from'react-native';
97
+
import { StyleSheet } from'./style';
98
+
99
+
constComponent= () => {
100
+
constlight= () =>StyleSheet.build(lightTheme);
101
+
constdark= () =>StyleSheet.build(darkTheme);
102
+
103
+
return (
104
+
<View>
105
+
<Button onPress={light} title="light"/>
106
+
<Button onPress={dark} title="dark"/>
107
+
</View>
108
+
);
109
+
};
110
+
```
111
+
62
112
### Demo
63
113
64
-
Scan and run with expo go app, See example folder for a complete setup.
114
+
Scan and run with expo go app, run the [example project](https://github.com/mohit23x/react-native-sugar-style/tree/main/example) for a more detailed example.
@@ -85,7 +135,7 @@ Available as **theme.constant**
85
135
86
136
### Why this package?
87
137
88
-
[There](https://github.com/vitalets/react-native-extended-stylesheet)[are](https://github.com/wvteijlingen/react-native-themed-styles)[many](https://github.com/wvteijlingen/react-native-themed-styles)[awesome](https://github.com/Shopify/restyle)[solutions](https://github.com/callstack/react-theme-provider)[for](https://www.npmjs.com/package/simple-theme) React Native. Through this package i wanted to explore and experiment a way to achieve a solution which is very similar to the existing react native code pattern, with the ability to get dynamic theme value and can be used in functional and class based components.
138
+
[There](https://github.com/vitalets/react-native-extended-stylesheet)[are](https://github.com/wvteijlingen/react-native-themed-styles)[many](https://github.com/wvteijlingen/react-native-themed-styles)[awesome](https://github.com/Shopify/restyle)[solutions](https://github.com/callstack/react-theme-provider)[for](https://www.npmjs.com/package/simple-theme)[styling](https://github.com/nandorojo/dripsy) in React Native. Through this package i wanted to explore and experiment a way to achieve a development experience which is very similar to the existing react native pattern, with the ability to get dynamic theme value and can be used in functional and class based components.
89
139
90
140
### Acknowledgement
91
141
@@ -96,7 +146,4 @@ Special thanks to the Authors of the amazing open source libraries
96
146
### Caveats
97
147
98
148
- May introduce performance issues (not tested)
99
-
- Re-rendering on theme change causes mount and un-mounting of parent
100
-
- re-renders when same theme is applied again
101
-
- Caching not implemented
102
-
- Dimension values are not dynamic
149
+
- Dimension values are not dynamic (device height/width don't change based on orientation)
0 commit comments