All the colors, sizes and layout rules are stored in our default theme. This can be found in the theme
folder inside our library. Every component inherits its styling rules from that file. Imagine this... You're building an application and you have 30 buttons using the primary color but you feel like that color doesn't really suit your project. You can re-write our theme file with only the things you want to change by using our theme components and all Galio components will change the that certain style.
- GalioTheme: default theme for components exporting an object with
{ COLORS, SIZES }
- withGalio: HoC for any React-Native component with args:
Component
and optionalstyles
. By using this, you can access constants we have in our default theme. - GalioProvider: React Context Provider getting custom theme from props and pass it to the React Context.
- install the latest galio-framework using
npm install galio-framework
oryarn add galio-framework
- import { theme, withGalio, GalioProvider } from 'galio-framework'
- export default withGalio(YourComponent, componentStyles);
- custom theme constants will overwrite the default galio theme constants
const customTheme = {
SIZES: { BASE: 18, }
// this will overwrite the Galio SIZES BASE value 16
COLORS: { PRIMARY: 'red', }
// this will overwrite the Galio COLORS PRIMARY color #B23AFC
};
<GalioProvider theme={customTheme}>
<YourComponent />
</GalioProvider>
Exporting a React class/function using our withGalio function enables your component to consume Galio's React Context and pass down theme in your component as a prop or as an argument for styles
. So now you can use our constant colors and sizes in your own components/screens.
const styles = theme => StyleSheet.create({
container: {
flex: 1,
backgroundColor: theme.COLORS.FACEBOOK
}
});
export default withGalio(App, styles);
Use the following reference tables to create your own custom theme
const { height, width } = Dimensions.get('screen');
By default the size of 16 is used to calculate all the sizes
Size name | Default value |
---|---|
THEME | |
BASE | 16 |
FONT | 16 |
ICON | 16 |
OPACITY | 0.8 |
BORDER_RADIUS | 6 |
BORDER_WIDTH | 0.8 |
BUTTON | |
BUTTON_WIDTH | 16 * 9 |
BUTTON_HEIGHT | 16 * 2.75 |
BUTTON_SHADOW_RADIUS | 10 |
BLOCK | |
BLOCK_SHADOW_OPACITY | 0.15 |
BLOCK_SHADOW_RADIUS | 8 |
ANDROID_ELEVATION | 1 |
CARD | |
CARD_BORDER_RADIUS | 16 * 0.4 |
CARD_BORDER_WIDTH | 16 * 0.05 |
CARD_WIDTH | width - (16 * 2) |
CARD_MARGIN_VERTICAL | 16 * 0.875 |
CARD_FOOTER_HORIZONTAL | 16 * 0.75 |
CARD_FOOTER_VERTICAL | 16 * 0.75 |
CARD_AVATAR_WIDTH | 16 * 2.5 |
CARD_AVATAR_HEIGHT | 16 * 2.5 |
CARD_AVATAR_RADIUS | 16 * 1.25 |
CARD_IMAGE_HEIGHT | 16 * 12.5 |
CARD_ROUND | 16 * 0.1875 |
CARD_ROUNDED | 16 * 0.5 |
INPUT | |
INPUT_BORDER_RADIUS | 16 * 0.5 |
INPUT_BORDER_WIDTH | 16 * 0.05 |
INPUT_HEIGHT | 16 * 2.75 |
INPUT_HORIZONTAL | 16 |
INPUT_TEXT | 16 * 0.875 |
INPUT_LABEL_TEXT | 16 * 0.9 |
INPUT_LABEL_BOTTOM | 16 / 4 |
INPUT_HELP_TEXT | 16 * 0.8 |
INPUT_ROUNDED | 16 * 1.7 |
NAVBAR | |
NAVBAR_HEIGHT | 16 * 4.125 |
NAVBAR_VERTICAL | 16 |
NAVBAR_TITLE_FLEX | 2 |
NAVBAR_TITLE_HEIGHT | height * 0.07 |
NAVBAR_TITLE_TEXT | 16 * 0.875 |
NAVBAR_LEFT_FLEX | 0.5 |
NAVBAR_LEFT_HEIGHT | height * 0.07 |
NAVBAR_LEFT_MARGIN | 16 |
NAVBAR_RIGHT_FLEX | 0.5 |
NAVBAR_RIGHT_HEIGHT | height * 0.07 |
NAVBAR_RIGHT_MARGIN | 16 |