-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #343 from THEOplayer/feature/android_rendering_target
Feature/android rendering target
- Loading branch information
Showing
13 changed files
with
214 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { useState } from 'react'; | ||
import type { StyleProp, ViewStyle } from 'react-native'; | ||
import { MenuRadioButton, MenuView, ScrollableMenu, SubMenuWithButton } from '@theoplayer/react-native-ui'; | ||
|
||
export interface Option<T> { | ||
label: string; | ||
value: T; | ||
} | ||
|
||
export interface CustomSubMenuProps<T> { | ||
/** | ||
* Overrides for the style of the menu. | ||
*/ | ||
menuStyle?: StyleProp<ViewStyle>; | ||
|
||
/** | ||
* The label displayed in the menu. | ||
*/ | ||
label: string; | ||
|
||
/** | ||
* The title displayed when opening the menu. | ||
*/ | ||
title: string; | ||
|
||
/** | ||
* List of available options. | ||
*/ | ||
options: Option<T>[]; | ||
|
||
/** | ||
* Get the current active option. | ||
*/ | ||
currentOption: () => T; | ||
|
||
/** | ||
* Called when a new option was selected. | ||
*/ | ||
onOptionSelected?: (option: Option<T>) => void; | ||
} | ||
|
||
/** | ||
* A button component that opens a custom selection menu for the `react-native-theoplayer` UI. | ||
*/ | ||
export function CustomSubMenu<T>(props: CustomSubMenuProps<T>) { | ||
const { options, label } = props; | ||
const currentLabel = options.find(v => v.value == props.currentOption())?.label ?? ""; | ||
const createMenu = () => { | ||
return <CustomSelectionView {...props}/>; | ||
}; | ||
return <SubMenuWithButton menuConstructor={createMenu} label={label} preview={currentLabel} />; | ||
} | ||
|
||
function CustomSelectionView<T>(props: CustomSubMenuProps<T>) { | ||
const { menuStyle, options } = props; | ||
const currentOption = options.find(v => v.value == props.currentOption()); | ||
const [selectedOption, setSelectedOption] = useState<Option<T> | undefined>(currentOption); | ||
|
||
const onSelectOption = (id: number | undefined): void => { | ||
if (id !== undefined) { | ||
const newSelection = id < options.length ? options[id] : undefined; | ||
if (newSelection) { | ||
setSelectedOption(newSelection); | ||
props.onOptionSelected?.(newSelection); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<MenuView | ||
style={menuStyle} | ||
menu={ | ||
<ScrollableMenu | ||
title={props.title} | ||
items={options.map((option, id) => ( | ||
<MenuRadioButton | ||
key={id} | ||
label={option.label} | ||
uid={id} | ||
onSelect={onSelectOption} | ||
selected={selectedOption?.value === option.value}></MenuRadioButton> | ||
))} | ||
/> | ||
} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { CustomSubMenu, Option } from './CustomSubMenu'; | ||
import { RenderingTarget } from 'react-native-theoplayer'; | ||
import * as React from 'react'; | ||
import type { StyleProp, ViewStyle } from 'react-native'; | ||
import { useContext } from 'react'; | ||
import { PlayerContext } from '@theoplayer/react-native-ui'; | ||
|
||
export interface RenderingTargetSubMenuProps { | ||
/** | ||
* Overrides for the style of the menu. | ||
*/ | ||
menuStyle?: StyleProp<ViewStyle>; | ||
} | ||
|
||
export function RenderingTargetSubMenu(props?: RenderingTargetSubMenuProps) { | ||
const ctx = useContext(PlayerContext); | ||
|
||
return <CustomSubMenu | ||
title={'Rendering Target'} | ||
menuStyle={props?.menuStyle} | ||
label={'Display'} | ||
options={[{ label: 'Surface', value: RenderingTarget.SURFACE_VIEW }, { | ||
label: 'Texture', | ||
value: RenderingTarget.TEXTURE_VIEW, | ||
}]} | ||
onOptionSelected={(option: Option<RenderingTarget>) => { | ||
ctx.player.renderingTarget = option.value; | ||
}} | ||
currentOption={() => ctx.player.renderingTarget ?? RenderingTarget.SURFACE_VIEW} />; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.