GeekyAnts / NativeBase

Mobile-first, accessible components for React Native & Web to build consistent UI across Android, iOS and Web.
https://nativebase.io/
MIT License
20.19k stars 2.38k forks source link

How can I get active theme variables in my custom component? #3044

Closed mehmet-erim closed 4 years ago

mehmet-erim commented 4 years ago

I have gone through these following points

bouchezb commented 4 years ago

Hi,

I had the same problem and i solved it by exporting theme variables in a wrapper module which provides my base stylesheet. Before that i started the theme ejection process described here https://docs.nativebase.io/Customize.html#theaming-nb-headref

export { default as ThemeVariables } from '../native-base-theme/variables/material'

then i use these variables in my components

import { ThemeVariables } from 'path/to/wrapper/module'

<Ionicons  name={'md-star'} color={ThemeVariables.brandWarning} size={35}  />

It works, but I don't think this is the right way to do it. Documentations are not really clear on this point. If someone knows a more elegant way to do this, I'll be happy to learn.

Regards.

Edit:

Also, take a look at these issues https://github.com/GeekyAnts/NativeBase/issues/2425 https://github.com/GeekyAnts/NativeBase/issues/1543

hanykumar commented 4 years ago

Hi @mehmet-erim, as mentioned in the documentation https://docs.nativebase.io/Customize.html#theaming-nb-headref, you can use material as variable.

import React, { Component } from 'react'; import { Container, Content, Text, StyleProvider } from 'native-base'; import getTheme from './native-base-theme/components'; import material from './native-base-theme/variables/material';export default class ThemeExample extends Component { render() { return ( <StyleProvider style={getTheme(material)}> <Container> <Content> <Button style={{backgroundColor: material.brandWarning}}> <Text>Click</Text> </Button> </Content> </Container> </StyleProvider> ); } }

hanykumar commented 4 years ago

Hi @mehmet-erim, latest version of Native base has been released. The issues should be fixed now. Native Base 2.13.12