首页 > 解决方案 > 反应原生样式表对象不是对象

问题描述

在 React Native 中,特别是在这个Card组件中,我想以组件的样式传播两个对象<View>,第一个对象是卡片,StyleSheet第二个对象props.styleStyleSheet来自另一个组件,但是它不起作用,当我尝试console.log(styles.card)它输出数字 19 并console.log(props.style)输出数字 22

import React from "react";
import { View, StyleSheet } from "react-native";

const Card = (props) => {
  console.log(styles.card) // This line output 19
  console.log(props.style) // This line output 22
  return (
    <View style={{ ...styles.card, ...props.style }}>{props.children}</View>
  );
};

const styles = StyleSheet.create({
  card: {
    shadowColor: "black",
    shadowOffset: { width: 0, height: 2 },
    shadowRadius: 6,
    shadowOpacity: 0.26,
    //elevation: 5,  shadow for android
    backgroundColor: "white",
    padding: 20,
    borderRadius: 10,
  },
});

export default Card;

标签: react-nativereact-native-stylesheet

解决方案


推荐阅读