Skip to content

Commit

Permalink
feat(player): new noGestures default layout prop
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Dec 24, 2023
1 parent 219b90e commit 2fff957
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/react/src/components/layouts/default/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface DefaultLayoutContext {
slots?: unknown;
sliderChaptersMinWidth: number;
disableTimeSlider: boolean;
noGestures?: boolean;
}

export function useDefaultLayoutLang(word: keyof DefaultLayoutTranslations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ export interface DefaultMediaLayoutProps<Slots = unknown> extends PrimitiveProps
* Whether the time slider should be disabled.
*/
disableTimeSlider?: boolean;
/**
* Whether all gestures such as pressing to play or seek should not be active.
*/
noGestures?: boolean;
}

export interface CreateDefaultMediaLayout {
Expand Down Expand Up @@ -162,6 +166,7 @@ export function createDefaultMediaLayout({
hideQualityBitrate = false,
sliderChaptersMinWidth = 600,
disableTimeSlider = false,
noGestures = false,
slots,
children,
...props
Expand Down Expand Up @@ -202,6 +207,7 @@ export function createDefaultMediaLayout({
slots,
sliderChaptersMinWidth,
disableTimeSlider,
noGestures,
Icons: icons,
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ DefaultVideoStartDuration.displayName = 'DefaultVideoStartDuration';
* -----------------------------------------------------------------------------------------------*/

function DefaultVideoGestures() {
const { noGestures } = React.useContext(DefaultLayoutContext);

if (noGestures) return null;

return (
<div className="vds-gestures">
<Gesture className="vds-gesture" event="pointerup" action="toggle:paused" />
Expand Down
8 changes: 8 additions & 0 deletions packages/vidstack/src/components/layouts/default-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class DefaultLayout extends Component<DefaultLayoutProps> {
noModal: false,
sliderChaptersMinWidth: 600,
disableTimeSlider: false,
noGestures: false,
};

// slider-chapters-min-width
Expand Down Expand Up @@ -50,6 +51,7 @@ export class DefaultLayout extends Component<DefaultLayoutProps> {
noModal,
sliderChaptersMinWidth,
disableTimeSlider,
noGestures,
} = this.$props;

this._whenQueryList = PlayerQueryList.create(when);
Expand All @@ -69,6 +71,7 @@ export class DefaultLayout extends Component<DefaultLayoutProps> {
noModal,
sliderChaptersMinWidth,
disableTimeSlider,
noGestures,
get menuContainer() {
return self.menuContainer;
},
Expand Down Expand Up @@ -154,6 +157,10 @@ export interface DefaultLayoutProps {
* Whether the time slider should be disabled.
*/
disableTimeSlider?: boolean;
/**
* Whether all gestures such as press to play or seek should not be active.
*/
noGestures?: boolean;
}

export interface DefaultLayoutContext {
Expand All @@ -165,6 +172,7 @@ export interface DefaultLayoutContext {
sliderChaptersMinWidth: ReadSignal<DefaultLayoutProps['sliderChaptersMinWidth']>;
menuContainer: HTMLElement | null;
disableTimeSlider: ReadSignal<boolean>;
noGestures: ReadSignal<boolean>;
}

export interface DefaultLayoutTranslations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {

export function DefaultVideoLayoutLarge() {
return html`
${DefaultVideoGestures()}${DefaultBufferingIndicator()}
${$computed(DefaultVideoGestures)}${DefaultBufferingIndicator()}
<media-captions class="vds-captions"></media-captions>
<div class="vds-scrim"></div>
Expand Down Expand Up @@ -131,7 +131,9 @@ function DefaultVideoMenus() {
}

function DefaultVideoGestures() {
return html`
const { noGestures } = useDefaultLayoutContext();

const Gestures = html`
<div class="vds-gestures">
<media-gesture class="vds-gesture" event="pointerup" action="toggle:paused"></media-gesture>
<media-gesture class="vds-gesture" event="pointerup" action="toggle:controls"></media-gesture>
Expand All @@ -144,4 +146,6 @@ function DefaultVideoGestures() {
<media-gesture class="vds-gesture" event="dblpointerup" action="seek:10"></media-gesture>
</div>
`;

return noGestures() ? null : Gestures;
}

0 comments on commit 2fff957

Please sign in to comment.