【问题标题】:Is there alternative to use outline:"none" property in react native?是否可以在本机反应中使用大纲:“无”属性?
【发布时间】:2021-07-01 12:26:30
【问题描述】:

实际上,我已将样式 {{ width: "100%", outline: "none", height: 50 }} 传递给子组件,我在终端中收到了一个警告,即轮廓不是有效属性. 如果在样式表中声明了此样式,则应用程序因错误而崩溃,因此必须将其声明为内联。 我找不到删除警告的方法,因为 react native 不支持 outline : "none" 属性,还有其他替代方法吗?

【问题讨论】:

  • 请重新考虑删除大纲?或者至少将其替换为出现在悬停和焦点上的边框。
  • 实际上我已经创建了一个带有图标和 TextInput flexDirection: "row" 的文本字段,所以当我点击图标时,文本字段被聚焦,现在因为我使用的是 monorepo 架构,所以我使用的是 react native web,在 web 部件中,当 textfield 聚焦时,它会在 textfield 中添加一个轮廓,这看起来很奇怪,这就是为什么我使用了 outline:"none",它可以工作并删除 web 部件中的轮廓,但在 android 中会出错。

标签: javascript reactjs react-native monorepo react-native-web


【解决方案1】:

您可以使用 react native web 中的 Platform API 仅在您的应用在 web 上运行时添加 outline 样式。

类似:

StyleSheet.create({
  textEditStyle: {
    Platform.select({
      web: {
        outline: 'none'
      }
    }),
    ... // Other styles go here
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-31
    • 2023-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多