Search code examples
react-nativenative-basetouchableopacity

How to display "text is copied" to the user after the text has been copied?


How to display "text is copied" to the user after the text has been copied?

const dataArray = [ { title: "Invoice Reference Number", content:QRCODE_SAMPLE.Irn } ];

<TouchableOpacity activeOpacity={1}
    onPress={() => Clipboard.setString(QRCODE_SAMPLE.Irn)}>   
    <Accordion style={{paddingTop:10,paddingBottom:50,backgroundColor:'#E0DDDD'}}dataArray={dataArray} expanded={1}>
    </Accordion>
</TouchableOpacity> 

Solution

  • You can do it like this :

        import {ToastAndroid} from 'react-native';
    

    Create this function :

        onCopyPressed(){
    
        Clipboard.setString(QRCODE_SAMPLE.Irn);
        ToastAndroid.show('A pikachu appeared nearby !', ToastAndroid.SHORT);
        }
    

    And call that function like this :

    const dataArray = [ { title: "Invoice Reference Number", content:QRCODE_SAMPLE.Irn } ];
    <TouchableOpacity activeOpacity={1}
            onPress={this.onCopyPressed.bind(this)}>   
            <Accordion style={{paddingTop:10,paddingBottom:50,backgroundColor:'#E0DDDD'}}dataArray={dataArray} expanded={1}>
            </Accordion>
        </TouchableOpacity>