2024-03-27 05:37:43 +01:00
|
|
|
import Clipboard from '@react-native-clipboard/clipboard';
|
2024-05-20 11:54:13 +02:00
|
|
|
import React, { forwardRef, useEffect, useState } from 'react';
|
|
|
|
import { Animated, StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
|
|
|
2024-04-12 00:40:52 +02:00
|
|
|
import triggerHapticFeedback, { HapticFeedbackTypes } from '../blue_modules/hapticFeedback';
|
2024-05-20 11:54:13 +02:00
|
|
|
import loc from '../loc';
|
2024-03-27 05:37:43 +01:00
|
|
|
|
|
|
|
type CopyTextToClipboardProps = {
|
|
|
|
text: string;
|
|
|
|
truncated?: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
const styleCopyTextToClipboard = StyleSheet.create({
|
|
|
|
address: {
|
|
|
|
marginVertical: 32,
|
|
|
|
fontSize: 15,
|
|
|
|
color: '#9aa0aa',
|
|
|
|
textAlign: 'center',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-08-31 00:43:50 +02:00
|
|
|
const CopyTextToClipboard = forwardRef<React.ElementRef<typeof TouchableOpacity>, CopyTextToClipboardProps>(({ text, truncated }, ref) => {
|
2024-03-27 05:37:43 +01:00
|
|
|
const [hasTappedText, setHasTappedText] = useState(false);
|
|
|
|
const [address, setAddress] = useState(text);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!hasTappedText) {
|
|
|
|
setAddress(text);
|
|
|
|
}
|
|
|
|
}, [text, hasTappedText]);
|
|
|
|
|
|
|
|
const copyToClipboard = () => {
|
|
|
|
setHasTappedText(true);
|
|
|
|
Clipboard.setString(text);
|
2024-04-12 00:40:52 +02:00
|
|
|
triggerHapticFeedback(HapticFeedbackTypes.Selection);
|
2024-03-27 05:53:06 +01:00
|
|
|
setAddress(loc.wallets.xpub_copiedToClipboard); // Adjust according to your localization logic
|
2024-03-27 05:37:43 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
setHasTappedText(false);
|
|
|
|
setAddress(text);
|
|
|
|
}, 1000);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2024-03-27 05:53:06 +01:00
|
|
|
<TouchableOpacity
|
|
|
|
ref={ref}
|
|
|
|
accessibilityRole="button"
|
|
|
|
onPress={copyToClipboard}
|
|
|
|
disabled={hasTappedText}
|
|
|
|
testID="CopyTextToClipboard"
|
|
|
|
>
|
2024-03-27 05:37:43 +01:00
|
|
|
<Animated.Text
|
|
|
|
style={styleCopyTextToClipboard.address}
|
|
|
|
{...(truncated ? { numberOfLines: 1, ellipsizeMode: 'middle' } : { numberOfLines: 0 })}
|
|
|
|
testID="AddressValue"
|
|
|
|
>
|
|
|
|
{address}
|
|
|
|
</Animated.Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
);
|
2024-03-27 05:53:06 +01:00
|
|
|
});
|
2024-03-27 05:37:43 +01:00
|
|
|
|
|
|
|
export default CopyTextToClipboard;
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: { justifyContent: 'center', alignItems: 'center', paddingHorizontal: 16 },
|
|
|
|
});
|