我正在尝试使用 react-native-ui-kitten 来反应原生组件并且它的工作很好。最近我想在我的应用程序中添加主题,为此我使用了他们的“RkTheme”和“RkType”,但没有一个有效。
期望 - 使用 RkTheme.setTheme(themeJson) 设置主题应该改变已经呈现在屏幕上的元素的样式
实际 - 使用 RkTheme.setTheme(themeJson) 设置主题不会改变已渲染组件的样式。
下面是包json的一部分
"dependencies": {
"prop-types": "^15.6.1",
"react": "16.2.0",
"react-dom": "^16.3.1",
"react-native": "0.51.0",
"react-native-linear-gradient": "^2.4.0",
"react-native-popup-menu": "^0.9",
"react-native-ui-kitten": "3.1.2",
"react-native-vector-icons": "^4.6.0",
"react-navigation": "1.0.0-beta.11",
"react-redux": "^5.0.7",
"realm": "^2.15.3",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"util": "^0.11.0",
},
反应组件的示例代码
import React from 'react'
import { StyleSheet, Text, View, Image, Button , TouchableOpacity} from 'react-native'
import {applyTheme} from '../config/bootstrap'
import {RkStyleSheet, RkTheme} from 'react-native-ui-kitten'
import { LightTheme } from '../config/lightTheme';
import { DarkTheme } from '../config/darkTheme';
export default class Sample extends React.Component {
constructor(props){
super(props)
this.changeTheme = this.changeTheme.bind(this)
}
changeTheme(theme){
if(theme){
RkTheme.setTheme(DarkTheme,null)
} else {
RkTheme.setTheme(LightTheme,null)
}
}
render() {
return (
<View style={styles.container}>
<Text>Sample</Text>
<TouchableOpacity onPress = { (e) => this.changeTheme(false) }>
<Text style={styles2.button1}>Apply Light</Text>
</TouchableOpacity>
<TouchableOpacity onPress = { (e) => this.changeTheme(true) }>
<Text style={styles2.button1}>Apply Dark</Text>
</TouchableOpacity>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
})
const styles2 = RkStyleSheet.create(theme => ({
button1 : {
color : theme.colors.secondaryColor
}
}))