I am trying to use react-native-elements with my React-Native app.
I have a central js file with theme details which are being injected using ThemeProvider as explained here - https://react-native-elements.github.io/react-native-elements/docs/customization.html
However, when I try to use the passed theme in a component's stylesheet.create method, I am getting an error. What am I doing wrong? -
import React from 'react';
import {View, StyleSheet} from 'react-native';
import {Text, withTheme} from 'react-native-elements';
const Header = props => {
const {theme} = props;
return (
<View style={styles.container}>
<Text>Home</Text>
</View>
);
};
const styles = StyleSheet.create({
container: {
width: '100%',
backgroundColor: theme.container.backgroundColor,//**** Getting error here stating that theme is not defined
shadowRadius: 1.5,
elevation: 2,
shadowColor: 'rgb(0,0,0)',
shadowOpacity: 0.4,
shadowOffset: {width: 0, height: 2.5},
},
});
export default withTheme(Header);
Please let me know if I can provide further details.
Update:
Thanks to the suggestion provided below @Sebastian Berglönn , I was able to get it parameterised without exporting to a different file by doing this -
const Header = props => {
const {theme} = props;
return (
<View style={styles(theme).container}>
<Text>Home</Text>
</View>
);
};
const styles = theme =>
StyleSheet.create({
container: {
width: '100%',
backgroundColor: theme.container.backgroundColor,
shadowRadius: 1.5,
elevation: 2,
shadowColor: 'rgb(0,0,0)',
shadowOpacity: 0.4,
shadowOffset: {width: 0, height: 2.5},
},
});