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

React Native运行代码报错:更新RCTView的marginRight属性出现未知值10,模拟器闪退

问题原因
  • React Native 布局属性中,间距类属性(margin、padding 等)仅支持两种合法值格式:
    1. 不带引号的数值,默认单位为 dp
    2. 带单位的字符串,比如 '10%'、'10px',或者特殊值 'auto'
  • 你代码中 rightContainer 样式的 marginRight 赋值为 '10',属于纯数字字符串,不属于上述合法格式,RN 底层渲染 ShadowNode 时无法识别该值,直接触发崩溃。
解决方法

修改 styles 中 rightContainer 的 marginRight 属性,去掉引号改为数值类型即可:

const styles = StyleSheet.create({
    container: {
        backgroundColor: '#4D5F75',
        padding: 10,
        margin: 10,
        borderRadius: 15,
        maxWidth: '75%'
    },
    leftContainer: {
        backgroundColor: '#4D5F75',
        marginLeft: 10,
        marginRight: 'auto'

    },
    rightContainer: {
        backgroundColor: '#BFC3CA',
        marginLeft: 'auto',
        marginRight: 10 // 去掉引号,改为数值类型
    }
});

修改后重新运行项目即可恢复正常。

内容的提问来源于stack exchange,提问作者Ankit Mohapatra

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 15:06:05