StyleSheetRegistry刷新所有(和/或一些)

时间:2017-11-29 16:24:31

标签: react-native

我创建了我的StyleSheet,但记住了这些StyleSheet

const CONFIG = {
    blue: '#19281a'
}

const styles = StyleSheet.create({
   blah: {
       backgroundColor: CONFIG.blue
   }
})

现在我想更改我的主题,所以我更改CONFIG中的值,但现在我要刷新所有(和/或一些)StyleSheets。这可能吗?

1 个答案:

答案 0 :(得分:1)

简短的回答是否定的。标准StyleSheet创建静态样式表。

当我需要做主题时,

react-native-extended-stylesheet就是我最终的目标。它扩展了StyleSheet并添加了额外的功能,因此迁移是轻松的。

在更改主题/必须强制重新呈现整个应用/丢失状态时有一些注意事项,但这些很容易解决。

https://github.com/vitalets/react-native-extended-stylesheet