Skip to content

Commit 4d3b0bc

Browse files
Rejig interactives disableArticleSwipe implementation
1 parent 1fd3594 commit 4d3b0bc

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

dotcom-rendering/src/components/InteractivesDisableArticleSwipe.importable.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,31 @@ import { useEffect } from 'react';
33
import { getInteractionClient } from '../lib/bridgetApi';
44

55
export const InteractivesDisableArticleSwipe = () => {
6-
useEffect(() => {
7-
void getInteractionClient()
6+
const onTouchStart = () => {
7+
getInteractionClient()
88
.disableArticleSwipe(true)
99
.catch((error) => {
10-
log('dotcom', 'disableArticleSwipe failed:', error);
10+
log('dotcom', 'disableArticleSwipe(true) failed', error);
11+
});
12+
};
13+
14+
const onTouchEnd = () => {
15+
getInteractionClient()
16+
.disableArticleSwipe(false)
17+
.catch((error) => {
18+
log('dotcom', 'disableArticleSwipe(false) failed', error);
1119
});
20+
};
21+
useEffect(() => {
22+
document.addEventListener('touchstart', onTouchStart, {
23+
passive: true,
24+
});
25+
document.addEventListener('touchend', onTouchEnd, { passive: true });
26+
27+
return () => {
28+
document.removeEventListener('touchstart', onTouchStart);
29+
document.removeEventListener('touchend', onTouchEnd);
30+
};
1231
}, []);
1332
return null;
1433
};

0 commit comments

Comments
 (0)