hybriteq / react-native-floating-bubble

A simple Facebook Chat Head like bubble for react native
MIT License
212 stars 57 forks source link

More than 1 bubble shows up #44

Open Sargnec opened 2 years ago

Sargnec commented 2 years ago

More than 1 bubble shows up and it looks like randomly happens. I'm showing bubble on background notification. Tried to look at the java codes I couldnt do anything

  setBackgroundMessageHandler(props){
        console.log('setBackgroundMessageHandler listener');
        // To display the bubble over other apps you need to get 'Draw Over Other Apps' permission from androind.
        // If you initialize without having the permission App could crash
        if(Platform.OS === 'android'){
            requestPermission().then(() => console.log("Permission Granted")).catch(() => console.log("Permission is not granted"))

            // Initialize bubble manage
            initialize().then(() => console.log("Initialized the bubble mange"))
        }
        return firebase.messaging().setBackgroundMessageHandler(async remoteMessage => {
            if(Platform.OS === 'android'){
            // Show Floating Bubble: x=10, y=10 position of the bubble
            hideFloatingBubble().then(() => console.log("Floating Bubble Removed"));
            showFloatingBubble(10, 10).then(() => props.handleAddAlarm(remoteMessage.notification));
            DeviceEventEmitter.addListener("floating-bubble-press", (e) => {
                Linking.openURL('appName://').then((data) => {
                    //fetch new orders
                })
                .catch((e) => {
                    console.log('Error opening app',e);
                });
                hideFloatingBubble().then(() => console.log("Floating Bubble Removed"));
                props.handleStopAlarm();
            });
            DeviceEventEmitter.addListener("floating-bubble-remove", (e) => {
                console.log("Remove Bubble")
                props.handleStopAlarm();
            });
        }
        });
    }
Sargnec commented 2 years ago

Btw it happens at odd number :D starting from third clicking it creates another bubble without removing previous one at 5th, 7th , 9th clickings