Skip to content

Commit 5941231

Browse files
authored
Merge pull request #18 from mohit23x/docs
update readme and guide
2 parents 86ad14b + 443cec2 commit 5941231

File tree

3 files changed

+331
-82
lines changed

3 files changed

+331
-82
lines changed

README.md

Lines changed: 23 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<h1 align="left">
22

3-
React Native Sugar Style
3+
🚀React Native Sugar Style
44

55
</h1>
6+
67
https://www.npmjs.com/package/react-native-sugar-style (🧪 Experimental)
78

8-
- Theme based alternative for React Native StyleSheet
9+
<br />
10+
11+
🎨 Theme based alternative for React Native StyleSheet
912

10-
- Support responsive values as array
13+
Support responsive values as array
1114

12-
- works on android/ios/web (expo/react-native)
15+
📐 Reduce computing device height & width in every component
1316

14-
| BEFORE | AFTER |
15-
| ------------------------------------- | ---------------------------------- |
16-
| ![Before](assets/before.png "Before") | ![After](assets/after.png "After") |
17+
📱 Works on android/ios/web (expo/react-native)
1718

18-
### Install
19+
## Install
1920

2021
```
2122
yarn add react-native-sugar-style
@@ -25,7 +26,7 @@ yarn add react-native-sugar-style
2526
npm i react-native-sugar-style
2627
```
2728

28-
### Usage
29+
## Usage
2930

3031
STEP 1: **style.tsx**
3132

@@ -44,123 +45,64 @@ const light = {
4445
text: "#000000",
4546
};
4647

47-
export const { StyleSheet, ThemeProvider, useTheme } = Sugar(light);
48+
export const { StyleSheet } = Sugar(light);
4849

4950
export default StyleSheet;
5051
```
5152

5253
<br />
5354

54-
STEP 2: **App.tsx**
55-
56-
Wrap with ThemeProvider
57-
58-
```javascript
59-
import React from 'react';
60-
import {ThemeProvider} from './style';
61-
import Navigation from './navigation';
62-
63-
const App = () => (
64-
<ThemeProvider>
65-
<Navigation>
66-
</ThemeProvider>
67-
);
68-
```
69-
70-
<br />
71-
72-
STEP 3: **component.tsx**
55+
STEP 2: **component.tsx**
7356

7457
Use StyleSheet as you do normally do in components
7558

7659
```javascript
7760
import React from "react";
7861
import { View, Text } from "react-native";
79-
import { StyleSheet, useTheme } from "./style";
62+
import { StyleSheet } from "./style";
8063

8164
const Component = () => {
82-
useTheme();
83-
8465
return (
8566
<View style={styles.container}>
8667
<Text style={styles.text}>Hello World</Text>
8768
</View>
8869
);
8970
};
9071

91-
const styles = StyleSheet.create((theme, constants) => ({
72+
const styles = StyleSheet.create((theme) => ({
9273
container: {
9374
height: constants.height,
9475
width: constants.width,
9576
backgroundColor: theme.background,
9677
flexDirection: ["column", "row"],
9778
},
9879
text: {
99-
fontSize: theme.size.m,
10080
color: theme.text,
10181
},
10282
}));
10383
```
10484

105-
> **NOTE**: if you add `useTheme()` in the navigation screen (parent component), then you can avoid using it in child components\*
106-
10785
<br />
10886

109-
STEP 4: **anotherComponent.tsx**
110-
111-
To change the theme you can call build method and it will swap the theme
112-
113-
```javascript
114-
import React from "react";
115-
import { View, Button } from "react-native";
116-
import { StyleSheet, light, dark } from "./style";
117-
118-
const Component = () => {
119-
const onLight = () => StyleSheet.build(light);
120-
const onDark = () => StyleSheet.build(dark);
121-
122-
return (
123-
<View>
124-
<Button onPress={onLight} title="light theme" />
125-
<Button onPress={onDark} title="dark theme" />
126-
</View>
127-
);
128-
};
129-
```
130-
131-
### Demo
87+
## Demo
13288

13389
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.
13490
https://expo.io/@mohit23x/projects/react-native-sugar-style or try the [react native web version](https://sugar-style.netlify.app/)
13591

13692
![Scan QR with expo app](assets/qr.png "Scan QR")
13793

138-
### Constants
139-
140-
Available as **theme.constant**
141-
142-
| Name | Type | React Native way |
143-
| ------------------------------------------------------------- | ------- | ------------------------------------------ |
144-
| height | number | const {height} = Dimensions.get('window'); |
145-
| width | number | const {width} = Dimensions.get('window'); |
146-
| screenHeight | number | const {height} = Dimensions.get('screen'); |
147-
| screenWidth | number | const {width} = Dimensions.get('screen'); |
148-
| statusBarHeight | number | StatusBar.currentHeight |
149-
| navBarHeight | number | screenHeight - statusBarHeight - height |
150-
| isNavBarVisible | boolean | bottom navigation is visible or not |
151-
| visibleHeight | number | height - navBarHeight |
152-
| platform: {android, ios, windows, web, isPad, isTv,isIPhoneX} | boolean | Platform.OS === 'android' |
94+
## More
15395

154-
### Why this package?
96+
[Guide](docs/Guide.md#Guide)
15597

156-
[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.
98+
[Constants](docs/Guide.md#Constants)
15799

158-
### Acknowledgement
100+
[API](docs/Guide.md#API)
159101

160-
Special thanks to the Authors of the amazing open source libraries
102+
[Live Example](docs/Guide.md#Demo)
161103

162-
[React Native Extended Stylesheet](https://github.com/vitalets/react-native-extended-stylesheet)
104+
[Why this Package](docs/Guide.md#Why?)
163105

164-
### Caveats
106+
[Acknowledgement](docs/Guide.md#Acknowledgement)
165107

166-
- May introduce performance issues (not tested)
108+
[Caveats](docs/Guide.md#Caveats)

0 commit comments

Comments
 (0)