You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Expo安卓端设置borderWidth为transparent崩溃问题求助

问题解决:Pressable组件设置borderWidth为"transparent"导致安卓崩溃
  • 问题根源:borderWidth样式属性要求传入数值类型(比如0、0.7这类),而"transparent"是borderColor的合法值,你错误地把透明逻辑用在了borderWidth上,这在安卓端会触发类型不匹配错误导致崩溃,iOS可能有容错处理所以未出现问题。

  • 修复方案:把透明逻辑移到borderColor属性,同时保持borderWidth为数值类型。调整后的样式代码如下:

borderWidth: 0.7,
borderColor: lookingOptions.includes(item?.name) ? "transparent" : "#你的常规边框颜色",

如果需要在选中时完全隐藏边框,也可以直接设置borderWidth为0:

borderWidth: lookingOptions.includes(item?.name) ? 0 : 0.7,
borderColor: "#你的常规边框颜色",
  • 关于Bug的疑问:这不是React Native或Expo的Bug,属于样式属性的类型使用错误。所有宽度类样式属性(如width、height、borderWidth)都要求传入数值,颜色相关属性才接受颜色值(包括transparent)。

内容的提问来源于stack exchange,提问作者Rahul Kathayat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 20:57:01