thabti / react-native-css

Style React-Native components with css
MIT License
769 stars 66 forks source link

Unable to use interpolation in CSS #61

Open anzorb opened 7 years ago

anzorb commented 7 years ago

react-native@0.47.2 react-native-css@2.0.7 Android 7.1.1

code:

    const runningColor = 'green';

    const lss = RNC`
     bla {
        background-color: ${runningColor};
      }
    `

    return <View style={lss.bla}></View>

Error: screenshot_20170905-213944

thabti commented 7 years ago

Thank you, I will investigate.

thabti commented 7 years ago

@anzorb

Does this only happen when using ${runningColor};?

anzorb commented 7 years ago

Any variable would cause this issue because it didn't appear to get interpolated when it was consumed by toJSS(). A console.log(css) in there show this.

If the string is encapsulated in brackets, it all works great.

 const runningColor = 'green';

    const lss = RNC(`
     bla {
        background-color: ${runningColor};
      }
    `);

    return <View style={lss.bla}></View>

Tagged template literals behave different with or without parentesis: Chrome:

const test = 'literals';

console.log`hello template ${test}`
>["hello template ", "", raw: Array(2)] 
"literals"

console.log(`hello template ${test}`)
>hello template literals

I don't have enough time to keep digging (and I can live with brackets), but maybe above info will make it obvious for you ^

thabti commented 7 years ago

@anzorb thank you so much for doing all the digging. Please test react-native-css@2.1.1.

Add the following test:https://github.com/sabeurthabti/react-native-css/blob/a7ad812fbb346daae052b337467d71e1e3d46fee/test/rnc.test.js#L240

should be working as expected.

yuritoledo commented 6 years ago

Hi,

Just for information, in the "react-native-css": "^2.1.2" works normally!