ADD: Shortcuts on Scan button long press

This commit is contained in:
marcosrdz 2020-05-23 15:40:16 -04:00
parent 44033b473d
commit c243ea405b
2 changed files with 140 additions and 39 deletions

View File

@ -1,5 +1,17 @@
/* global alert */
import React, { Component } from 'react';
import { View, TouchableOpacity, Text, StyleSheet, InteractionManager, RefreshControl, SectionList, Alert, Platform } from 'react-native';
import {
View,
TouchableOpacity,
Clipboard,
Text,
StyleSheet,
InteractionManager,
RefreshControl,
SectionList,
Alert,
Platform,
} from 'react-native';
import { BlueScanButton, WalletsCarousel, BlueHeaderDefaultMain, BlueTransactionListItem } from '../../BlueComponents';
import { Icon } from 'react-native-elements';
import { NavigationEvents } from 'react-navigation';
@ -8,11 +20,14 @@ import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import PropTypes from 'prop-types';
import { PlaceholderWallet } from '../../class';
import WalletImport from '../../class/walletImport';
import ActionSheet from '../ActionSheet';
import ImagePicker from 'react-native-image-picker';
let EV = require('../../events');
let A = require('../../analytics');
/** @type {AppStorage} */
let BlueApp = require('../../BlueApp');
let loc = require('../../loc');
const LocalQRCode = require('@remobile/react-native-qrcode-local-image');
let BlueElectrum = require('../../BlueElectrum');
const WalletsListSections = { CAROUSEL: 'CAROUSEL', LOCALTRADER: 'LOCALTRADER', TRANSACTIONS: 'TRANSACTIONS' };
@ -432,7 +447,7 @@ export default class WalletsList extends Component {
overflow: 'hidden',
}}
>
<BlueScanButton onPress={this.onScanButtonPressed} />
<BlueScanButton onPress={this.onScanButtonPressed} onLongPress={this.sendButtonLongPress} />
</View>
);
} else {
@ -459,6 +474,87 @@ export default class WalletsList extends Component {
});
};
choosePhoto = () => {
ImagePicker.launchImageLibrary(
{
title: null,
mediaType: 'photo',
takePhotoButtonTitle: null,
},
response => {
if (response.uri) {
const uri = Platform.OS === 'ios' ? response.uri.toString().replace('file://', '') : response.path.toString();
LocalQRCode.decode(uri, (error, result) => {
if (!error) {
this.onBarScanned({ data: result });
} else {
alert('The selected image does not contain a QR Code.');
}
});
}
},
);
};
copyFromClipbard = async () => {
this.onBarScanned(await Clipboard.getString());
};
sendButtonLongPress = async () => {
const isClipboardEmpty = (await Clipboard.getString()).replace(' ', '').length === 0;
if (Platform.OS === 'ios') {
let options = [loc.send.details.cancel, 'Choose Photo', 'Scan QR Code'];
if (!isClipboardEmpty) {
options.push('Copy from Clipboard');
}
ActionSheet.showActionSheetWithOptions({ options, cancelButtonIndex: 0 }, buttonIndex => {
if (buttonIndex === 1) {
this.choosePhoto();
} else if (buttonIndex === 2) {
this.props.navigation.navigate('ScanQRCode', {
launchedBy: this.props.navigation.state.routeName,
onBarScanned: this.onBarCodeRead,
showFileImportButton: false,
});
} else if (buttonIndex === 3) {
this.copyFromClipbard();
}
});
} else if (Platform.OS === 'android') {
let buttons = [
{
text: loc.send.details.cancel,
onPress: () => {},
style: 'cancel',
},
{
text: 'Choose Photo',
onPress: this.choosePhoto,
},
{
text: 'Scan QR Code',
onPress: () =>
this.props.navigation.navigate('ScanQRCode', {
launchedBy: this.props.navigation.state.routeName,
onBarScanned: this.onBarCodeRead,
showFileImportButton: false,
}),
},
];
if (!isClipboardEmpty) {
buttons.push({
text: 'Copy From Clipboard',
onPress: this.copyFromClipbard,
});
}
ActionSheet.showActionSheetWithOptions({
title: '',
message: '',
buttons,
});
}
};
render() {
return (
<View style={{ flex: 1 }}>

View File

@ -521,11 +521,14 @@ export default class WalletTransactions extends Component {
this.onBarCodeRead({ data: await Clipboard.getString() });
};
sendButtonLongPress = () => {
sendButtonLongPress = async () => {
const isClipboardEmpty = (await Clipboard.getString()).replace(' ', '').length === 0;
if (Platform.OS === 'ios') {
ActionSheet.showActionSheetWithOptions(
{ options: [loc.send.details.cancel, 'Choose Photo', 'Scan QR Code', 'Copy from Clipboard'], cancelButtonIndex: 0 },
buttonIndex => {
let options = [loc.send.details.cancel, 'Choose Photo', 'Scan QR Code'];
if (!isClipboardEmpty) {
options.push('Copy from Clipboard');
}
ActionSheet.showActionSheetWithOptions({ options, cancelButtonIndex: 0 }, buttonIndex => {
if (buttonIndex === 1) {
this.choosePhoto();
} else if (buttonIndex === 2) {
@ -537,13 +540,9 @@ export default class WalletTransactions extends Component {
} else if (buttonIndex === 3) {
this.copyFromClipbard();
}
},
);
});
} else if (Platform.OS === 'android') {
ActionSheet.showActionSheetWithOptions({
title: '',
message: '',
buttons: [
let buttons = [
{
text: loc.send.details.cancel,
onPress: () => {},
@ -562,11 +561,17 @@ export default class WalletTransactions extends Component {
showFileImportButton: false,
}),
},
{
];
if (!isClipboardEmpty) {
buttons.push({
text: 'Copy From Clipboard',
onPress: this.copyFromClipbard,
},
],
});
}
ActionSheet.showActionSheetWithOptions({
title: '',
message: '',
buttons,
});
}
};