This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo Router Split View
一个 Expo Router 子模块,提供原生分屏布局。
重要 SplitView 是一个 alpha API,仅在 Expo SDK 55 及更高版本的 iOS 上可用。此 API 可能会发生破坏性变更,目前尚未适用于生产环境。
expo-router/unstable-split-view 是 expo-router 的子模块,导出用于构建分栏布局的组件,这些布局使用平台原生系统分栏视图。
有关适用于原生和 Web 应用的基于文件的路由库的更多信息,请参阅 Expo Router 参考文档。
平台支持
Split View 仅适用于 iOS。在其他平台上,SplitView 组件会自动回退为标准 Slot 导航器,确保你的应用无需条件代码即可在所有平台上运行。
iPhone 支持
在 iPhone 上,SplitView 会自动将所有列折叠为单个视图。一次仅显示一列。
选择初始列
使用 topColumnForCollapsing 属性控制分栏视图折叠时显示哪一列:
<SplitView topColumnForCollapsing="primary">{/* ... */}</SplitView>
接受的值为 primary、supplementary 和 secondary。未设置时,系统将使用其默认行为。
在列之间导航
信息
.show()方法要求react-native-screens版本为 4.24.0 或更高。SDK 55 捆绑的是~4.23.0,因此你需要手动安装react-native-screens@~4.24.0才能使用此功能。
使用 ref 和 show 方法以编程方式显示特定列:
import { useRef } from 'react'; import { Pressable, Text } from 'react-native'; import { SplitView } from 'expo-router/unstable-split-view'; import type { SplitHostCommands } from 'react-native-screens/experimental'; export default function Layout() { const ref = useRef<SplitHostCommands>(null); return ( <SplitView ref={ref} topColumnForCollapsing="primary"> <SplitView.Column> <Pressable onPress={() => ref.current?.show('secondary')}> <Text>Show main content</Text> </Pressable> </SplitView.Column> </SplitView> ); }
已知限制
Only specific children allowed
SplitView 仅接受 SplitView.Column 和 SplitView.Inspector 作为直接子项。其他组件将被忽略,并显示警告。
信息 **注意:**我们正在积极开发
SplitView,并期待收到反馈。你可以在 Discord 上分享想法、在 GitHub 上提交问题,或使用本页底部的 反馈 按钮。
安装
若要在项目中使用 expo-router/unstable-split-view,需要在项目中安装 expo-router。请按照 Expo Router 安装指南中的说明操作:
Learn how to install Expo Router in your project.
使用 SplitView.Column
SplitView.Column 用于在分栏布局中定义其他列。在主要内容区域之前最多可以添加两列。
两列布局
包含主要内容的简单侧边栏:
三列布局
包含辅助列和主要内容的侧边栏:
使用 SplitView.Inspector
SplitView.Inspector 会添加一个从尾随边缘滑入的辅助列,适合显示其他详细信息或元数据:
<SplitView> <SplitView.Column>{/* Sidebar */}</SplitView.Column> <SplitView.Inspector> <View style={{ flex: 1, padding: 16 }}> <Text>Inspector Panel</Text> </View> </SplitView.Inspector> </SplitView>
完整示例
下面是一个具有三列的密码管理器风格应用:
app_layout.tsxindex.tsx[type][id].tsxindex.tsxAPI
import { SplitView } from 'expo-router/unstable-split-view';
Components
Type: React.Element<SplitViewProps>
For full list of supported props, see SplitHostProps
Type: React.Element<SplitViewColumnProps>
ReactNodeType: React.Element<SplitViewColumnProps>