Skip to main content

Customizing Themes

BaseTheme<TColors> is where you define your application's color palette, type scale, borders, border radius values, and more. If you need to customize the default theme to match your design requirements you should implement BaseTheme from @flexnative/theme-context.

Example

Example of using custom theme values.

import ThemeContext from '@flexnative/theme-context';

import {
BASE_SIZE,
BORDER_RADIUS,
BORDER_WIDTH,
DISABLED_OPACITY,
FONT_SIZE,
GHOST_ACTIVE_TRANSPARENCY,
GHOST_TRANSPARENCY,
PADDING_HORIZONTAL_MULTIPLIER,
PADDING_VERTICAL_MULTIPLIER
} from "./constants";

const myThemeColors = {
default: '#4A148C',
background: "#C5CAE9",
card: "#E8EAF6",
text: '#ffffff',
border: '#9FA8DA',
info: "#00E5FF",
success: "#00C853",
warning: "#F9A825",
error: "#B71C1C",
dark: "#212121",
secondary: "#F50057",
light: "#ebebeb",
primary: '#26C6DA',
overlay: '#00000021',
color1: '#C51162', //New color
color2: '#7B1FA2', //New color
};

const myTheme = {
colors: myThemeColors,
scheme: 'light',
borderWidth: BORDER_WIDTH,
borderRadius: BORDER_RADIUS,
fontSize: FONT_SIZE,
metrics: {
basSize: BASE_SIZE,
disabledOpacity: DISABLED_OPACITY,
ghostOpacity: GHOST_TRANSPARENCY,
verticalMultiplier: PADDING_VERTICAL_MULTIPLIER,
horizontalMultiplier: PADDING_HORIZONTAL_MULTIPLIER
}
}

function App() {
return (
<ThemeContext.Provider value={myTheme}>
<YourAPP />
</ThemeContext.Provider>
);
}
note

You can use createTheme method to create your custom theme.

import ThemeContext, { BaseTheme, createTheme, light as colors} from '@flexnative/theme-context';


type MyExtraColorsProps = {
color1: ColorValue;
color2: ColorValue,
}

const myThemeColors: BaseTheme<MyExtraColorsProps> = {
...colors
color1: '#C51162', //New color
color2: '#7B1FA2', //New color
};

const metrics: {
basSize: 12,
}

function App() {
return (
<ThemeContext.Provider value={createTheme({colors: myThemeColors, metrics})}>
<YourAPP />
</ThemeContext.Provider>
);
}