mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 09:50:15 +01:00
147 lines
3.6 KiB
TypeScript
147 lines
3.6 KiB
TypeScript
import { useNavigation } from '@react-navigation/native';
|
|
import React from 'react';
|
|
import { Image, Keyboard, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
|
|
|
|
import { scanQrHelper } from '../helpers/scan-qr';
|
|
import loc from '../loc';
|
|
import { useTheme } from './themes';
|
|
|
|
interface AddressInputProps {
|
|
isLoading?: boolean;
|
|
address?: string;
|
|
placeholder?: string;
|
|
onChangeText: (text: string) => void;
|
|
onBarScanned: (ret: { data?: any }) => void;
|
|
scanButtonTapped?: () => void;
|
|
launchedBy?: string;
|
|
editable?: boolean;
|
|
inputAccessoryViewID?: string;
|
|
onBlur?: () => void;
|
|
keyboardType?:
|
|
| 'default'
|
|
| 'numeric'
|
|
| 'email-address'
|
|
| 'ascii-capable'
|
|
| 'numbers-and-punctuation'
|
|
| 'url'
|
|
| 'number-pad'
|
|
| 'phone-pad'
|
|
| 'name-phone-pad'
|
|
| 'decimal-pad'
|
|
| 'twitter'
|
|
| 'web-search'
|
|
| 'visible-password';
|
|
}
|
|
|
|
const AddressInput = ({
|
|
isLoading = false,
|
|
address = '',
|
|
placeholder = loc.send.details_address,
|
|
onChangeText,
|
|
onBarScanned,
|
|
scanButtonTapped = () => {},
|
|
launchedBy,
|
|
editable = true,
|
|
inputAccessoryViewID,
|
|
onBlur = () => {},
|
|
keyboardType = 'default',
|
|
}: AddressInputProps) => {
|
|
const { colors } = useTheme();
|
|
const { navigate } = useNavigation();
|
|
const stylesHook = StyleSheet.create({
|
|
root: {
|
|
borderColor: colors.formBorder,
|
|
borderBottomColor: colors.formBorder,
|
|
backgroundColor: colors.inputBackgroundColor,
|
|
},
|
|
scan: {
|
|
backgroundColor: colors.scanLabel,
|
|
},
|
|
scanText: {
|
|
color: colors.inverseForegroundColor,
|
|
},
|
|
});
|
|
|
|
const onBlurEditing = () => {
|
|
onBlur();
|
|
Keyboard.dismiss();
|
|
};
|
|
|
|
return (
|
|
<View style={[styles.root, stylesHook.root]}>
|
|
<TextInput
|
|
testID="AddressInput"
|
|
onChangeText={onChangeText}
|
|
placeholder={placeholder}
|
|
placeholderTextColor="#81868e"
|
|
value={address}
|
|
style={styles.input}
|
|
editable={!isLoading && editable}
|
|
multiline={!editable}
|
|
inputAccessoryViewID={inputAccessoryViewID}
|
|
clearButtonMode="while-editing"
|
|
onBlur={onBlurEditing}
|
|
autoCapitalize="none"
|
|
autoCorrect={false}
|
|
keyboardType={keyboardType}
|
|
/>
|
|
{editable ? (
|
|
<TouchableOpacity
|
|
testID="BlueAddressInputScanQrButton"
|
|
disabled={isLoading}
|
|
onPress={async () => {
|
|
await scanButtonTapped();
|
|
Keyboard.dismiss();
|
|
// @ts-ignore: Fix later
|
|
scanQrHelper(navigate, launchedBy).then(onBarScanned);
|
|
}}
|
|
accessibilityRole="button"
|
|
style={[styles.scan, stylesHook.scan]}
|
|
accessibilityLabel={loc.send.details_scan}
|
|
accessibilityHint={loc.send.details_scan_hint}
|
|
>
|
|
<Image source={require('../img/scan-white.png')} accessible={false} />
|
|
<Text style={[styles.scanText, stylesHook.scanText]} accessible={false}>
|
|
{loc.send.details_scan}
|
|
</Text>
|
|
</TouchableOpacity>
|
|
) : null}
|
|
</View>
|
|
);
|
|
};
|
|
|
|
const styles = StyleSheet.create({
|
|
root: {
|
|
flexDirection: 'row',
|
|
borderWidth: 1.0,
|
|
borderBottomWidth: 0.5,
|
|
minHeight: 44,
|
|
height: 44,
|
|
marginHorizontal: 20,
|
|
alignItems: 'center',
|
|
marginVertical: 8,
|
|
borderRadius: 4,
|
|
},
|
|
input: {
|
|
flex: 1,
|
|
marginHorizontal: 8,
|
|
minHeight: 33,
|
|
color: '#81868e',
|
|
},
|
|
scan: {
|
|
height: 36,
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
borderRadius: 4,
|
|
paddingVertical: 4,
|
|
paddingHorizontal: 8,
|
|
marginHorizontal: 4,
|
|
},
|
|
scanText: {
|
|
marginLeft: 4,
|
|
},
|
|
});
|
|
|
|
export default AddressInput;
|