无法使用样式组件将样式应用于 React Native 中的自定义组件?

Mus*_*eed 2 css frontend reactjs react-native styled-components

styled-components在我的 React Native 应用程序中使用它来设计它。样式在其他组件上运行良好,但是当我尝试为自定义创建的组件设置样式时,不会应用任何样式。

在这种情况下,不应用填充。

这是我的代码示例之一:

import React, { Component } from "react";
import { View } from "react-native";
import styled from "styled-components/native";
import { BigTitle } from "./Titles";

class Home extends Component {
  render() {
    return (
      <View>
        <MainTitle title="Hello World!" />
      </View>
    );
  }
}
export default Home;

const MainTitle = styled(BigTitle)`
  padding-top: 45px;
  padding-bottom: 10px;
`;


Run Code Online (Sandbox Code Playgroud)

这是自定义创建的组件:


import React from "react";
import { Text } from "react-native";
import styled from "styled-components/native";

interface TitleProps {
  title: string;
}

export const BigTitle = (props: TitleProps) => {
  return <BigTitleText>{props.title}</BigTitleText>;
};

const BigTitleText = styled(Text)`
  text-align: left;
  font-size: 20px;
  letter-spacing: 1.8px;
  color: ${props => props.theme.textColor};
  font-family: ${props => props.theme.fontFamily};
  text-transform: uppercase;
  opacity: 1;
`;

Run Code Online (Sandbox Code Playgroud)

小智 7

尝试在BigTitle组件中使用style属性:

export const BigTitle = (props: TitleProps) => {
  return <BigTitleText style={props.style}>{props.title}</BigTitleText>;
};
Run Code Online (Sandbox Code Playgroud)