From 443cec2cac2e71056e864521c95ce31f699132dd Mon Sep 17 00:00:00 2001 From: Mohit Date: Sun, 7 Mar 2021 18:30:29 +0530 Subject: [PATCH] update readme and guide --- README.md | 104 ++++------------- docs/Guide.md | 307 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 331 insertions(+), 82 deletions(-) create mode 100644 docs/Guide.md diff --git a/README.md b/README.md index 83dd475..353d00b 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,22 @@

- React Native Sugar Style + πŸš€React Native Sugar Style

+ https://www.npmjs.com/package/react-native-sugar-style (πŸ§ͺ Experimental) -- Theme based alternative for React Native StyleSheet +
+ +🎨 Theme based alternative for React Native StyleSheet -- Support responsive values as array +✨ Support responsive values as array -- works on android/ios/web (expo/react-native) +πŸ“ Reduce computing device height & width in every component -| BEFORE | AFTER | -| ------------------------------------- | ---------------------------------- | -| ![Before](assets/before.png "Before") | ![After](assets/after.png "After") | +πŸ“± Works on android/ios/web (expo/react-native) -### Install +## Install ``` yarn add react-native-sugar-style @@ -25,7 +26,7 @@ yarn add react-native-sugar-style npm i react-native-sugar-style ``` -### Usage +## Usage STEP 1: **style.tsx** @@ -44,43 +45,23 @@ const light = { text: "#000000", }; -export const { StyleSheet, ThemeProvider, useTheme } = Sugar(light); +export const { StyleSheet } = Sugar(light); export default StyleSheet; ```
-STEP 2: **App.tsx** - -Wrap with ThemeProvider - -```javascript -import React from 'react'; -import {ThemeProvider} from './style'; -import Navigation from './navigation'; - -const App = () => ( - - - -); -``` - -
- -STEP 3: **component.tsx** +STEP 2: **component.tsx** Use StyleSheet as you do normally do in components ```javascript import React from "react"; import { View, Text } from "react-native"; -import { StyleSheet, useTheme } from "./style"; +import { StyleSheet } from "./style"; const Component = () => { - useTheme(); - return ( Hello World @@ -88,7 +69,7 @@ const Component = () => { ); }; -const styles = StyleSheet.create((theme, constants) => ({ +const styles = StyleSheet.create((theme) => ({ container: { height: constants.height, width: constants.width, @@ -96,71 +77,32 @@ const styles = StyleSheet.create((theme, constants) => ({ flexDirection: ["column", "row"], }, text: { - fontSize: theme.size.m, color: theme.text, }, })); ``` -> **NOTE**: if you add `useTheme()` in the navigation screen (parent component), then you can avoid using it in child components\* -
-STEP 4: **anotherComponent.tsx** - -To change the theme you can call build method and it will swap the theme - -```javascript -import React from "react"; -import { View, Button } from "react-native"; -import { StyleSheet, light, dark } from "./style"; - -const Component = () => { - const onLight = () => StyleSheet.build(light); - const onDark = () => StyleSheet.build(dark); - - return ( - -