gluestack

gluestack Logogluestack

How to custom Theme with createConfig

thanghoba posted this in #support
Open in Discord
Avatar
thanghobaOP
export const gluestackUIConfig = createConfig({ aliases, tokens, themes: { light: {}, dark: {}, custom: { // Some code here }, }, globalStyle, plugins: [new AnimationResolver(MotionAnimationDriver)], });

13 Replies

Avatar
sravankumar101
hey @thanghoba
you can directly copy paste the custom theme you've written to the gluestackuiprovider - > in the config prop
And also you can extend the property with some new objects but you can't directly add new properties
For example :
import { config as defaultConfig } from "@gluestack-ui/config"; import { createConfig } from "@gluestack-ui/themed"; const config = createConfig({ ...defaultConfig, tokens: { ...defaultConfig.tokens, colors: { ...defaultConfig.tokens.colors, info800: "#540B8C", info900: "#4A116D", }, space: { ...defaultConfig.tokens.space, "212": 212, //layoutPadding "234": 234, //qrBoxInner "372": 372, //imgWidth "508": 508, //boxSize "544": 544, authcard: 544, "622": 622, containerWidth: 1016, }, borderWidths: { ...defaultConfig.tokens.borderWidths, "20": 20, "50": 50, }, opacity: { ...defaultConfig.tokens.opacity, }, fonts: { ...defaultConfig.tokens.fonts, body: "Manrope-Regular", heading: "Manrope-Bold", }, }, components: { ...defaultConfig.components, }, }); export { config };
I've added some extra space values in the object like 212,234,authcard, etc.., which will not be available by the default config of gluestack.This is possible
But you can't customly create a property like custom and expect that to work.
Avatar
thanghobaOP
I want create themes and using this component.
import { Theme } from '@gluestack-ui/themed';
And i using hooks useTheme() and log this data in the hooks is a empty array.
Avatar
thanghobaOP
I think the way <Theme>works is similar to tamagui <Theme>: https://tamagui.dev/docs/core/theme
Avatar
viraj1098
Avatar
thanghobaOP
@viraj1098 No, I mean custom Theme and using it like Theme tamagui
Avatar
viraj1098
Also if you are starting a project please start with v2 instead of v1
Avatar
thanghobaOP
I'm doing some basic practice with gluestack before applying it to my project.
I tried to follow the link you sent but it encountered some issues like:
It only receives 1 Theme in the back, I set state and toggle change theme but don't work.