Tối giản
Căn trái, không nút Cancel, không animation.
Cách hoạt động
Phần tiêu đề “Cách hoạt động”showCancelButton={false}giữ ô nhập rộng hết cỡ.placeholderAlign="left"đặt icon và placeholder sát mép đầu.animated={false}tắt animation.
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 { StyleSheet, Text, View } from 'react-native';import Search from 'react-native-search-box';
export default function Minimal() { const [query, setQuery] = useState('');
return ( <View style={styles.screen}> <Text style={styles.title}>Notes</Text> <Search showCancelButton={false} placeholderAlign="left" animated={false} backgroundColor="transparent" placeholder="Search notes" inputHeight={40} inputStyle={styles.input} searchIconExpandedMargin={18} placeholderExpandedMargin={34} onChangeText={setQuery} onDelete={() => setQuery('')} /> <Text style={styles.text}>{query ? `Notes about “${query}”` : 'All notes'}</Text> </View> );}
const styles = StyleSheet.create({ screen: { flex: 1, backgroundColor: '#fff', padding: 16 }, title: { fontSize: 28, fontWeight: '700', color: '#111', marginBottom: 8, marginLeft: 5 }, input: { fontSize: 16, color: '#111', backgroundColor: '#fff', borderWidth: 1, borderColor: '#d1d5db', borderRadius: 8, }, text: { marginTop: 16, marginLeft: 5, color: '#6b7280' },});