DEV Community

HarmonyOS
HarmonyOS

Posted on

[Smart & Sports Watch] How to Resolve the Conflict Between Swiper Right Swipe and System Exiting the App in API 6 JS?

Read the original article:[Smart & Sports Watch] How to Resolve the Conflict Between Swiper Right Swipe and System Exiting the App in API 6 JS?

Problem:

When there is only one page in the page stack, the default swipe event dispatch will cause the app to exit instead of triggering the right swipe of the Swiper.

Solution:

This can be resolved by using app.setSwipeToDismiss(true) to disable the right swipe exit function (this only works in API 6 and may not be effective in other APIs). Since app.setSwipeToDismiss(true) is a global setting that disables the right swipe exit function, it is necessary to set it to false when the Swiper index is 0 to keep the right swipe exit function enabled.

onShow() {
    app.setSwipeToDismiss(this.currPage != 0);
},
onHide() {
    app.setSwipeToDismiss(false);
},
onDestroy() {
    app.setSwipeToDismiss(false);
},
onMainPageChange(e) {
    // Record the current number of pages
    this.currPage = e.index
    // Determine whether to enable the gesture and swipe right to exit based on the page
    app.setSwipeToDismiss(this.currPage != 0);
Enter fullscreen mode Exit fullscreen mode

Written by Erman Derici

Top comments (0)