一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
68 行
1.9 KiB
TypeScript
68 行
1.9 KiB
TypeScript
import * as React from 'react';
|
|
import { _ } from '@joplin/lib/locale';
|
|
import { StyleSheet } from 'react-native';
|
|
import { themeStyle } from '../../global-style';
|
|
import { useMemo, useState } from 'react';
|
|
import { Searchbar } from 'react-native-paper';
|
|
|
|
interface Props {
|
|
themeId: number;
|
|
value: string;
|
|
autoFocus: boolean;
|
|
placeholder?: string;
|
|
onChangeText: (text: string)=> void;
|
|
onClearButtonPress: ()=> void;
|
|
onSubmitEditing?: ()=> void;
|
|
}
|
|
|
|
const useStyles = (themeId: number) => {
|
|
return useMemo(() => {
|
|
const theme = themeStyle(themeId);
|
|
return StyleSheet.create({
|
|
searchContainer: {
|
|
borderWidth: 2,
|
|
borderColor: theme.dividerColor,
|
|
backgroundColor: theme.backgroundColor,
|
|
margin: theme.margin,
|
|
borderRadius: theme.borderRadius,
|
|
},
|
|
searchTextInput: {
|
|
color: theme.color,
|
|
fontSize: theme.fontSize,
|
|
},
|
|
});
|
|
}, [themeId]);
|
|
};
|
|
|
|
const SearchBar: React.FC<Props> = ({ themeId, value, autoFocus, placeholder, onChangeText, onClearButtonPress, onSubmitEditing }) => {
|
|
const [isFocused, setIsFocused] = useState(false);
|
|
const theme = themeStyle(themeId);
|
|
const styles = useStyles(themeId);
|
|
|
|
return (
|
|
<Searchbar
|
|
style={[styles.searchContainer, isFocused && { borderColor: theme.color4 }]}
|
|
inputStyle={styles.searchTextInput}
|
|
autoFocus={autoFocus}
|
|
autoCapitalize='none'
|
|
autoComplete='off'
|
|
autoCorrect={false}
|
|
clearAccessibilityLabel={_('Clear')}
|
|
clearIcon='close'
|
|
iconColor={theme.colorFaded}
|
|
onBlur={() => setIsFocused(false)}
|
|
onChangeText={onChangeText}
|
|
onClearIconPress={onClearButtonPress}
|
|
onFocus={() => setIsFocused(true)}
|
|
onSubmitEditing={onSubmitEditing}
|
|
placeholder={placeholder ?? _('Search')}
|
|
placeholderTextColor={theme.colorFaded}
|
|
value={value}
|
|
selectionColor={theme.textSelectionColor}
|
|
keyboardAppearance={theme.keyboardAppearance}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default SearchBar;
|