This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 55).
DockedSearchBar
一个用于显示内联搜索输入的 Jetpack Compose DockedSearchBar 组件。
Android
For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.
Expo UI DockedSearchBar 与官方的 Jetpack Compose SearchBar API 保持一致,并显示一个搜索输入框,该输入框会保持锚定在其父布局中,而不会展开为全屏。
安装
Terminal
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基础停靠式搜索栏
BasicDockedSearchBarExample.tsx
import { useState } from 'react'; import { Host, DockedSearchBar } from '@expo/ui/jetpack-compose'; export default function BasicDockedSearchBarExample() { const [query, setQuery] = useState(''); return ( <Host matchContents> <DockedSearchBar onQueryChange={setQuery} /> </Host> ); }
带有占位符和前导图标
使用 DockedSearchBar.Placeholder 和 DockedSearchBar.LeadingIcon 插槽组件来自定义搜索栏外观。
DockedSearchBarWithSlotsExample.tsx
import { useState } from 'react'; import { Host, DockedSearchBar, Text } from '@expo/ui/jetpack-compose'; export default function DockedSearchBarWithSlotsExample() { const [query, setQuery] = useState(''); return ( <Host matchContents> <DockedSearchBar onQueryChange={setQuery}> <DockedSearchBar.Placeholder> <Text>搜索项目...</Text> </DockedSearchBar.Placeholder> <DockedSearchBar.LeadingIcon> <Text>🔍</Text> </DockedSearchBar.LeadingIcon> </DockedSearchBar> </Host> ); }
API
import { DockedSearchBar } from '@expo/ui/jetpack-compose';
Components
Type: React.Element<DockedSearchBarProps>
Type: React.Element<LeadingIconProps>
Type: React.Element<PlaceholderProps>