@castlabs/react-native-prestoplay-ios-avplayerviewcontroller 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/AVPlayerViewControllerExtension.swift +72 -0
- package/ios/ApplePlayerControlsPlugin.swift +23 -0
- package/ios/RNPrestoplayApplePlayerControlsModule.swift +192 -0
- package/ios/RNPrestoplayApplePlayerControlsPluginFactory.swift +19 -0
- package/ios/RNPrestroplay-Bridging-Header.h +9 -0
- package/ios/RNPrestroplayBridge.m +26 -0
- package/lib/AVPlayerViewControllerExtension.d.ts +28 -0
- package/lib/AVPlayerViewControllerExtension.js +148 -0
- package/lib/AVPlayerViewControllerPlugin.d.ts +15 -0
- package/lib/AVPlayerViewControllerPlugin.js +20 -0
- package/lib/components/AVPlayerViewControllerProvider.ios.d.ts +38 -0
- package/lib/components/AVPlayerViewControllerProvider.ios.js +41 -0
- package/lib/components/AppleTvContextualAction.ios.d.ts +32 -0
- package/lib/components/AppleTvContextualAction.ios.js +43 -0
- package/lib/components/AppleTvInfoBarAction.ios.d.ts +34 -0
- package/lib/components/AppleTvInfoBarAction.ios.js +46 -0
- package/lib/components/AppleTvPlayerControls.ios.d.ts +52 -0
- package/lib/components/AppleTvPlayerControls.ios.js +60 -0
- package/lib/components/AppleTvTransportBarAction.ios.d.ts +34 -0
- package/lib/components/AppleTvTransportBarAction.ios.js +47 -0
- package/lib/components/AppleTvTransportBarPopupMenu.ios.d.ts +41 -0
- package/lib/components/AppleTvTransportBarPopupMenu.ios.js +81 -0
- package/lib/components/AppleTvTransportBarSubMenu.ios.d.ts +41 -0
- package/lib/components/AppleTvTransportBarSubMenu.ios.js +70 -0
- package/lib/components/AppleTvTransportBarSubMenuItem.ios.d.ts +24 -0
- package/lib/components/AppleTvTransportBarSubMenuItem.ios.js +23 -0
- package/lib/events/AppleTvActionDetails.d.ts +7 -0
- package/lib/events/AppleTvActionDetails.js +1 -0
- package/lib/events/EventType.d.ts +7 -0
- package/lib/events/EventType.js +8 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +11 -0
- package/lib/types/Action.d.ts +13 -0
- package/lib/types/Action.js +1 -0
- package/lib/types/ActionType.d.ts +6 -0
- package/lib/types/ActionType.js +7 -0
- package/lib/types/ActionUiProperty.d.ts +5 -0
- package/lib/types/ActionUiProperty.js +1 -0
- package/lib/types/PopupMenu.d.ts +8 -0
- package/lib/types/PopupMenu.js +1 -0
- package/lib/types/PopupMenuInternal.d.ts +8 -0
- package/lib/types/PopupMenuInternal.js +1 -0
- package/lib/types/SubMenu.d.ts +7 -0
- package/lib/types/SubMenu.js +1 -0
- package/lib/types/SubMenuItem.d.ts +4 -0
- package/lib/types/SubMenuItem.js +1 -0
- package/package.json +89 -0
- package/react-native-prestoplay-ios-avplayerviewcontroller.podspec +21 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useContext, useEffect, useRef } from 'react';
|
|
2
|
+
import { AppleTvPlayerControlsContext } from './AppleTvPlayerControls.ios';
|
|
3
|
+
import { ActionType } from '../types/ActionType';
|
|
4
|
+
import uuid from 'uuid-random';
|
|
5
|
+
/**
|
|
6
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
7
|
+
*
|
|
8
|
+
* You can use the tvOS player UI to present controls contextually, which you
|
|
9
|
+
* display for a specific range of time in the content and then dismiss.
|
|
10
|
+
*
|
|
11
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience#Present-Actions-Contextually | Present Actions Contextually}.
|
|
12
|
+
*
|
|
13
|
+
* @group Components
|
|
14
|
+
*/
|
|
15
|
+
export const AppleTvContextualAction = props => {
|
|
16
|
+
const { eventEmitter, updateAction, addAction, removeAction } = useContext(AppleTvPlayerControlsContext);
|
|
17
|
+
const actionId = useRef(uuid());
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const _actionId = actionId.current;
|
|
20
|
+
addAction(ActionType.Contextual, _actionId, props);
|
|
21
|
+
return () => {
|
|
22
|
+
removeAction(ActionType.Contextual, _actionId);
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
const onPressRef = useRef(props.onPress);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
onPressRef.current = props.onPress;
|
|
28
|
+
}, [props.onPress]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const _actionId = actionId.current;
|
|
31
|
+
const onEvent = (_event) => {
|
|
32
|
+
onPressRef.current();
|
|
33
|
+
};
|
|
34
|
+
eventEmitter.addEventListener(_actionId, onEvent);
|
|
35
|
+
return () => {
|
|
36
|
+
eventEmitter.removeEventListener(_actionId, onEvent);
|
|
37
|
+
};
|
|
38
|
+
}, [eventEmitter]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
updateAction(actionId.current, true, props.title, props.icon);
|
|
41
|
+
}, [props.title, props.icon, updateAction]);
|
|
42
|
+
return null; // declarative action, AppleTvPlayerControls interprets it
|
|
43
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* AppleTvInfoBarActionProps defines the properties for an
|
|
4
|
+
* {@link AppleTvInfoBarAction}
|
|
5
|
+
*
|
|
6
|
+
* @group Type Aliases
|
|
7
|
+
*/
|
|
8
|
+
export type AppleTvInfoBarActionProps = {
|
|
9
|
+
/** The text of the infobar action button. */
|
|
10
|
+
title: string;
|
|
11
|
+
/** The name of the image resource in the Xcode app project. */
|
|
12
|
+
icon: string;
|
|
13
|
+
/** The state of the info bar action button. */
|
|
14
|
+
state: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Action to be executed when the button is pressed.
|
|
17
|
+
*
|
|
18
|
+
* @param value - The action state string passed to the handler.
|
|
19
|
+
*/
|
|
20
|
+
onPress: (value: string) => void;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
24
|
+
*
|
|
25
|
+
* An AVPlayerViewController presents an Info tab when playing an asset with
|
|
26
|
+
* embedded or external metadata. The tab’s view displays the metadata details,
|
|
27
|
+
* and it may show up to two AppleTvInfoBarAction controls along its trailing
|
|
28
|
+
* edge.
|
|
29
|
+
*
|
|
30
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience#Present-Actions-in-the-Info-Tab | Present Actions in the Info Tab}.
|
|
31
|
+
*
|
|
32
|
+
* @group Components
|
|
33
|
+
*/
|
|
34
|
+
export declare const AppleTvInfoBarAction: React.FC<AppleTvInfoBarActionProps>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useContext, useEffect, useRef } from 'react';
|
|
2
|
+
import { AppleTvPlayerControlsContext } from './AppleTvPlayerControls.ios';
|
|
3
|
+
import { ActionType } from '../types/ActionType';
|
|
4
|
+
import uuid from 'uuid-random';
|
|
5
|
+
/**
|
|
6
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
7
|
+
*
|
|
8
|
+
* An AVPlayerViewController presents an Info tab when playing an asset with
|
|
9
|
+
* embedded or external metadata. The tab’s view displays the metadata details,
|
|
10
|
+
* and it may show up to two AppleTvInfoBarAction controls along its trailing
|
|
11
|
+
* edge.
|
|
12
|
+
*
|
|
13
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience#Present-Actions-in-the-Info-Tab | Present Actions in the Info Tab}.
|
|
14
|
+
*
|
|
15
|
+
* @group Components
|
|
16
|
+
*/
|
|
17
|
+
export const AppleTvInfoBarAction = props => {
|
|
18
|
+
const { eventEmitter, updateAction, addAction, removeAction } = useContext(AppleTvPlayerControlsContext);
|
|
19
|
+
const actionId = useRef(uuid());
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const _actionId = actionId.current;
|
|
22
|
+
addAction(ActionType.InfoBar, _actionId, props);
|
|
23
|
+
return () => {
|
|
24
|
+
removeAction(ActionType.InfoBar, _actionId);
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
const onPressRef = useRef(props.onPress);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
onPressRef.current = props.onPress;
|
|
30
|
+
}, [props.onPress]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const _actionId = actionId.current;
|
|
33
|
+
const onEvent = (event) => {
|
|
34
|
+
const details = event.details;
|
|
35
|
+
onPressRef.current(details.data);
|
|
36
|
+
};
|
|
37
|
+
eventEmitter.addEventListener(_actionId, onEvent);
|
|
38
|
+
return () => {
|
|
39
|
+
eventEmitter.removeEventListener(_actionId, onEvent);
|
|
40
|
+
};
|
|
41
|
+
}, [eventEmitter]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
updateAction(actionId.current, props.state, props.title, props.icon);
|
|
44
|
+
}, [props.title, props.icon, props.state, updateAction]);
|
|
45
|
+
return null; // declarative action
|
|
46
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { AppleTvTransportBarActionProps } from './AppleTvTransportBarAction.ios';
|
|
3
|
+
import { AppleTvInfoBarActionProps } from './AppleTvInfoBarAction.ios';
|
|
4
|
+
import { BaseEventEmitter } from '@castlabs/react-native-prestoplay';
|
|
5
|
+
import { AppleTvContextualActionProps } from './AppleTvContextualAction.ios';
|
|
6
|
+
import { ActionType } from '../types/ActionType';
|
|
7
|
+
import { PopupMenuInternal } from '../types/PopupMenuInternal';
|
|
8
|
+
/**
|
|
9
|
+
* AppleTvInfoBarActionProps defines the properties for an
|
|
10
|
+
* {@link AppleTvPlayerControls}.
|
|
11
|
+
*
|
|
12
|
+
* Its children can be any of the following components:
|
|
13
|
+
* - {@link AppleTvTransportBarAction}
|
|
14
|
+
* - {@link AppleTvInfoBarAction}
|
|
15
|
+
* - {@link AppleTvContextualAction}
|
|
16
|
+
* - {@link AppleTvTransportBarPopupMenu}
|
|
17
|
+
*
|
|
18
|
+
* @group Type Aliases
|
|
19
|
+
*/
|
|
20
|
+
export type AppleTvPlayerControlsProps = {
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
};
|
|
23
|
+
type AppleTvPlayerControlsContextType = {
|
|
24
|
+
eventEmitter: BaseEventEmitter;
|
|
25
|
+
updateAction: (actionId: string, state: boolean, title: string, icon: string) => void;
|
|
26
|
+
addAction: (type: ActionType, actionId: string, props: AppleTvTransportBarActionProps | AppleTvInfoBarActionProps | AppleTvContextualActionProps) => void;
|
|
27
|
+
removeAction: (type: ActionType, actionId: string) => void;
|
|
28
|
+
setPopupMenu: (menuId: string, popUpMenu: PopupMenuInternal) => void;
|
|
29
|
+
removePopupMenu: (menuId: string) => void;
|
|
30
|
+
};
|
|
31
|
+
export declare const AppleTvPlayerControlsContext: React.Context<AppleTvPlayerControlsContextType>;
|
|
32
|
+
/**
|
|
33
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
34
|
+
*
|
|
35
|
+
* Use the tvOS player UI to present custom controls in an
|
|
36
|
+
* {@link AVPlayerViewControllerProvider} by including this component as a child.
|
|
37
|
+
*
|
|
38
|
+
* This component serves as a **provider** for its child components, enabling
|
|
39
|
+
* integration of custom actions and menus within the tvOS player interface.
|
|
40
|
+
*
|
|
41
|
+
* Supported child components include:
|
|
42
|
+
* - {@link AppleTvTransportBarAction}
|
|
43
|
+
* - {@link AppleTvInfoBarAction}
|
|
44
|
+
* - {@link AppleTvContextualAction}
|
|
45
|
+
* - {@link AppleTvTransportBarPopupMenu}
|
|
46
|
+
*
|
|
47
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience | Customizing the tvOS Playback Experience}.
|
|
48
|
+
*
|
|
49
|
+
* @group Components
|
|
50
|
+
*/
|
|
51
|
+
declare const AppleTvPlayerControls: React.FC<AppleTvPlayerControlsProps>;
|
|
52
|
+
export default AppleTvPlayerControls;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React, { createContext } from 'react';
|
|
2
|
+
import { BaseEventEmitter, usePlayer } from '@castlabs/react-native-prestoplay';
|
|
3
|
+
import { AVPlayerViewControllerExtension } from '../AVPlayerViewControllerExtension';
|
|
4
|
+
export const AppleTvPlayerControlsContext = createContext({
|
|
5
|
+
eventEmitter: new BaseEventEmitter(),
|
|
6
|
+
updateAction: (_actionId, _state, _title, _icon) => { },
|
|
7
|
+
addAction: () => { },
|
|
8
|
+
removeAction: () => { },
|
|
9
|
+
setPopupMenu: () => { },
|
|
10
|
+
removePopupMenu: () => { },
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
14
|
+
*
|
|
15
|
+
* Use the tvOS player UI to present custom controls in an
|
|
16
|
+
* {@link AVPlayerViewControllerProvider} by including this component as a child.
|
|
17
|
+
*
|
|
18
|
+
* This component serves as a **provider** for its child components, enabling
|
|
19
|
+
* integration of custom actions and menus within the tvOS player interface.
|
|
20
|
+
*
|
|
21
|
+
* Supported child components include:
|
|
22
|
+
* - {@link AppleTvTransportBarAction}
|
|
23
|
+
* - {@link AppleTvInfoBarAction}
|
|
24
|
+
* - {@link AppleTvContextualAction}
|
|
25
|
+
* - {@link AppleTvTransportBarPopupMenu}
|
|
26
|
+
*
|
|
27
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience | Customizing the tvOS Playback Experience}.
|
|
28
|
+
*
|
|
29
|
+
* @group Components
|
|
30
|
+
*/
|
|
31
|
+
const AppleTvPlayerControls = React.memo(({ children }) => {
|
|
32
|
+
const player = usePlayer();
|
|
33
|
+
const avPlayerExtension = player.getExtension(AVPlayerViewControllerExtension);
|
|
34
|
+
const addAction = (type, actionId, props) => {
|
|
35
|
+
avPlayerExtension.addAction(type, actionId, props);
|
|
36
|
+
};
|
|
37
|
+
const removeAction = (type, actionId) => {
|
|
38
|
+
avPlayerExtension.removeAction(type, actionId);
|
|
39
|
+
};
|
|
40
|
+
const updateAction = (actionId, state, title, icon) => {
|
|
41
|
+
avPlayerExtension.updateAction(actionId, state, title, icon);
|
|
42
|
+
};
|
|
43
|
+
const setPopupMenu = (menuId, popUpMenu) => {
|
|
44
|
+
avPlayerExtension.setPopupMenu(menuId, popUpMenu);
|
|
45
|
+
};
|
|
46
|
+
const removePopupMenu = (menuId) => {
|
|
47
|
+
avPlayerExtension.removePopupMenu(menuId);
|
|
48
|
+
};
|
|
49
|
+
return (<AppleTvPlayerControlsContext.Provider value={{
|
|
50
|
+
eventEmitter: avPlayerExtension.eventEmitter,
|
|
51
|
+
updateAction,
|
|
52
|
+
addAction,
|
|
53
|
+
removeAction,
|
|
54
|
+
setPopupMenu: setPopupMenu,
|
|
55
|
+
removePopupMenu,
|
|
56
|
+
}}>
|
|
57
|
+
{children}
|
|
58
|
+
</AppleTvPlayerControlsContext.Provider>);
|
|
59
|
+
});
|
|
60
|
+
export default AppleTvPlayerControls;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* AppleTvTransportBarActionProps defines the properties for an
|
|
4
|
+
* {@link AppleTvTransportBarAction}
|
|
5
|
+
*
|
|
6
|
+
* @group Type Aliases
|
|
7
|
+
*/
|
|
8
|
+
export type AppleTvTransportBarActionProps = {
|
|
9
|
+
/** The text of the transport bar action button. */
|
|
10
|
+
title: string;
|
|
11
|
+
/** The name of the image resource in the Xcode app project. */
|
|
12
|
+
icon: string;
|
|
13
|
+
/** The state of the info bar action button. */
|
|
14
|
+
state: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Action to be executed when the button is pressed.
|
|
17
|
+
*
|
|
18
|
+
* @param value - The action state string passed to the handler.
|
|
19
|
+
*/
|
|
20
|
+
onPress: (value: string) => void;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
24
|
+
*
|
|
25
|
+
* Displays custom controls in the transport bar of the tvOS player UI.
|
|
26
|
+
*
|
|
27
|
+
* If it is a children of an {@link AppleTvTransportBarPopupMenu}, the action is shown
|
|
28
|
+
* inside the popup menu. Otherwise, it is shown directly in the transport bar.
|
|
29
|
+
*
|
|
30
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience#Add-Custom-Transport-Bar-Items | Add Custom Transport Bar Items}.
|
|
31
|
+
*
|
|
32
|
+
* @group Components
|
|
33
|
+
*/
|
|
34
|
+
export declare const AppleTvTransportBarAction: React.FC<AppleTvTransportBarActionProps>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useContext, useEffect, useRef } from 'react';
|
|
2
|
+
import { AppleTvPlayerControlsContext } from './AppleTvPlayerControls.ios';
|
|
3
|
+
import { ActionType } from '../types/ActionType';
|
|
4
|
+
import uuid from 'uuid-random';
|
|
5
|
+
/**
|
|
6
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
7
|
+
*
|
|
8
|
+
* Displays custom controls in the transport bar of the tvOS player UI.
|
|
9
|
+
*
|
|
10
|
+
* If it is a children of an {@link AppleTvTransportBarPopupMenu}, the action is shown
|
|
11
|
+
* inside the popup menu. Otherwise, it is shown directly in the transport bar.
|
|
12
|
+
*
|
|
13
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience#Add-Custom-Transport-Bar-Items | Add Custom Transport Bar Items}.
|
|
14
|
+
*
|
|
15
|
+
* @group Components
|
|
16
|
+
*/
|
|
17
|
+
export const AppleTvTransportBarAction = props => {
|
|
18
|
+
const { eventEmitter: eventEmitter, updateAction, addAction, removeAction, } = useContext(AppleTvPlayerControlsContext);
|
|
19
|
+
const actionId = useRef(uuid());
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const _actionId = actionId.current;
|
|
22
|
+
addAction(ActionType.TransportBar, _actionId, props);
|
|
23
|
+
return () => {
|
|
24
|
+
removeAction(ActionType.TransportBar, _actionId);
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
const onPressRef = useRef(props.onPress);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
onPressRef.current = props.onPress;
|
|
30
|
+
}, [props.onPress]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const _actionId = actionId.current;
|
|
33
|
+
const onEvent = (event) => {
|
|
34
|
+
const details = event.details;
|
|
35
|
+
onPressRef.current(details.data);
|
|
36
|
+
};
|
|
37
|
+
eventEmitter.addEventListener(_actionId, onEvent);
|
|
38
|
+
return () => {
|
|
39
|
+
eventEmitter.removeEventListener(_actionId, onEvent);
|
|
40
|
+
};
|
|
41
|
+
}, [eventEmitter]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const _actionId = actionId.current;
|
|
44
|
+
updateAction(_actionId, props.state, props.title, props.icon);
|
|
45
|
+
}, [props.title, props.icon, props.state, updateAction]);
|
|
46
|
+
return null;
|
|
47
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import SubMenu from '../types/SubMenu';
|
|
4
|
+
type AppleTvTransportBarPopupMenuContextType = {
|
|
5
|
+
addSubMenu: (ids: string, subMenu: SubMenu) => void;
|
|
6
|
+
removeSubmenu: (id: string) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const AppleTvTransportBarPopupMenuContext: React.Context<AppleTvTransportBarPopupMenuContextType>;
|
|
9
|
+
/**
|
|
10
|
+
* AppleTvTransportBarPopupMenuProps defines the properties for an
|
|
11
|
+
* {@link AppleTvTransportBarPopupMenu}.
|
|
12
|
+
*
|
|
13
|
+
* Its children can be any of the following components:
|
|
14
|
+
* - {@link AppleTvTransportBarAction}
|
|
15
|
+
* - {@link AppleTvTransportBarSubMenu}
|
|
16
|
+
*
|
|
17
|
+
* @group Type Aliases
|
|
18
|
+
*/
|
|
19
|
+
export type AppleTvTransportBarPopupMenuProps = {
|
|
20
|
+
/** The popup menu title. */
|
|
21
|
+
title: string;
|
|
22
|
+
/** The name of the image resource in the Xcode app.*/
|
|
23
|
+
icon: string;
|
|
24
|
+
/** The popup menu children, which can be {@link AppleTvTransportBarAction}
|
|
25
|
+
* or {@link AppleTvTransportBarSubMenu} components.
|
|
26
|
+
*/
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
31
|
+
*
|
|
32
|
+
* The AppleTvTransportBarPopupMenu component allows grouping multiple
|
|
33
|
+
* {@link AppleTvTransportBarAction} and {@link AppleTvTransportBarSubMenu}
|
|
34
|
+
* into a popup menu displayed in the tvOS player UI transport bar.
|
|
35
|
+
*
|
|
36
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience#Add-Custom-Transport-Bar-Items | Add Custom Transport Bar Items}.
|
|
37
|
+
*
|
|
38
|
+
* @group Components
|
|
39
|
+
*/
|
|
40
|
+
export declare const AppleTvTransportBarPopupMenu: React.FC<AppleTvTransportBarPopupMenuProps>;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React, { createContext, useCallback, useContext, useEffect, useRef, } from 'react';
|
|
2
|
+
import { AppleTvPlayerControlsContext } from './AppleTvPlayerControls.ios';
|
|
3
|
+
import { ActionType } from '../types/ActionType';
|
|
4
|
+
import uuid from 'uuid-random';
|
|
5
|
+
export const AppleTvTransportBarPopupMenuContext = createContext({
|
|
6
|
+
addSubMenu: () => { },
|
|
7
|
+
removeSubmenu: () => { },
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
11
|
+
*
|
|
12
|
+
* The AppleTvTransportBarPopupMenu component allows grouping multiple
|
|
13
|
+
* {@link AppleTvTransportBarAction} and {@link AppleTvTransportBarSubMenu}
|
|
14
|
+
* into a popup menu displayed in the tvOS player UI transport bar.
|
|
15
|
+
*
|
|
16
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience#Add-Custom-Transport-Bar-Items | Add Custom Transport Bar Items}.
|
|
17
|
+
*
|
|
18
|
+
* @group Components
|
|
19
|
+
*/
|
|
20
|
+
export const AppleTvTransportBarPopupMenu = React.memo(props => {
|
|
21
|
+
const { eventEmitter: eventEmitter, updateAction, setPopupMenu: setPopupMenu, removePopupMenu, } = useContext(AppleTvPlayerControlsContext);
|
|
22
|
+
const menuId = useRef(uuid());
|
|
23
|
+
const transportBarActions = useRef(new Map());
|
|
24
|
+
const subMenus = useRef(new Map());
|
|
25
|
+
const update = useCallback(() => {
|
|
26
|
+
const popupMenu = {
|
|
27
|
+
title: props.title,
|
|
28
|
+
icon: props.icon,
|
|
29
|
+
transportBarActions: Array.from(transportBarActions.current.entries()).map(([id, value]) => ({
|
|
30
|
+
...value,
|
|
31
|
+
id, // add the map key as a property
|
|
32
|
+
})),
|
|
33
|
+
subMenus: Array.from(subMenus.current.entries()).map(([id, value]) => ({
|
|
34
|
+
...value,
|
|
35
|
+
id, // add the map key as a property
|
|
36
|
+
})),
|
|
37
|
+
};
|
|
38
|
+
setPopupMenu(menuId.current, popupMenu);
|
|
39
|
+
}, [props.icon, props.title, setPopupMenu]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const _menuId = menuId.current;
|
|
42
|
+
return () => {
|
|
43
|
+
removePopupMenu(_menuId);
|
|
44
|
+
};
|
|
45
|
+
}, [removePopupMenu]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
update();
|
|
48
|
+
}, [props.title, props.icon, update]);
|
|
49
|
+
const addActionInternal = (type, actionId, actionProps) => {
|
|
50
|
+
if (type === ActionType.TransportBar) {
|
|
51
|
+
const transportAction = actionProps;
|
|
52
|
+
transportBarActions.current.set(actionId, transportAction);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const removeActionInternal = (type, actionId) => {
|
|
56
|
+
transportBarActions.current.delete(actionId);
|
|
57
|
+
};
|
|
58
|
+
const addSubMenu = (subMenuId, subMenu) => {
|
|
59
|
+
subMenus.current.set(subMenuId, subMenu);
|
|
60
|
+
update();
|
|
61
|
+
};
|
|
62
|
+
const removeSubmenu = (subMenuId) => {
|
|
63
|
+
subMenus.current.delete(subMenuId);
|
|
64
|
+
update();
|
|
65
|
+
};
|
|
66
|
+
return (<AppleTvPlayerControlsContext.Provider value={{
|
|
67
|
+
eventEmitter: eventEmitter,
|
|
68
|
+
updateAction,
|
|
69
|
+
addAction: addActionInternal,
|
|
70
|
+
removeAction: removeActionInternal,
|
|
71
|
+
setPopupMenu: () => { },
|
|
72
|
+
removePopupMenu: () => { },
|
|
73
|
+
}}>
|
|
74
|
+
<AppleTvTransportBarPopupMenuContext.Provider value={{
|
|
75
|
+
addSubMenu,
|
|
76
|
+
removeSubmenu,
|
|
77
|
+
}}>
|
|
78
|
+
{props.children}
|
|
79
|
+
</AppleTvTransportBarPopupMenuContext.Provider>
|
|
80
|
+
</AppleTvPlayerControlsContext.Provider>);
|
|
81
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
type AppleTvTransportBarSubMenuContextType = {
|
|
3
|
+
addMenuItem: (title: string, value: string) => void;
|
|
4
|
+
removeMenuItem: (title: string) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const AppleTvTransportBarSubMenuContext: React.Context<AppleTvTransportBarSubMenuContextType>;
|
|
7
|
+
/**
|
|
8
|
+
* Type definition for the properties of an {@link AppleTvTransportBarSubMenu}
|
|
9
|
+
* component.
|
|
10
|
+
*
|
|
11
|
+
* @group Type Aliases
|
|
12
|
+
*/
|
|
13
|
+
export type AppleTvTransportBarSubMenuProps = {
|
|
14
|
+
/** The submenu title. */
|
|
15
|
+
title: string;
|
|
16
|
+
/** The name of the image resource in the Xcode app.*/
|
|
17
|
+
icon: string;
|
|
18
|
+
/** The default value selected of the submenu. */
|
|
19
|
+
defaultValue: string;
|
|
20
|
+
/** The submenu children, which can be {@link AppleTvTransportBarSubMenuItem} components. */
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* The action to be executed when a submenu item is selected.
|
|
24
|
+
* @param value - The value of the selected submenu item.
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
onPress: (value: string) => void;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
31
|
+
*
|
|
32
|
+
* The AppleTvTransportBarSubMenu component allows grouping multiple
|
|
33
|
+
* {@link AppleTvTransportBarSubMenuItem} components into a submenu displayed
|
|
34
|
+
* in a popup menu in the tvOS player UI transport bar.
|
|
35
|
+
*
|
|
36
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience#Add-Custom-Transport-Bar-Items | Add Custom Transport Bar Items}.
|
|
37
|
+
*
|
|
38
|
+
* @group Components
|
|
39
|
+
*/
|
|
40
|
+
export declare const AppleTvTransportBarSubMenu: React.FC<AppleTvTransportBarSubMenuProps>;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React, { createContext, useCallback, useContext, useEffect, useRef, } from 'react';
|
|
2
|
+
import { AppleTvPlayerControlsContext } from './AppleTvPlayerControls.ios';
|
|
3
|
+
import { AppleTvTransportBarPopupMenuContext } from './AppleTvTransportBarPopupMenu.ios';
|
|
4
|
+
import uuid from 'uuid-random';
|
|
5
|
+
export const AppleTvTransportBarSubMenuContext = createContext({
|
|
6
|
+
addMenuItem: () => { },
|
|
7
|
+
removeMenuItem: () => { },
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
11
|
+
*
|
|
12
|
+
* The AppleTvTransportBarSubMenu component allows grouping multiple
|
|
13
|
+
* {@link AppleTvTransportBarSubMenuItem} components into a submenu displayed
|
|
14
|
+
* in a popup menu in the tvOS player UI transport bar.
|
|
15
|
+
*
|
|
16
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience#Add-Custom-Transport-Bar-Items | Add Custom Transport Bar Items}.
|
|
17
|
+
*
|
|
18
|
+
* @group Components
|
|
19
|
+
*/
|
|
20
|
+
export const AppleTvTransportBarSubMenu = props => {
|
|
21
|
+
const { eventEmitter } = useContext(AppleTvPlayerControlsContext);
|
|
22
|
+
const { addSubMenu, removeSubmenu } = useContext(AppleTvTransportBarPopupMenuContext);
|
|
23
|
+
const subMenuId = useRef(uuid());
|
|
24
|
+
const subMenuItems = useRef(new Map());
|
|
25
|
+
const update = useCallback(() => {
|
|
26
|
+
addSubMenu(subMenuId.current, {
|
|
27
|
+
id: subMenuId.current,
|
|
28
|
+
title: props.title,
|
|
29
|
+
defaultValue: props.defaultValue,
|
|
30
|
+
menuItems: Array.from(subMenuItems.current.entries()).map(([title, value]) => ({ value, title })),
|
|
31
|
+
});
|
|
32
|
+
}, [addSubMenu, props.title, props.defaultValue]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const _subMenuId = subMenuId.current;
|
|
35
|
+
return () => {
|
|
36
|
+
if (_subMenuId !== null) {
|
|
37
|
+
removeSubmenu(_subMenuId);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}, [removeSubmenu]);
|
|
41
|
+
const onPressRef = useRef(props.onPress);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
onPressRef.current = props.onPress;
|
|
44
|
+
}, [props.onPress]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const _subMenuId = subMenuId.current;
|
|
47
|
+
const onEvent = (event) => {
|
|
48
|
+
const details = event.details;
|
|
49
|
+
onPressRef.current(details.data);
|
|
50
|
+
};
|
|
51
|
+
eventEmitter.addEventListener(_subMenuId, onEvent);
|
|
52
|
+
return () => {
|
|
53
|
+
eventEmitter.removeEventListener(_subMenuId, onEvent);
|
|
54
|
+
};
|
|
55
|
+
}, [eventEmitter]);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
update();
|
|
58
|
+
}, [props.title, props.icon, props.defaultValue, update]);
|
|
59
|
+
const addMenuItem = (title, value) => {
|
|
60
|
+
subMenuItems.current.set(title, value);
|
|
61
|
+
update();
|
|
62
|
+
};
|
|
63
|
+
const removeMenuItem = (title) => {
|
|
64
|
+
subMenuItems.current.delete(title);
|
|
65
|
+
update();
|
|
66
|
+
};
|
|
67
|
+
return (<AppleTvTransportBarSubMenuContext.Provider value={{ addMenuItem, removeMenuItem }}>
|
|
68
|
+
{props.children}
|
|
69
|
+
</AppleTvTransportBarSubMenuContext.Provider>);
|
|
70
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* The properties for an {@link AppleTvTransportBarSubMenuItem} component.
|
|
4
|
+
*
|
|
5
|
+
* @group Type Aliases
|
|
6
|
+
*/
|
|
7
|
+
export type AppleTvTransportBarSubMenuItemProps = {
|
|
8
|
+
/** The text of the submenu item. */
|
|
9
|
+
title: string;
|
|
10
|
+
/** The value of the submenu item. */
|
|
11
|
+
value: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
15
|
+
*
|
|
16
|
+
* The AppleTvTransportBarSubMenuItem component represents an item inside
|
|
17
|
+
* an {@link AppleTvTransportBarSubMenu} submenu displayed in a popup menu
|
|
18
|
+
* in the tvOS player UI transport bar.
|
|
19
|
+
*
|
|
20
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience#Add-Custom-Transport-Bar-Items | Add Custom Transport Bar Items}.
|
|
21
|
+
*
|
|
22
|
+
* @group Components
|
|
23
|
+
*/
|
|
24
|
+
export declare const AppleTvTransportBarSubMenuItem: React.FC<AppleTvTransportBarSubMenuItemProps>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useContext, useEffect } from 'react';
|
|
2
|
+
import { AppleTvTransportBarSubMenuContext } from './AppleTvTransportBarSubMenu.ios';
|
|
3
|
+
/**
|
|
4
|
+
* **⚠️ This component is only supported on tvOS.**
|
|
5
|
+
*
|
|
6
|
+
* The AppleTvTransportBarSubMenuItem component represents an item inside
|
|
7
|
+
* an {@link AppleTvTransportBarSubMenu} submenu displayed in a popup menu
|
|
8
|
+
* in the tvOS player UI transport bar.
|
|
9
|
+
*
|
|
10
|
+
* For more details, see Apple documentation: {@link https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience#Add-Custom-Transport-Bar-Items | Add Custom Transport Bar Items}.
|
|
11
|
+
*
|
|
12
|
+
* @group Components
|
|
13
|
+
*/
|
|
14
|
+
export const AppleTvTransportBarSubMenuItem = props => {
|
|
15
|
+
const { addMenuItem, removeMenuItem } = useContext(AppleTvTransportBarSubMenuContext);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
addMenuItem(props.title, props.value);
|
|
18
|
+
return () => {
|
|
19
|
+
removeMenuItem(props.title);
|
|
20
|
+
};
|
|
21
|
+
}, [props.title, props.value, addMenuItem, removeMenuItem]);
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type { AVPlayerViewControllerProviderProps } from './components/AVPlayerViewControllerProvider.ios';
|
|
2
|
+
export type { AppleTvTransportBarSubMenuItemProps } from './components/AppleTvTransportBarSubMenuItem.ios';
|
|
3
|
+
export type { AppleTvContextualActionProps } from './components/AppleTvContextualAction.ios';
|
|
4
|
+
export type { AppleTvInfoBarActionProps } from './components/AppleTvInfoBarAction.ios';
|
|
5
|
+
export type { AppleTvTransportBarActionProps } from './components/AppleTvTransportBarAction.ios';
|
|
6
|
+
export type { AppleTvTransportBarPopupMenuProps } from './components/AppleTvTransportBarPopupMenu.ios';
|
|
7
|
+
export type { AppleTvTransportBarSubMenuProps } from './components/AppleTvTransportBarSubMenu.ios';
|
|
8
|
+
export type { AppleTvPlayerControlsProps } from './components/AppleTvPlayerControls.ios';
|
|
9
|
+
export { default as AVPlayerViewControllerPlugin } from './AVPlayerViewControllerPlugin';
|
|
10
|
+
export { AVPlayerViewControllerProvider } from './components/AVPlayerViewControllerProvider.ios';
|
|
11
|
+
export { default as AppleTvPlayerControls } from './components/AppleTvPlayerControls.ios';
|
|
12
|
+
export { AppleTvTransportBarAction } from './components/AppleTvTransportBarAction.ios';
|
|
13
|
+
export { AppleTvTransportBarPopupMenu } from './components/AppleTvTransportBarPopupMenu.ios';
|
|
14
|
+
export { AppleTvTransportBarSubMenu } from './components/AppleTvTransportBarSubMenu.ios';
|
|
15
|
+
export { AppleTvTransportBarSubMenuItem } from './components/AppleTvTransportBarSubMenuItem.ios';
|
|
16
|
+
export { AppleTvInfoBarAction } from './components/AppleTvInfoBarAction.ios';
|
|
17
|
+
export { AppleTvContextualAction } from './components/AppleTvContextualAction.ios';
|