以下是:
<Text style={{color: 'blue', fontSize: 30}} />
Run Code Online (Sandbox Code Playgroud)
与以下相比,有任何性能影响:
<Text style={styles.blueButton} />
...
const styles = StyleSheet.create({
blueButton: {
color: 'blue',
fontSize: 30,
}
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试将react-native-elements 与我的React-Native 应用程序一起使用。
\n我有一个包含主题详细信息的中央 js 文件,这些文件是使用 ThemeProvider 注入的,如此处所述 - https://react-native-elements.github.io/react-native-elements/docs/customization.html
\n但是,当我尝试在组件的 stylesheet.create 方法中使用传递的主题时,出现错误。我究竟做错了什么?-
\nimport React from \'react\';\nimport {View, StyleSheet} from \'react-native\';\nimport {Text, withTheme} from \'react-native-elements\';\n\nconst Header = props => {\n const {theme} = props;\n\n return (\n <View style={styles.container}>\n <Text>Home</Text>\n </View>\n );\n};\nconst styles = StyleSheet.create({\n container: {\n width: \'100%\',\n backgroundColor: theme.container.backgroundColor,//**** Getting error here stating that theme is not defined\n shadowRadius: 1.5,\n elevation: 2,\n shadowColor: \'rgb(0,0,0)\',\n shadowOpacity: 0.4,\n shadowOffset: {width: 0, height: 2.5},\n },\n});\n\nexport default withTheme(Header);\nRun Code Online (Sandbox Code Playgroud)\n如果我可以提供更多详细信息,请告诉我。 …
我正在尝试将宽度参数传递到样式表中,如下所示:
<View style={styles.children(width)}>{children}</View>
Run Code Online (Sandbox Code Playgroud)
并像这样使用它:
const styles = StyleSheet.create({
modalContent: {
flex: 1,
justifyContent: 'center',
margin: '5%',
},
modalOverlay: {
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
backgroundColor: 'rgba(0,0,0,0.5)',
},
children: (width: any) => ({
width: width,
backgroundColor: 'white',
position: 'absolute',
bottom: 0,
borderTopRightRadius: 40,
borderTopLeftRadius: 40,
paddingVertical: 30,
paddingHorizontal: 20,
}),
});
,
Run Code Online (Sandbox Code Playgroud)
但是打字稿抛出错误This expression is not callable. No constituent of type 'ViewStyle | TextStyle | ImageStyle' is callable.
我该如何解决这个打字稿问题?
javascript typescript reactjs react-native react-native-stylesheet