react-native-css icon indicating copy to clipboard operation
react-native-css copied to clipboard

Unable to use interpolation in CSS

Open anzorb opened this issue 8 years ago • 5 comments

[email protected] [email protected] 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

anzorb avatar Sep 06 '17 01:09 anzorb

Thank you, I will investigate.

thabti avatar Sep 06 '17 09:09 thabti

@anzorb

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

thabti avatar Sep 06 '17 09:09 thabti

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 ^

anzorb avatar Sep 06 '17 13:09 anzorb

@anzorb thank you so much for doing all the digging. Please test [email protected].

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

should be working as expected.

thabti avatar Sep 10 '17 20:09 thabti

Hi,

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

yuritoledo avatar Feb 18 '18 14:02 yuritoledo