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

React Native中styled.View不识别props,Flex组件方向未按预期生效

问题原因及解决方法

你的Flex组件没有将接收到的direction属性传递给内部的StyledFlex组件,导致StyledFlex始终使用默认的row作为flex-direction的值,所以布局还是横向排列。

修正代码

修改flex.js中的Flex组件,把props传递给StyledFlex:

const Flex = (props) => {
  return <StyledFlex {...props}>{props.children}</StyledFlex>
}

或者也可以明确传递direction属性:

const Flex = (props) => {
  return <StyledFlex direction={props.direction}>{props.children}</StyledFlex>
}

这样修改后,当你传入direction="column"时,StyledFlex就能正确获取到这个参数,将flex-direction设置为column,实现纵向布局。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 22:55:48