Skip to content

Commit 27c3cea

Browse files
committed
fix(ios): prevent double onClick on TabbarLink in touch mode (#263)
fixes #263
1 parent 3eb5406 commit 27c3cea

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/shared/use-ios-tabbar-highlight.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ export const useIosTabbarHighlight = (params) => {
6060
startAnimation();
6161
};
6262

63+
const onContainerClick = (e) => {
64+
if (data.suppressNativeClick && e.isTrusted) {
65+
data.suppressNativeClick = false;
66+
e.stopPropagation();
67+
}
68+
};
69+
6370
const unsetHighlightOnTouch = () => {
6471
if (!getHasTabbarLinks()) return;
6572
cancelAnimationFrame(data.raf);
@@ -73,6 +80,7 @@ export const useIosTabbarHighlight = (params) => {
7380
const { activeIndex, newActiveIndex, linkEls } = data;
7481
if (activeIndex !== newActiveIndex) {
7582
linkEls[newActiveIndex].click();
83+
data.suppressNativeClick = true;
7684
}
7785
getHighlightEl().style.transform = `translateX(${newActiveIndex * 100}%)`;
7886
getHighlightEl().style.transitionTimingFunction = '';
@@ -137,13 +145,15 @@ export const useIosTabbarHighlight = (params) => {
137145
const el = getEl();
138146
if (!el || !getHasHighlight()) return;
139147
el.addEventListener('pointerdown', onPointer);
148+
el.addEventListener('click', onContainerClick, true);
140149
document.addEventListener('pointermove', onPointer);
141150
document.addEventListener('pointerup', onPointer);
142151
};
143152
const detachEvents = () => {
144153
const el = getEl();
145154
if (!el || !getHasHighlight()) return;
146155
el.removeEventListener('pointerdown', onPointer);
156+
el.removeEventListener('click', onContainerClick, true);
147157
document.removeEventListener('pointermove', onPointer);
148158
document.removeEventListener('pointerup', onPointer);
149159
};

0 commit comments

Comments
 (0)