Skip to content

Commit ba8f7e0

Browse files
authored
Merge pull request #115 from THEOplayer/bugfix/android-chromecast-button-non-responsive
Use onTouchEnd to fix Chromecast button non responsive on Android
2 parents 296a200 + a2a2e80 commit ba8f7e0

5 files changed

Lines changed: 20 additions & 14 deletions

File tree

.changeset/pink-trees-open.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@theoplayer/react-native-ui': patch
3+
---
4+
5+
Fixed an issue on mobile platforms where the Chromecast button would not be tappable.

example/android/app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ android {
9797
keyPassword 'android'
9898
}
9999
}
100+
compileOptions {
101+
coreLibraryDesugaringEnabled true
102+
}
100103
buildTypes {
101104
debug {
102105
signingConfig signingConfigs.debug
@@ -117,6 +120,7 @@ dependencies {
117120

118121
// The version of react-native is set by the React Native Gradle Plugin
119122
implementation("com.facebook.react:react-android")
123+
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")
120124

121125
if (hermesEnabled.toBoolean()) {
122126
implementation("com.facebook.react:hermes-android")

example/web/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const CopyWebpackPluginConfig = new CopyWebpackPlugin({
5454
// /.*@theoplayer\/.*\.js$/ : process all js files from @theoplayer packages to apply the root import alias. This is only needed for this example.
5555
const babelLoaderConfiguration = {
5656
test: [/\.tsx?$/, /.*@theoplayer\/.*\.js$/],
57-
exclude: ['/**/*.d.ts', '/**/node_modules/'],
57+
exclude: [/\.d\.ts$/, /cmcd-connector\.esm\.js$/],
5858
use: {
5959
loader: 'babel-loader',
6060
options: {

src/ui/components/uicontroller/UiContainer.tsx

Lines changed: 3 additions & 4 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

@@ -436,8 +436,7 @@ export const UiContainer = forwardRef<UiContainerRef, UiContainerProps>((props,
436436
<Animated.View
437437
style={[combinedUiContainerStyle, { opacity: fadeAnimation }]}
438438
onTouchMove={onUserAction_}
439-
onStartShouldSetResponder={() => true}
440-
onResponderRelease={onUserAction_}
439+
onTouchEnd={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)