Skip to content

Commit d0423ca

Browse files
authored
Merge pull request #13177 from yashhash2/my-awesome-changes
Add Swipe Gesture Support for Side Navigation in Kolibri
2 parents 5a2ee5a + df2ee99 commit d0423ca

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

packages/kolibri/components/pages/AppBarPage/index.vue

+34-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
<!-- TODO useScrollPosition to set scrollPosition...
44
here or in router, but somewhere -->
55
<div class="main">
6+
<div
7+
v-if="windowIsSmall"
8+
ref="swipeZone"
9+
class="swipe-zone"
10+
></div>
11+
612
<ScrollingHeader :scrollPosition="0">
713
<transition mode="out-in">
814
<AppBar
@@ -58,6 +64,8 @@
5864
import commonCoreStrings from 'kolibri/uiText/commonCoreStrings';
5965
import { isTouchDevice } from 'kolibri/utils/browserInfo';
6066
import useUser from 'kolibri/composables/useUser';
67+
import { ref, getCurrentInstance } from 'vue';
68+
import { useSwipe } from '@vueuse/core';
6169
import ScrollingHeader from '../ScrollingHeader';
6270
import AppBar from './internal/AppBar';
6371
import SideNav from './internal/SideNav';
@@ -71,11 +79,26 @@
7179
},
7280
mixins: [commonCoreStrings],
7381
setup() {
82+
const instance = getCurrentInstance();
83+
const isRtl = ref(instance?.proxy.isRtl);
84+
const swipeZone = ref(null);
85+
const navShown = ref(false);
86+
useSwipe(swipeZone, {
87+
onSwipeEnd: (e, direction) => {
88+
if (direction === 'right' && !navShown.value && !isRtl.value) {
89+
navShown.value = true;
90+
} else if (direction === 'left' && !navShown.value && isRtl.value) {
91+
navShown.value = true;
92+
}
93+
},
94+
});
7495
const { windowIsSmall } = useKResponsiveWindow();
7596
const { isAppContext } = useUser();
7697
return {
7798
windowIsSmall,
7899
isAppContext,
100+
swipeZone,
101+
navShown,
79102
};
80103
},
81104
props: {
@@ -102,7 +125,6 @@
102125
data() {
103126
return {
104127
appBarHeight: 124,
105-
navShown: false,
106128
lastScrollTop: 0,
107129
hideAppBars: true,
108130
throttledHandleScroll: null,
@@ -222,4 +244,15 @@
222244
background-color: white;
223245
}
224246
247+
.swipe-zone {
248+
position: fixed;
249+
top: 0;
250+
bottom: 0;
251+
left: 0;
252+
z-index: 5;
253+
width: 30px;
254+
background: red;
255+
opacity: 0;
256+
}
257+
225258
</style>

packages/kolibri/components/pages/AppBarPage/internal/SideNav.vue

+19-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<transition :name="showAppNavView ? 'bottom-nav' : 'side-nav'">
1010
<div
1111
v-show="navShown"
12+
ref="sideNavInside"
1213
class="side-nav"
1314
:class="showAppNavView ? 'bottom-offset' : ''"
1415
:style="{
@@ -266,6 +267,8 @@
266267
import useNav from 'kolibri/composables/useNav';
267268
import useUser from 'kolibri/composables/useUser';
268269
import useUserSyncStatus from 'kolibri/composables/useUserSyncStatus';
270+
import { useSwipe } from '@vueuse/core';
271+
import { ref, getCurrentInstance } from 'vue';
269272
import SyncStatusDisplay from '../../../SyncStatusDisplay';
270273
import LearnOnlyDeviceNotice from './LearnOnlyDeviceNotice';
271274
import TotalPoints from './TotalPoints';
@@ -298,7 +301,21 @@
298301
BottomNavigationBar,
299302
},
300303
mixins: [commonCoreStrings],
301-
setup() {
304+
setup(props, { emit }) {
305+
const instance = getCurrentInstance();
306+
const isRtl = instance?.proxy.isRtl;
307+
308+
const sideNavInside = ref(null);
309+
useSwipe(sideNavInside, {
310+
threshold: 100,
311+
onSwipeEnd: (e, direction) => {
312+
if (direction === 'left' && !isRtl) {
313+
emit('toggleSideNav');
314+
} else if (direction === 'right' && isRtl) {
315+
emit('toggleSideNav');
316+
}
317+
},
318+
});
302319
const { windowIsSmall, windowIsLarge } = useKResponsiveWindow();
303320
const {
304321
canManageContent,
@@ -330,6 +347,7 @@
330347
userSyncStatus: status,
331348
userLastSynced: lastSynced,
332349
navItems,
350+
sideNavInside,
333351
};
334352
},
335353
props: {

0 commit comments

Comments
 (0)