我为EStyleSheet.globalVars获取null

时间:2018-01-22 04:50:09

标签: reactjs react-native

我正在使用react-native-extended-stylesheet

EStyleSheet.build({   
        $currencyFontColor: 'hsl(45, 100%, 94%)',
});

...

const styles = EStyleSheet.create({

   underlayColor: Color(EStyleSheet.value('$currencyFontColor')).darken(0.5),
});

但我明白了:

 Unresolved variable: $currencyFontColor

我还尝试console.log('global vars', EStyleSheet.globalVars);并获得了global vars null

1 个答案:

答案 0 :(得分:1)

如文档所述:

  

请注意,在大多数情况下,应在函数内部而不是直接使用EStyleSheet.value()

const styles = EStyleSheet.create({
  button1: {
    width: () => EStyleSheet.value('$contentWidth') + 10 // <-- Correct!
  },
  button2: {
    width: EStyleSheet.value('$contentWidth') + 10 // <-- Incorrect. Because EStyleSheet.build() may occur later and $contentWidth will be undefined at this moment.
  }
});

您的代码必须像这样才能正常工作

EStyleSheet.build({   
    $currencyFontColor: 'hsl(45, 100%, 94%)',
});

...

const styles = EStyleSheet.create({

   underlayColor: () => Color(EStyleSheet.value('$currencyFontColor')).darken(0.5),
});