vitalets / react-native-extended-stylesheet

Extended StyleSheets for React Native
MIT License
2.93k stars 132 forks source link

Extended styles sheets not working with React native version 0.53.3 #82

Closed shubhi15 closed 6 years ago

shubhi15 commented 6 years ago

Hello

I am trying to use EStyleSheet.create method to create my styles but it is returning me empty object. Code refrence import EStyleSheet from 'react-native-extended-stylesheet';

const styles = EStyleSheet.create({ background: { backgroundColor: '#fff', flex: 1, }, }); console.log("exported category styles"); console.log(styles) export default styles;

my console statement returning styles as empty object.

Regards Shubhi

vitalets commented 6 years ago

Hi @shubhi15!

Do you call EStyleSheet.build() in your code?

anderllr commented 6 years ago

I'm with the same error, and I called EStyleSheet.build() in my App.js file.

vitalets commented 6 years ago

I think this is because styles are imported (and executed) before EStyleSheet.build() call. Imagine you have app.js:

import styles from './styles'; // <-- occurs before EStyleSheet.build()

EStyleSheet.build();

and styles.js is:

import EStyleSheet from 'react-native-extended-stylesheet';

const styles = EStyleSheet.create({
  background: {
    backgroundColor: '#fff',
    flex: 1,
  },
});
console.log("exported category styles");
console.log(styles); // <-- here styles are not builded yet and console shows {}
export default styles; 

If this does not help, please show your code as Expo snack using this template: https://snack.expo.io/@vitalets/extended-stylesheet-simple

anderllr commented 6 years ago

Thanks @vitalets you're right, I've forgotten to call the js file where EStyleSheet.build(); was configured.

vitalets commented 6 years ago

You are welcome!