Giao diện riêng
Nền tối, icon riêng và viền sáng.
Cách hoạt động
Phần tiêu đề “Cách hoạt động”iconSearchvàiconDeletenhận bất kỳ element nào.- Chỗ cho nút Cancel được đo theo chữ, ở đây là “Never mind”.
- Các prop shadow đổi giữa lúc thu và lúc mở, tạo hiệu ứng sáng.
Dùng
Toàn bộ source
Phần tiêu đề “Toàn bộ source”Đây chính là đoạn code đang chạy trong điện thoại. Chép vào app của bạn là dùng được.
import { useState } from 'react';import { ScrollView, StyleSheet, Text, View } from 'react-native';import Search from 'react-native-search-box';
const COVERS = ['#3f6212', '#1e3a8a', '#701a75', '#7c2d12'];const TRACKS = [ { title: 'Night drive', artist: 'Lumen' }, { title: 'Paper moons', artist: 'Ode & Co' }, { title: 'Slow tide', artist: 'Marea' }, { title: 'Static bloom', artist: 'Lumen' }, { title: 'Copper sky', artist: 'Vale' }, { title: 'Undertow', artist: 'Marea' },];
export default function Themed() { const [query, setQuery] = useState(''); const reset = () => setQuery(''); const tracks = TRACKS.filter((track) => `${track.title} ${track.artist}`.toLowerCase().includes(query.toLowerCase()), );
return ( <View style={styles.screen}> <Search backgroundColor="#121212" placeholder="Songs" placeholderTextColor="#a3a3a3" selectionColor="#a3e635" keyboardAppearance="dark" titleCancelColor="#a3e635" cancelTitle="Never mind" cancelButtonTextStyle={styles.cancel} inputStyle={styles.input} inputHeight={44} inputBorderRadius={22} iconSearch={<Text style={styles.icon}>♪</Text>} iconDelete={<Text style={styles.icon}>✕</Text>} searchIconExpandedMargin={22} placeholderExpandedMargin={40} shadowVisible shadowColor="#a3e635" shadowOpacityExpanded={0.5} shadowRadius={10} shadowOffsetHeightExpanded={0} shadowOffsetHeightCollapsed={0} onChangeText={setQuery} onDelete={reset} onCancel={reset} /> <ScrollView contentContainerStyle={styles.list} keyboardShouldPersistTaps="handled"> {tracks.map(({ title, artist }, i) => ( <View key={title} style={styles.row}> <View style={[styles.cover, { backgroundColor: COVERS[i % COVERS.length] }]} /> <View> <Text style={styles.title}>{title}</Text> <Text style={styles.artist}>{artist}</Text> </View> </View> ))} {tracks.length === 0 && <Text style={styles.artist}>Nothing by that name.</Text>} </ScrollView> </View> );}
const styles = StyleSheet.create({ screen: { flex: 1, backgroundColor: '#121212' }, input: { fontSize: 16, backgroundColor: '#262626', color: '#fafafa' }, cancel: { fontSize: 15, fontWeight: '600' }, icon: { width: 14, height: 14, lineHeight: 14, fontSize: 14, textAlign: 'center', color: '#a3e635' }, list: { padding: 16, gap: 14 }, row: { flexDirection: 'row', alignItems: 'center', gap: 12 }, cover: { width: 52, height: 52, borderRadius: 8 }, title: { fontSize: 16, fontWeight: '600', color: '#fafafa' }, artist: { marginTop: 2, color: '#a3a3a3' },});