This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 55).
HorizontalFloatingToolbar
一个用于显示浮动操作栏的 Jetpack Compose HorizontalFloatingToolbar 组件。
For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.
Expo UI HorizontalFloatingToolbar 封装了官方 Jetpack Compose HorizontalFloatingToolbar,并显示一个悬浮在内容上方的水平工具栏,其中包含操作按钮。
注意: 如果你只需要一个单独的悬浮按钮,请改用
FloatingActionButton。
安装
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
可滚动内容上方的悬浮工具栏
将工具栏放在带有 floatingToolbarExitAlwaysScrollBehavior 的 Box 中,以获得随滚动隐藏/显示的行为。使用 align('bottomCenter') 将工具栏定位在屏幕底部。整个布局都保留在 Compose 层中——不需要 React Native 的绝对定位。
import { Box, HorizontalFloatingToolbar, Host, Icon, IconButton, LazyColumn, ListItem, } from '@expo/ui/jetpack-compose'; import { align, fillMaxSize, fillMaxWidth, offset } from '@expo/ui/jetpack-compose/modifiers'; export default function FloatingToolbarExample() { return ( <Host style={{ flex: 1 }}> <Box modifiers={[fillMaxSize()]} floatingToolbarExitAlwaysScrollBehavior="bottom"> <LazyColumn modifiers={[fillMaxSize()]}>{/* ...列表项... */}</LazyColumn> <HorizontalFloatingToolbar variant="vibrant" modifiers={[align('bottomCenter'), offset(0, -16)]}> <IconButton onClick={() => console.log('Edit pressed')}> <Icon source={require('./assets/edit.xml')} /> </IconButton> <HorizontalFloatingToolbar.FloatingActionButton onClick={() => console.log('Add pressed')}> <Icon source={require('./assets/add.xml')} /> </HorizontalFloatingToolbar.FloatingActionButton> </HorizontalFloatingToolbar> </Box> </Host> ); }
带有 FloatingActionButton 的工具栏
将 IconButton 作为工具栏项目的直接子元素,并将 HorizontalFloatingToolbar.FloatingActionButton 用作主要操作。
import { Host, HorizontalFloatingToolbar, IconButton, Icon } from '@expo/ui/jetpack-compose'; export default function ToolbarWithFABExample() { return ( <Host matchContents> <HorizontalFloatingToolbar> <IconButton onClick={() => console.log('Edit pressed')}> <Icon source={require('./assets/edit.xml')} contentDescription="编辑" /> </IconButton> <IconButton onClick={() => console.log('Share pressed')}> <Icon source={require('./assets/share.xml')} contentDescription="分享" /> </IconButton> <HorizontalFloatingToolbar.FloatingActionButton onPress={() => console.log('Add pressed')}> <Icon source={require('./assets/add.xml')} contentDescription="添加" /> </HorizontalFloatingToolbar.FloatingActionButton> </HorizontalFloatingToolbar> </Host> ); }
API
import { HorizontalFloatingToolbar } from '@expo/ui/jetpack-compose';
Components
Type: React.Element<HorizontalFloatingToolbarProps>
Renders a HorizontalFloatingToolbar component.
A horizontal toolbar that floats above content, typically used for action buttons.
Type: React.Element<HorizontalFloatingToolbarFloatingActionButtonProps>
FloatingActionButton component for HorizontalFloatingToolbar. This component marks its children to be rendered in the FAB slot.