Skip to content

Commit 4f68630

Browse files
committed
Add click event to existing mouse events for Web. Also renamed the function to reflect real name for that events according to W3C
1 parent 4dff3b1 commit 4f68630

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

src/ui/components/uicontroller/UiContainer.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { THEOplayerTheme } from '../../THEOplayerTheme';
88
import type { MenuConstructor, UiControls } from './UiControls';
99
import { ErrorDisplay } from '../message/ErrorDisplay';
1010
import { type Locale, defaultLocale } from '../util/Locale';
11-
import { usePointerMove } from '../../hooks/usePointerMove';
11+
import { useWebMouseEvents } from '../../hooks/useWebMouseEvents';
1212
import { useThrottledCallback } from '../../hooks/useThrottledCallback';
1313

1414
export interface UiContainerProps {
@@ -398,7 +398,7 @@ export const UiContainer = forwardRef<UiContainerRef, UiContainerProps>((props,
398398
* If an ad is playing, the UI should pass through all pointer events ("box-none") in order for ad clickThrough to work.
399399
* Throttle the callback avoids hammering the fade-in animation.
400400
*/
401-
usePointerMove('#theoplayer-root-container', useThrottledCallback(onUserAction_, WEB_POINTER_MOVE_THROTTLE), doFadeOut_);
401+
useWebMouseEvents('#theoplayer-root-container', useThrottledCallback(onUserAction_, WEB_POINTER_MOVE_THROTTLE), doFadeOut_);
402402

403403
const combinedUiContainerStyle = [UI_CONTAINER_STYLE, props.style];
404404

@@ -437,7 +437,6 @@ export const UiContainer = forwardRef<UiContainerRef, UiContainerProps>((props,
437437
style={[combinedUiContainerStyle, { opacity: fadeAnimation }]}
438438
onTouchMove={onUserAction_}
439439
onTouchEnd={onUserAction_}
440-
onClick={onUserAction_}
441440
pointerEvents={adInProgress ? 'box-none' : uiVisible_ ? 'auto' : 'box-only'}>
442441
{uiVisible_ && (
443442
<>
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,27 @@ import { useEffect } from 'react';
22
import { Platform } from 'react-native';
33

44
/**
5-
* Listens to pointer events on Web.
5+
* Listens to mouse events on Web.
66
*/
7-
export const usePointerMove = (elementId: string, onMove: () => void, onLeave?: () => void) => {
7+
export const useWebMouseEvents = (elementId: string, onInteraction: () => void, onLeave?: () => void) => {
88
useEffect(() => {
99
if (Platform.OS !== 'web') {
1010
return;
1111
}
1212
const elementRef = document?.querySelector(elementId);
1313
if (elementRef) {
14-
/**
15-
* Listening to `mousemove` events instead of `pointermove`, which requires the page to be "activated" through
16-
* a tap/click first.
17-
*/
18-
elementRef?.addEventListener('mousemove', onMove);
14+
elementRef?.addEventListener('mousemove', onInteraction);
15+
elementRef?.addEventListener('click', onInteraction);
1916
if (onLeave) {
2017
elementRef?.addEventListener('mouseleave', onLeave);
2118
}
2219
}
2320
return () => {
24-
elementRef?.removeEventListener('mousemove', onMove);
21+
elementRef?.removeEventListener('mousemove', onInteraction);
22+
elementRef?.removeEventListener('click', onInteraction);
2523
if (onLeave) {
2624
elementRef?.removeEventListener('mouseleave', onLeave);
2725
}
2826
};
29-
}, [onMove, onLeave, elementId]);
27+
}, [onInteraction, onLeave, elementId]);
3028
};

0 commit comments

Comments
 (0)