67
Views
2
Comments
[Google Maps Plugin] Suspect behavior on back button
Question
google-maps-plugin
Mobile icon
Forge asset by João Grazina

Tenho a seguinte situação: utilizo um script no evento OnApplicationReady que captura o botão voltar do dispositivo e apresenta uma caixa de diálogo antes de sair do app, conforme abaixo:


document.addEventListener('backbutton', onPressBack, false);

function onPressBack(e) {
    e.preventDefault();
   
    var pagesExit = ['/Teste/Login', '/Teste/Splash', '/Teste', '/Teste/', '/Teste/Principal'];
    var actualPathName = window.location.pathname;
   
    if (pagesExit.indexOf(actualPathName) > -1) {
        sairApp();
    } else {
        backPage();
    }
}


O plugin do Google Maps também possui uma caputura do botão voltar que força a saída do app mesmo que o usuário não queira. Se estiver na tela HomeScreen e aperta o botão voltar o app encerra, ignorando o cancelamento da caixa de diálogo que apresento (mesmo que o usuário não queira sair):

Já testei sem o plugin do Google Maps e a captura do botão voltar funciona corretamente, quando vinculo o plugin ao app o comportamento estranho começa a acontecer.

Mesmo utilizando outros plugins para tratamento do botão sair, o plugin do Google Maps interfere no comportamento e sempre força a saída na tela Home.

Como é possível ajustar o comportamento do botão voltar para que o plugin não interfira na saída do app?


Eurico Junior

2020-03-04 14-50-24
Armando Gomes

Hello Eurico,


First of all, I would suggest type the question in english, if possible. This would allow a greater audience to reply to you.


I would say that the GMaps event is the last one applied and, as such, will override yours. Try something like a button on the screen that will invoke a JS object. This JS object will apply your code and, possibly, override the overrider. Would this be something possible to test?


Another possible thing would be to remove all the listeners to a given action and redo them.


Thanks,

Armando

UserImage.jpg
Eurico Junior

Hello Armando


Thanks for your response. I did a test of overlapping the listener's back button and canceling ALL previously enabled listeners, but it did not work. I do not know why, but the Maps plugin always forces the app to exit when you click the back button, no matter what screen you're on.


Eurico Junior

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.