Skip to content

Commit 0f6b9a5

Browse files
Merge pull request #779 from THEOplayer/feature/example-extension-button
Add an extension menu with custom actions
2 parents c029583 + 23f6b6b commit 0f6b9a5

4 files changed

Lines changed: 52 additions & 2 deletions

File tree

example/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
KeyOSDrmFairplayContentProtectionIntegrationFactory,
5252
KeyOSDrmWidevineContentProtectionIntegrationFactory,
5353
} from '@theoplayer/react-native-drm';
54+
import { ExtensionMenuButton } from './custom/ExtensionMenuButton';
5455

5556
// Register Ezdrm Fairplay integration
5657
ContentProtectionRegistry.registerContentProtectionIntegration('customEzdrm', 'fairplay', new EzdrmFairplayContentProtectionIntegrationFactory());
@@ -166,6 +167,7 @@ export default function App() {
166167
<AutoFocusGuide>
167168
<ControlBar>
168169
<Spacer />
170+
<ExtensionMenuButton>{/*<ExtensionButton label={'Custom action'} onPress={() => {}} />*/}</ExtensionMenuButton>
169171
<MediaCacheMenuButton>
170172
<MediaCacheDownloadButton />
171173
<MediaCachingTaskListSubMenu />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import { MenuButton, MenuRadioButton, MenuView, ScrollableMenu } from '@theoplayer/react-native-ui';
3+
import type { StyleProp, ViewStyle } from 'react-native';
4+
import { ExtensionSvg } from '../res/ExtensionSvg';
5+
6+
export interface ExtensionMenuButtonProps {
7+
/**
8+
* Overrides for the style of the menu.
9+
*/
10+
menuStyle?: StyleProp<ViewStyle>;
11+
}
12+
13+
/**
14+
* A button component that opens a media cache menu.
15+
*/
16+
export const ExtensionMenuButton = (props: React.PropsWithChildren<ExtensionMenuButtonProps>) => {
17+
if (!props.children) {
18+
return <></>;
19+
}
20+
return (
21+
<MenuButton
22+
svg={<ExtensionSvg />}
23+
menuConstructor={() => <MenuView style={props.menuStyle} menu={<ScrollableMenu title={'Extensions'} items={props.children} />} />}
24+
/>
25+
);
26+
};
27+
28+
export const ExtensionButton = ({ label, onPress }: { label: string; onPress?: () => void }) => (
29+
<MenuRadioButton label={label} uid={0} onSelect={() => onPress?.()} />
30+
);

example/src/custom/MediaCacheDownloadButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { PlayerContext } from '@theoplayer/react-native-ui';
22
import React, { useCallback, useContext } from 'react';
33
import { MediaCache } from 'react-native-theoplayer';
4-
import { MenuRadioButton } from '@theoplayer/react-native-ui/src/ui/components/menu/common/MenuRadioButton';
4+
import { MenuRadioButton } from '@theoplayer/react-native-ui';
55

66
export const MediaCacheDownloadButton = () => {
77
const { player } = useContext(PlayerContext);
88

99
const onPress = useCallback(() => {
1010
const currentSource = player?.source;
1111
if (currentSource) {
12-
MediaCache.createTask(currentSource, {
12+
void MediaCache.createTask(currentSource, {
1313
amount: '100%',
1414
expirationDate: new Date(Date.now() + 24 * 60 * 60 * 1000),
1515
allowsCellularAccess: true,

example/src/res/ExtensionSvg.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { SvgProps } from 'react-native-svg';
2+
import Svg, { Path } from 'react-native-svg';
3+
import React from 'react';
4+
import { SvgContext } from '@theoplayer/react-native-ui';
5+
6+
export const ExtensionSvg = (props: SvgProps) => {
7+
return (
8+
<SvgContext.Consumer>
9+
{(context) => (
10+
<>
11+
<Svg viewBox={'0 -960 960 960'} {...context} {...props}>
12+
<Path d="M352-120H200q-33 0-56.5-23.5T120-200v-152q48 0 84-30.5t36-77.5q0-47-36-77.5T120-568v-152q0-33 23.5-56.5T200-800h160q0-42 29-71t71-29q42 0 71 29t29 71h160q33 0 56.5 23.5T800-720v160q42 0 71 29t29 71q0 42-29 71t-71 29v160q0 33-23.5 56.5T720-120H568q0-50-31.5-85T460-240q-45 0-76.5 35T352-120Zm-152-80h85q24-66 77-93t98-27q45 0 98 27t77 93h85v-240h80q8 0 14-6t6-14q0-8-6-14t-14-6h-80v-240H480v-80q0-8-6-14t-14-6q-8 0-14 6t-6 14v80H200v88q54 20 87 67t33 105q0 57-33 104t-87 68v88Zm260-260Z" />
13+
</Svg>
14+
</>
15+
)}
16+
</SvgContext.Consumer>
17+
);
18+
};

0 commit comments

Comments
 (0)