Skip to content

Commit

Permalink
tvOS seems to be working?
Browse files Browse the repository at this point in the history
  • Loading branch information
LunatiqueCoder committed Sep 9, 2022
1 parent 5d00516 commit 390c071
Show file tree
Hide file tree
Showing 7 changed files with 876 additions and 469 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"eslint-plugin-react": "^7.29.3",
"prettier": "^2.5.1",
"react": "^17.0.2",
"react-native": "^0.67.3",
"react-native": "npm:[email protected]",
"react-native-builder-bob": "^0.18.2",
"react-native-video": "^5.2.0",
"release-it": "^15.0.0",
Expand Down
12 changes: 7 additions & 5 deletions src/VideoPlayer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useCallback, useState, useEffect, useRef} from 'react';
import {TouchableWithoutFeedback, View} from 'react-native';
import {View} from 'react-native';
import Video, {
OnLoadData,
OnProgressData,
Expand All @@ -13,6 +13,7 @@ import {
BottomControls,
PlayPause,
} from './components';
import {PlatformSupport} from './components/PlatformSupport';
import {_onBack} from './utils';
import {_styles} from './styles';
import type {VideoPlayerProps} from './types';
Expand Down Expand Up @@ -374,9 +375,10 @@ export const VideoPlayer = (props: VideoPlayerProps) => {
}, []);

return (
<TouchableWithoutFeedback
onPress={events.onScreenTouch}
style={[_styles.player.container, styles.containerStyle]}>
<PlatformSupport
showControls={showControls}
containerStyles={styles.containerStyle}
onScreenTouch={events.onScreenTouch}>
<View style={[_styles.player.container, styles.containerStyle]}>
<Video
{...props}
Expand Down Expand Up @@ -445,6 +447,6 @@ export const VideoPlayer = (props: VideoPlayerProps) => {
</>
)}
</View>
</TouchableWithoutFeedback>
</PlatformSupport>
);
};
14 changes: 10 additions & 4 deletions src/components/Control.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import React, {ReactNode} from 'react';
import {TouchableHighlight} from 'react-native';
import {TouchableHighlight, ViewProps} from 'react-native';
import {styles} from './styles';

interface ControlProps {
interface ControlProps extends ViewProps {
children: ReactNode;
callback?: () => void;
style?: any;
resetControlTimeout?: () => void;
}

export const Control = ({children, callback, style = {}}: ControlProps) => {
export const Control = ({
children,
callback,
style = {},
...props
}: ControlProps) => {
return (
<TouchableHighlight
underlayColor="transparent"
activeOpacity={0.3}
onPress={() => {
callback && callback();
}}
style={[styles.control, style]}>
style={[styles.control, style]}
{...props}>
{children}
</TouchableHighlight>
);
Expand Down
43 changes: 43 additions & 0 deletions src/components/PlatformSupport.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, {ReactNode} from 'react';
import {
TouchableWithoutFeedback,
Platform,
StyleProp,
ViewStyle,
} from 'react-native';
import {TVOSSupport} from './TVOSSupport';
import {_styles} from '../styles';

interface OSSupport {
children: ReactNode;
containerStyles: StyleProp<ViewStyle>;
onScreenTouch: () => void;
showControls: boolean;
}

export const PlatformSupport = ({
children,
onScreenTouch,
containerStyles,
showControls,
}: OSSupport) => {
if (Platform.isTV) {
return (
<>
<TVOSSupport
showControls={showControls}
onScreenTouch={onScreenTouch}
/>
{children}
</>
);
}

return (
<TouchableWithoutFeedback
onPress={onScreenTouch}
style={[_styles.player.container, containerStyles]}>
{children}
</TouchableWithoutFeedback>
);
};
7 changes: 5 additions & 2 deletions src/components/PlayPause/PlayPause.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {Animated, Image} from 'react-native';
import {Animated, Image, Platform} from 'react-native';
import {Control, NullControl} from '../';
import type {VideoAnimations} from '../../types';
import {styles} from './styles';
Expand All @@ -15,6 +15,8 @@ interface PlayPauseProps {
onPressRewind: () => void;
}

const tvProps = {hasTVPreferredFocus: true};

const play = require('../../assets/img/play.png');
const pause = require('../../assets/img/pause.png');
const rewind = require('../../assets/img/rewind.png');
Expand Down Expand Up @@ -53,7 +55,8 @@ export const PlayPause = ({
<Control
callback={togglePlayPause}
resetControlTimeout={resetControlTimeout}
style={styles.playContainer}>
style={styles.playContainer}
{...(Platform.isTV ? tvProps : {})}>
<Image source={source} resizeMode={'contain'} style={styles.play} />
</Control>
<Control
Expand Down
17 changes: 17 additions & 0 deletions src/components/TVOSSupport.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'react-native/tvos-types.d';
import {useTVEventHandler} from 'react-native';

interface OSSupport {
showControls: boolean;
onScreenTouch: () => void;
}

export const TVOSSupport = ({showControls, onScreenTouch}: OSSupport) => {
useTVEventHandler(() => {
if (!showControls) {
onScreenTouch();
}
});

return null;
};
Loading

0 comments on commit 390c071

Please sign in to comment.