Merge pull request #5985 from BlueWallet/addressinput

REF: AddressInput to TSX
This commit is contained in:
GLaDOS 2024-01-07 15:28:14 +00:00 committed by GitHub
commit 29596c58dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 47 deletions

View File

@ -322,8 +322,8 @@ const AztecoRedeemRoot = () => {
const ScanQRCodeStack = createNativeStackNavigator();
const ScanQRCodeRoot = () => (
<ScanQRCodeStack.Navigator screenOptions={{ headerShown: false, presentation: 'fullScreenModal' }}>
<ScanQRCodeStack.Screen name="ScanQRCode" component={ScanQRCode} />
<ScanQRCodeStack.Navigator initialRouteName='ScanQRCode' name="ScanQRCodeRoot" screenOptions={{ headerShown: false, presentation: 'fullScreenModal' }}>
<ScanQRCodeStack.Screen name="ScanQRCode" component={ScanQRCode} initialParams={ScanQRCode.initialParams} />
</ScanQRCodeStack.Navigator>
);

View File

@ -1,15 +1,36 @@
import React, { useRef } from 'react';
import PropTypes from 'prop-types';
import { Text } from 'react-native-elements';
import { findNodeHandle, Image, Keyboard, StyleSheet, TextInput, TouchableOpacity, View } from 'react-native';
import { getSystemName } from 'react-native-device-info';
import React from 'react';
import { Image, Keyboard, Text, StyleSheet, TextInput, TouchableOpacity, View } from 'react-native';
import loc from '../loc';
import * as NavigationService from '../NavigationService';
import { requestCameraAuthorization } from '../helpers/scan-qr';
import { scanQrHelper } from '../helpers/scan-qr';
import { useTheme } from './themes';
const fs = require('../blue_modules/fs');
import { useNavigation } from '@react-navigation/native';
const isDesktop = getSystemName() === 'Mac OS X';
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,
@ -17,17 +38,15 @@ const AddressInput = ({
placeholder = loc.send.details_address,
onChangeText,
onBarScanned,
onBarScannerDismissWithoutData = () => {},
scanButtonTapped = () => {},
launchedBy,
editable = true,
inputAccessoryViewID,
onBlur = () => {},
keyboardType = 'default',
}) => {
}: AddressInputProps) => {
const { colors } = useTheme();
const scanButtonRef = useRef();
const {navigate} = useNavigation()
const stylesHook = StyleSheet.create({
root: {
borderColor: colors.formBorder,
@ -72,21 +91,8 @@ const AddressInput = ({
onPress={async () => {
await scanButtonTapped();
Keyboard.dismiss();
if (isDesktop) {
fs.showActionSheet({ anchor: findNodeHandle(scanButtonRef.current) }).then(onBarScanned);
} else {
requestCameraAuthorization().then(() => {
NavigationService.navigate('ScanQRCodeRoot', {
screen: 'ScanQRCode',
params: {
launchedBy,
onBarScanned,
onBarScannerDismissWithoutData,
showFileImportButton: true
},
});
});
}
// @ts-ignore: Fix later
scanQrHelper(navigate, launchedBy, false).then(onBarScanned);
}}
accessibilityRole="button"
style={[styles.scan, stylesHook.scan]}
@ -136,19 +142,4 @@ const styles = StyleSheet.create({
},
});
AddressInput.propTypes = {
isLoading: PropTypes.bool,
onChangeText: PropTypes.func,
onBarScanned: PropTypes.func.isRequired,
launchedBy: PropTypes.string,
address: PropTypes.string,
placeholder: PropTypes.string,
editable: PropTypes.bool,
scanButtonTapped: PropTypes.func,
inputAccessoryViewID: PropTypes.string,
onBarScannerDismissWithoutData: PropTypes.func,
onBlur: PropTypes.func,
keyboardType: PropTypes.string,
};
export default AddressInput;

View File

@ -86,7 +86,7 @@ const ScanQRCode = () => {
const [isLoading, setIsLoading] = useState(false);
const navigation = useNavigation();
const route = useRoute();
const { launchedBy, onBarScanned, onDismiss, showFileImportButton, onBarScannerDismissWithoutData = () => {} } = route.params;
const { launchedBy, onBarScanned, onDismiss, showFileImportButton } = route.params;
const scannedCache = {};
const { colors } = useTheme();
const isFocused = useIsFocused();
@ -302,7 +302,6 @@ const ScanQRCode = () => {
};
const dismiss = () => {
onBarScannerDismissWithoutData();
if (launchedBy) {
navigation.navigate({ name: launchedBy, params: {}, merge: true });
} else {