Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to stop an App closing with Swipe right?

ANSWERED

Is there a way to disable the Swipe right action from accidentally closing an App?

Author | ch, passion for improvement.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Provided by @Gondwana to intercept Swipe exit

 

 

document.addEventListener("beforeunload", (evt) => {
  // prevent the actual swipe unload event
  evt.preventDefault();
  background.x = 0;
});

 

 

requires

<svg id="background">

Author | ch, passion for improvement.

View best answer in original post

Best Answer
13 REPLIES 13

How can you prompt the user before closing and if he refuses the close, to return to the App and continue?

Author | ch, passion for improvement.

Best Answer
0 Votes

Does anyone know how - its far too easy to accidentally swipe right and the App just closes immediately, can it be stopped from doing this?

 

One can stop the back button doing this but what is the point if a simple swipe overrides that protection.

Author | ch, passion for improvement.

Best Answer

Provided by @Gondwana to intercept Swipe exit

 

 

document.addEventListener("beforeunload", (evt) => {
  // prevent the actual swipe unload event
  evt.preventDefault();
  background.x = 0;
});

 

 

requires

<svg id="background">

Author | ch, passion for improvement.

Best Answer

How can I leverage this code so that when my user swipes right, I don't get a black background but the text(i.e) I was showing before? 

Best Answer
0 Votes

Are you using document.location.assign() and document.history.back()?

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Actually no. Is there some example of it somewhere? 

Best Answer
0 Votes

https://dev.fitbit.com/blog/ Fitbit OS SDK 5.0.

 

The reference doco might also help.

 

You may find that you need an opaque background to one of your views, so that two don't get displayed simultaneously.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thanks! I'll try that. I just tried the document.location.assign and it messes up the whole view and reactivates all components I have previously deactivated. 

Best Answer
0 Votes

I'm assuming you're using multiple views (documents)...

Peter McLennan
Gondwana Software
Best Answer
0 Votes

No. I'm using just one but I might have to transition to multiple views that are dependent to the situation the app is in when swipe happens. 

Best Answer
0 Votes

Oh; this might be overkill then. You may be able to do what you want just by using an animation (see that blog post).

Peter McLennan
Gondwana Software
Best Answer

That worked great!! Thanks! I was so worried I have to do multiple views. I'm surely considering re-doing the app and give it a more sensible structure since it's becoming bigger than it how it was conceived. Thanks!! 

Best Answer

No worries. I shouldn't have assumed multiple views. I doubtless did so because I'm using them myself at the moment.

Peter McLennan
Gondwana Software
Best Answer
0 Votes