Skip to content
This repository has been archived by the owner on Apr 18, 2020. It is now read-only.

Unable to use interpolation in CSS #61

Open
anzorb opened this issue Sep 6, 2017 · 5 comments
Open

Unable to use interpolation in CSS #61

anzorb opened this issue Sep 6, 2017 · 5 comments

Comments

@anzorb
Copy link

anzorb commented Sep 6, 2017

[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

@thabti
Copy link
Owner

thabti commented Sep 6, 2017

Thank you, I will investigate.

@thabti
Copy link
Owner

thabti commented Sep 6, 2017

@anzorb

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

@anzorb
Copy link
Author

anzorb commented Sep 6, 2017

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
Copy link
Owner

thabti commented Sep 10, 2017

@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.

@yuritoledo
Copy link

Hi,

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants