vitalets / react-native-extended-stylesheet

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

Multiple math operators #60

Closed deadcoder0904 closed 5 years ago

deadcoder0904 commented 6 years ago

Currently only 1 operator is supported, so if I have to do the following I can't

{
  height: '$deviceHeight/2-100'
}

Instead I have to do

{
  $halfDeviceHeight: '$deviceHeight/2',
  height: '$halfDeviceHeight-100'
}

So for many operators this becomes unnecessary & this happens for quite a few use cases that I've encountered in the past few weeks or so

vitalets commented 6 years ago

Yes, it seems to be rare cases. Multiple operators support is not trivial - we should consider operators priority and maybe support brackets - all this increases complexity. I'm thinking about setting such values via function. Something like this:

{
  height: () => EStyleSheet.value('$deviceHeight/2') - 100
}

Currently this will work only with global variables. But technically it is possible to provide local variables to calls of EStyleSheet.value() during calculation of particular sheet.

deadcoder0904 commented 6 years ago

When complex UI comes, its not a rare case. As I am developing many RN apps right now, I feel that need because for different devices, the UI doesn't seem to work. react-native-extended-stylesheet reduces lot of my work & this particular case is what makes me to create unnecessary local variables. Thank you for this repo. It really helps a lot 😄

vitalets commented 6 years ago

ok, thanks for the feedback! Will such approach be sufficient for you tasks?

{
  height: () => EStyleSheet.value('$deviceHeight/2') - 100
}
deadcoder0904 commented 6 years ago

Yep that works perfectly fine

vitalets commented 6 years ago

Ok. I will have a look.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.