【问题标题】:How can you style/theme an element of just one type in react-native-elements?你如何在 react-native-elements 中设置一个元素的样式/主题?
【发布时间】:2021-09-06 15:09:42
【问题描述】:

我正在尝试使用 React Native 和 React Native Elements 作为一组 UI 组件来组合一个简单的手机应用程序模型。我想将各种元素的样式设置为一个共同的主题,所以我按照文档中的示例进行操作:https://reactnativeelements.com/docs/customization#using-themeprovider

但是那里的示例存在问题(正如文档中所说),它设置了 all 按钮的样式。我想做的是只设置实体按钮的背景颜色,例如,留下清除按钮,清除! 谁能指出正确的方向?

当前的 sn-p(为节省空间而修剪):

const myTheme = {
  Button: {
    buttonStyle: {
      borderRadius: 4,
      backgroundColor: '#03E0EE',
    },
    titleStyle: {
      color: '#180D43',
    },
  },
};

...

<ThemeProvider theme={myTheme}>
  <View style={styles.footerContainer}>
    <Button title="Primary Button"/>
    <Button title="Secondary Button" type="clear" />
  </View>
</ThemeProvider>

【问题讨论】:

  • 为 SolidButton 和/或 ClearButton 创建一个包装组件。使这个包装器组件使用带有样式道具的 myTheme 上下文(例如 ButtonSolid\ButtonClear)。 AFAIK 没有像 css 中那样的选择器功能。
  • @MichaelBahl 想要发布以上内容作为答案?这样人们就可以投票等。

标签: react-native react-native-elements


【解决方案1】:

为 SolidButton 和/或 ClearButton 创建一个包装器组件。使这个包装器组件使用带有样式道具的 myTheme 上下文(例如 ButtonSolid\ButtonClear)。 AFAIK 没有像 css 中那样的选择器功能。

【讨论】:

    猜你喜欢
    • 2017-05-30
    • 2020-12-06
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    相关资源
    最近更新 更多