How to detect when third party app's dialog box appears in React native?

290 views Asked by At

My app sends stickers to WhatsaApp and it shows a dialog box. How to wait for the user action on the dialog box and perform action after the dialog box gone.

export default function CreateScreen({route, navigation}){
    const [PreviewImages, setPreviewImages] = React.useState([]);
    const [isAnimated, setAnimated] = React.useState(false);
    const [PackName, setPackName] = React.useState(Date.now().toString());
    const [AuthorName, setAuthorName] = React.useState('');
    const [Version, setVersion] = React.useState(1);

    const context = React.useContext(AppContext);

    React.useLayoutEffect(() => {
        navigation.setOptions({
          headerRight: () => (
            <Button onPress={send} title="Create" color="#00ff00"/>
          ),
        });
    });
      

    const removePreview=(x)=>{
        setPreviewImages(PreviewImages.filter((i,index)=>index!==x));
    }

    const src = 'file://'+RNFS.DownloadDirectoryPath+'/'+'file10.jpg';
    const dest = 'file://'+RNFS.DownloadDirectoryPath+'/'+'file10_1.jpg';



    const send =async()=>{

        log('sending...')

        try{
        
            const packData = {
                authorName:AuthorName,
                packName:PackName,
                isAnimated:isAnimated,
                version:Version,
                previewImages:PreviewImages,
            }

            let jsonData = await DecoratePack(packData)


            await RNWhatsAppStickers.prepare(jsonData)
            .then(res=>res.slice(1))
            .then(str=>JSON.parse(str))
            .then(obj=>{
                log('pack ',obj['identifier'])
                return RNWhatsAppStickers.send(obj['identifier'],obj['identifier'])
            })
            .then(r2=>log(r2))
            .catch(err=>Alert.alert('Could not create pack',err.toString()))
            
        }catch(e){
            Alert.alert('Problem with pack',e.toString())
        }
        
        
    }


   
    return(
        <View style={root.main}>
            <Screen1/>
        </View>
    );
}

If I set the create button to navigate back to home screen after creatnig pack then whatsapp dialoge box will appear on home screen. It is kind of ok but dialog box is appeared to tell there is issue in pack or pack name already exist then it will be annoying for user to go to the create screen again.

Thanks for your help

1

There are 1 answers

0
CrackerKSR On BEST ANSWER

By onActivityResult we can detect the activity of third party apps fired by your app.

You'll need to listen to onActivityResult if you want to get results from an activity you started with startActivityForResult. To do this, you must extend BaseActivityEventListener or implement ActivityEventListener.

http://reactnative.dev/docs/native-modules-android#getting-activity-result-from-startactivityforresult