react-native#TextInputSubmitEditingEventData TypeScript Examples
The following examples show how to use
react-native#TextInputSubmitEditingEventData.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FieldSearchBarFull.tsx From react-native-jigsaw with MIT License | 4 votes |
FieldSearchBarFull: React.FC<Props> = ({
showIcon,
Icon,
icon = "search",
placeholder = "",
style,
theme: { colors, typography },
onChange: changeOverride,
onSubmit: submitOverride,
value,
defaultValue,
}) => {
const [focused, setIsFocused] = React.useState(false);
const onBlur = () => {
setIsFocused(false);
};
const [internalValue, setInternalValue] = React.useState<string | undefined>(
value || defaultValue
);
React.useEffect(() => {
if (value != null) {
setInternalValue(value);
}
}, [value]);
React.useEffect(() => {
if (defaultValue != null) {
setInternalValue(defaultValue);
}
}, [defaultValue]);
const onChange = React.useCallback(
(text: string) => {
changeOverride && changeOverride(text);
},
[changeOverride]
);
const onFocus = () => {
setIsFocused(true);
};
const onSubmit = (
e: NativeSyntheticEvent<TextInputSubmitEditingEventData>
) => {
submitOverride && submitOverride(e);
};
const { lineHeight, ...typeStyles } = typography.body2; // eslint-disable-line @typescript-eslint/no-unused-vars
const handleChangeText = (newValue: string) => {
setInternalValue(newValue);
if (onChange) {
onChange(newValue);
}
};
return (
<View style={[styles.container, style]}>
{showIcon && (
<Icon
name={icon}
size={Config.fieldSearchBarFullIconSize}
color={focused ? colors.primary : colors.light}
/>
)}
<View style={{ marginLeft: showIcon ? 12 : 0, flex: 1 }}>
<TextInput
clearButtonMode="while-editing"
placeholder={placeholder}
value={internalValue}
onBlur={onBlur}
onFocus={onFocus}
onChangeText={handleChangeText}
onSubmitEditing={onSubmit}
placeholderTextColor={colors.light}
style={[
{
color: colors.medium,
},
typeStyles,
]}
/>
</View>
</View>
);
}
Example #2
Source File: index.tsx From hive-keychain-mobile with MIT License | 4 votes |
UrlModal = ({
isVisible,
toggle,
onNewSearch,
url,
setUrl,
history,
clearHistory,
}: Props) => {
const urlInput: MutableRefObject<TextInput> = useRef();
const insets = useSafeAreaInsets();
const styles = getStyles(insets);
if (isVisible && urlInput) {
setTimeout(() => {
const {current} = urlInput;
if (current && !current.isFocused()) {
current.focus();
}
}, SLIDE_TIME);
}
const onSubmitUrlFromInput = (
obj: NativeSyntheticEvent<TextInputSubmitEditingEventData>,
) => {
const url = obj.nativeEvent.text;
onSubmitUrl(url);
};
const onSubmitUrl = (url: string) => {
toggle(false);
// Add duckduck go search for url with no domain
if (url.includes(' ') || !url.includes('.')) {
onNewSearch(`https://duckduckgo.com/?q=${url.replace(/ /g, '+')}`);
} else {
const hasProtocol = url.match(/^[a-z]*:\/\//);
const sanitizedURL = hasProtocol ? url : `https://${url}`;
onNewSearch(sanitizedURL);
}
};
const dismissModal = () => {
toggle(false);
};
return (
<Modal
isVisible={isVisible}
style={styles.urlModal}
onBackdropPress={dismissModal}
onBackButtonPress={dismissModal}
animationIn="slideInDown"
animationOut="slideOutUp"
backdropOpacity={0.8}
animationInTiming={SLIDE_TIME}
animationOutTiming={SLIDE_TIME}
useNativeDriver>
<View style={styles.urlModalContent}>
<TextInput
keyboardType="web-search"
ref={urlInput}
autoCapitalize="none"
autoCorrect={false}
clearButtonMode="never"
onChangeText={setUrl}
onSubmitEditing={onSubmitUrlFromInput}
placeholder={translate('browser.search')}
returnKeyType="go"
style={styles.urlInput}
value={url}
selectTextOnFocus
/>
{url.length ? (
<TouchableOpacity
style={styles.option}
onPress={() => Share.share({message: url})}>
<ShareIcon width={16} height={16} />
</TouchableOpacity>
) : null}
{url.length ? (
<TouchableOpacity
style={styles.option}
onPress={() => Clipboard.setString(url)}>
<Copy width={16} height={16} />
</TouchableOpacity>
) : null}
{url.length ? (
<TouchableOpacity style={styles.option} onPress={() => setUrl('')}>
<Text style={styles.eraseText}>X</Text>
</TouchableOpacity>
) : null}
</View>
<ScrollView>
<UrlAutocomplete onSubmit={onSubmitUrl} input={url} history={history} />
{history.length ? (
<TouchableOpacity onPress={clearHistory}>
<Text style={styles.clearHistory}>
{translate('browser.history.clear')}
</Text>
</TouchableOpacity>
) : null}
</ScrollView>
</Modal>
);
}