Skip to content

Commit e24780f

Browse files
chore: updated readme
1 parent 1605b08 commit e24780f

File tree

2 files changed

+70
-14
lines changed

2 files changed

+70
-14
lines changed

README.md

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ No additional steps are necessary.
2727
## Usage
2828
<details><summary>Theme</summary>
2929
<br />
30+
3031
## Basic usage
3132

3233
You don't need extra steps to use the default theme via whole app. The default theme is ***light***.
3334

3435

35-
## Custom theme
36+
## Custom Theme
3637

37-
**You need to wrap whole app in ```ThemeContainer```**
38+
**You need to wrap whole app in ```MaterialComponentsProvider```**
3839

3940
This library provides an opportunity to automatically create themes from target colors. ```buildThemesFromColors``` function takes theme colors and returns light and dark themes.
4041
Each theme color must be one of the next color formats: hex, rgb or rgba.
@@ -56,56 +57,99 @@ const themes = buildThemesFromColors(themeColors);
5657
5758
export default function App() {
5859
return (
59-
<ThemeContainer theme={themes.lightTheme}>
60+
<MaterialComponentsProvider theme={themes.lightTheme}>
6061
{/* Rest of your app code */}
61-
</ThemeContainer>
62+
</MaterialComponentsProvider>
6263
);
6364
}
6465
```
6566

66-
Also, you can create a custom theme manually and pass it as a property to the ThemeContainer component. (hint: Check Theme interface provided by the library)
67+
Also, you can create a custom theme manually and pass it as a property to the MaterialComponentsProvider component. (hint: Check Theme interface provided by the library)
6768

6869
## Themes provided via the library
6970

7071
This library provides _dark_ and _light_ themes e.g. on iOS 13+ and Android 10+, you can get user's preferred color scheme ('dark' or 'light') with the ([Appearance API](https://reactnative.dev/docs/appearance)).
7172

72-
**You need to wrap whole app in ```ThemeContainer```**
73+
**You need to wrap whole app in ```MaterialComponentsProvider```**
7374

7475
```
7576
import {useColorScheme} from 'react-native';
76-
import {ThemeContainer, DarkTheme, LightTheme} from '@computools/react-native-material-components';
77+
import {MaterialComponentsProvider, DarkTheme, LightTheme} from '@computools/react-native-material-components';
7778
7879
export default function App() {
7980
const scheme = useColorScheme();
8081
8182
return (
82-
<ThemeContainer theme={scheme === 'dark' ? DarkTheme : LightTheme}>
83+
<MaterialComponentsProvider theme={scheme === 'dark' ? DarkTheme : LightTheme}>
8384
{/* Rest of your app code */}
84-
</ThemeContainer>
85+
</MaterialComponentsProvider>
8586
);
8687
};
8788
```
8889

89-
## Using the current theme in your own components
90+
## Using the current Theme in your own components
9091

9192
To gain access to the theme in any component you can use the useTheme hook. It returns the theme object:
9293

9394
```
9495
import React from 'react';
95-
import {TouchableOpacity, Text} from 'react-native';
96+
import {TouchableOpacity, Text, TouchableOpacityProps} from 'react-native';
9697
import {useTheme} from '@computools/react-native-material-components';
9798
98-
export const MySubmitButton() => {
99+
export const MySubmitButton: React.FC<TouchableOpacityProps> = ({style, ...props}) => {
99100
const {primary} = useTheme();
100101
101102
return (
102-
<TouchableOpacity style={{backgroundColor: primary.container}}>
103+
<TouchableOpacity style={[{backgroundColor: primary.container}, style]} {...props}>
103104
<Text>Submit</Text>
104105
</TouchableOpacity>
105106
);
106107
}
107108
```
108109
</details>
110+
<details><summary>Typography</summary>
111+
112+
## Basic usage
113+
114+
You don't need extra steps to use the default typography via whole app. The default font is Roboto for Android and san Francisco for IOS.
115+
116+
## Custom Typography
117+
118+
**You need to wrap whole app in ```MaterialComponentsProvider```**
119+
120+
You can create a custom typography styles and pass it as a typography property to the MaterialComponentsProvider component.
121+
122+
_See the example:_
123+
```
124+
import {MaterialComponentsProvider, materialTypography, MaterialTypography} from '@computools/react-native-material-components';
125+
126+
const typographyStyles: MaterialTypography = {...materialTypography, bodyMedium: {...materialTypography.bodyMedium, fontFamily: 'Montserrat-Medium'}}
127+
128+
export default function App() {
129+
return (
130+
<MaterialComponentsProvider typography={typographyStyles}>
131+
{/* Rest of your app code */}
132+
</MaterialComponentsProvider>
133+
);
134+
}
135+
```
136+
137+
## Using the current Typography in your own components
138+
139+
To gain access to the typography in any component you can use the useTypography hook. It returns the material typography styles object:
140+
141+
```
142+
import React, {PropsWithChildren} from 'react';
143+
import {TouchableOpacity, Text} from 'react-native';
144+
import {useTypography} from '@computools/react-native-material-components';
145+
146+
export const AppBodyLargeText: React.FC<PropsWithChildren> = ({children}) => {
147+
const {bodyLarge} = useTypography();
148+
149+
return <Text style={bodyLarge}>{children}</Text>;
150+
}
151+
```
152+
</deatils>
109153
<details><summary>Activity Indicators</summary>
110154
<br />
111155
<details><summary>Circular Activity Indicator</summary>

example/src/App.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import * as React from 'react';
22
import {StyleSheet, View} from 'react-native';
3+
import {GestureHandlerRootView} from 'react-native-gesture-handler';
4+
5+
import {MaterialComponentsProvider, materialTypography} from '@computools/react-native-material-components';
6+
import {SafeAreaProvider} from 'react-native-safe-area-context';
37

48
export default function App() {
5-
return <View style={styles.container} />;
9+
return (
10+
<MaterialComponentsProvider typography={{...materialTypography, bodyLarge: {...materialTypography.bodyLarge, fontWeight: '800'}}}>
11+
<SafeAreaProvider>
12+
<GestureHandlerRootView style={{flex: 1}}>
13+
<View style={styles.container}></View>
14+
</GestureHandlerRootView>
15+
</SafeAreaProvider>
16+
</MaterialComponentsProvider>
17+
);
618
}
719

820
export const styles = StyleSheet.create({

0 commit comments

Comments
 (0)