某些样式未应用react-native

时间:2019-01-23 17:16:21

标签: react-native

viewStyle无法应用。我究竟做错了什么? 我正在上一门课程,我一行一行地写,但是我的只是被应用了textStyle。

我会为任何想法表示感谢

const Header = (props) => {

    const { viewStyle, textStyle } = styles;
    return (
        <View style={viewStyle}>
            <Text style={textStyle}>{props.headerText}</Text>
        </View>
    );
};
const styles = {
    viewStyle: {
        backgroundColor: '#F8F8F8',
        justifyContent: 'center',
        alignItems: 'center',
        height: 60,
        paddingTop: 15,
        shadowColor: '#000',
        shadowOffset: { width: 0, height: 2 },
        shadowOpacity: 0.2,
        elevation: 0.2,
        position: 'relative'    
    },
    textStyle: {
        fontSize: 20
    }

}
export default Header;

1 个答案:

答案 0 :(得分:0)

  import {StyleSheet,View,Text} from 'react-native'; 





  const Header = (props) => {
        return (
            <View style={styles.viewStyle}>
                <Text style={styles.textStyle}>{props.headerText}</Text>
            </View>
        );
    };


  const styles = StyleSheet.create({
        viewStyle: {
            backgroundColor: '#F8F8F8',
            justifyContent: 'center',
            alignItems: 'center',
            height: 60,
            paddingTop: 15,
            shadowColor: '#000',
            shadowOffset: { width: 0, height: 2 },
            shadowOpacity: 0.2,
            elevation: 0.2,
            position: 'relative'    
        },
        textStyle: {
            fontSize: 20
        }
    })
相关问题