-
Notifications
You must be signed in to change notification settings - Fork 2
Theme
The application supports multi-theming based on the device theme for both platforms.
Use the colors.ts file in order to add colors. It's recommended to keep the app's colors in this file in order not to repeat them. Otherwise, it'll be impossible to implement multi-theming correctly. If you don't know how to choose the name for a color then there is a useful tool for this.
The next type is used in order to describe the application theme:
export type Theme = {
primary: string;
accent: string;
background: string;
surface: string;
error: string;
text: string;
secondaryText: string;
separator: string;
disabled: string;
placeholder: string;
backdrop: string;
notification: string;
};
-
primary
- primary color for your app, usually your brand color; -
accent
- secondary color for your app which complements the primary color; -
background
- background color for pages, such as lists; -
surface
- background color for elements containing content, such as cards; -
error
- color for error's text; -
text
- primary color for app's text; -
secondaryText
- secondary color for app's text; -
separator
- color is used for separators; -
disabled
- color for disabled elements; -
placeholder
- color for placeholder text, such as input placeholder; -
backdrop
- color for backdrops of various components such as modals; -
notification
- color is used for notification's color.
You could also extend your own theme type.
useTheme
is a hook that was developed in order to support dynamic changes for the app's theme. It also makes it possible to use StyleSheet
dynamically.
In order to use this hook correctly, follow the steps below:
- Create
styles.ts
file in the component's folder; - Use
styleSheetFactory
function from thetheme
module:
export default styleSheetFactory(theme => ({
text: {
color: theme.text,
},
});
-
import themedStyles from './styles'
in the component's file; - Use
useTheme
hook:
const [styles, theme, resolvedName] = useTheme(themedStyles);
-
styles
- is a style sheet object that is used for styling; -
theme
- is an object that contains theme's colors; -
resolvedName
- is a name of the current theme;
useImages
is a hook that was developed in order to support different images based on the current theme.
If you want to add a new image to the project then add it to light
and dark
images in images.ts.
In order to use this hook correctly, follow the steps below:
- Use
useImages
hook:
const images = useImages();
- Use the object with the images.
A good practice throughout working with sizes is to keep them in a single file. In the future, it'll be possible to make global changes from a single place. It also helps us to standardize the sizes for the whole application. Use sizes.ts in order to keep all the sizes.
The base project contains a lot of working examples, use this folder as a reference.