android - 如何在 react-native 中添加破折号或虚线边框?

标签 android ios reactjs react-native

我想在一侧添加虚线边框,

{
  height: '100%',
  width: 20,
  position: 'absolute',
  borderRadius : 1,
  borderStyle: 'dashed',
  borderRightWidth: 1,
  borderRightColor: 'rgba(161,155,183,1)'
}

这不起作用,但是当我将其更改为

{
  height: '100%',
  width: 20,
  position: 'absolute',
  borderRadius : 1,
  borderStyle: 'dashed',
  borderWidth: 1,
  borderColor: 'rgba(161,155,183,1)'
}

有效,但边界在 4 边。 如何仅在一侧添加 bashed 边框? 还有没有办法在破折号上增加更多的间距? "react-native": "0.57.7"

最佳答案

https://github.com/facebook/react-native/issues/7838

根据查看代码,这看起来像是一个有意的限制。如果尝试使用虚线或点线边框,则有专门检查颜色和宽度是否在所有边上都相同的代码。我敢猜测,如果您将 borderWidth 设置为 1 而不是 borderBottomWidth,那么警告将会消失并且您的边框将会显示。

你可以通过使用这种掩码来实现:

const inputStyles = 
StyleSheet.create({
container: {
height: 20,
marginRight: 25,
marginLeft: 25,
paddingTop: 25,
paddingBottom: 25,
borderStyle: 'dotted',
borderWidth: 2,
borderColor: '#b7c2c6',
position: 'relative',
overflow: 'hidden',
},
topMask: {
height: 3,
width: 9999,
backgroundColor: 'white',
position: 'absolute',
top: -3,
left: 0,
},
rightMask: {
height: 9999,
width: 3,
backgroundColor: 'white',
position: 'absolute',
top: 0,
right: -3,
},
leftMask: {
height: 9999,
width: 3,
backgroundColor: 'white',
position: 'absolute',
top: 0,
left: -3,
},
});

这个问题还没有解决:https://github.com/facebook/react-native/issues/17251

您可以将 borderRadius 设置为 1 或 0.5 以获得虚线边框。

关于android - 如何在 react-native 中添加破折号或虚线边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54694110/

相关文章:

java - 如何使Web View (Intent.ACTION_VIEW)变大?

objective-c - 在不使用 reloadData 的情况下动态更新 UITableView 的部分

ios - 自定义 slider 响应缓慢

reactjs - 如何在 Android 和 iOS 上的 Capacitor 应用中实现 Firebase 身份验证?

javascript - 如何在 ReactJs 中使用组合

android - 如何以编程方式读取 Android 中的 wifi 密码

android - 尝试播放音频时,我的mediaplayer类出现运行时错误(Android/Eclipse)

android - 更改签名 key ,保留包名

ios - NSXMLParser 预期结果一遍又一遍地重复并一次添加 1 个项目

javascript - 使用 Reflux,资源是 2 家商店还是 1 家商店? (自行车/CurrentBike 与自行车)