Skip to content

Commit

Permalink
fix(player): better handle ios controls
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Nov 6, 2023
1 parent f1837ad commit 5820094
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
7 changes: 5 additions & 2 deletions packages/react/src/components/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import * as React from 'react';

import {
createReactComponent,
useReactContext,
useSignal,
useStateContext,
type ReactElementProps,
} from 'maverick.js/react';
import { mediaState } from 'vidstack';
import { mediaContext, mediaState } from 'vidstack';

import { MediaProviderInstance } from './primitives/instances';

Expand Down Expand Up @@ -62,7 +63,9 @@ interface MediaOutletProps extends React.HTMLAttributes<HTMLMediaElement> {
function MediaOutlet({ provider, ...props }: MediaOutletProps) {
const { controls, crossorigin, poster } = useStateContext(mediaState),
{ loader } = provider.$state,
{ $iosControls: iosControls } = useReactContext(mediaContext)!,
$controls = useSignal(controls),
$iosControls = useSignal(iosControls),
$crossorigin = useSignal(crossorigin),
$poster = useSignal(poster),
$loader = useSignal(loader),
Expand All @@ -71,7 +74,7 @@ function MediaOutlet({ provider, ...props }: MediaOutletProps) {
return $mediaType
? React.createElement($mediaType === 'audio' ? 'audio' : 'video', {
...props,
controls: $controls,
controls: $controls || $iosControls,
crossOrigin: typeof $crossorigin === 'boolean' ? '' : $crossorigin,
poster: $mediaType === 'video' && $controls && $poster ? $poster : null,
preload: 'none',
Expand Down
4 changes: 2 additions & 2 deletions packages/vidstack/src/components/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,12 @@ export class MediaPlayer
}

private _isIOSControls() {
const { controls, playsinline, started, fullscreen } = this.$state;
const { playsinline, fullscreen } = this.$state;
return (
IS_IPHONE &&
!canFullscreen() &&
this.$state.mediaType() === 'video' &&
((controls() && !playsinline()) || (!playsinline() && started()) || fullscreen())
(!playsinline() || fullscreen())
);
}

Expand Down
5 changes: 3 additions & 2 deletions packages/vidstack/src/components/ui/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ export class Controls extends Component<ControlsProps, {}, ControlsEvents> {
private _hideControls() {
if (!this.el) return;

const { controls } = this._media.$state,
isHidden = controls() || this._media.$iosControls();
const { $iosControls } = this._media,
{ controls } = this._media.$state,
isHidden = controls() || $iosControls();

setAttribute(this.el, 'aria-hidden', isHidden ? 'true' : null);
setStyle(this.el, 'display', isHidden ? 'none' : null);
Expand Down
1 change: 1 addition & 0 deletions packages/vidstack/src/core/state/media-state-sync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { effect } from 'maverick.js';

import { MediaPlayerController } from '../api/player-controller';

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/vidstack/src/elements/define/provider-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ export class MediaProviderElement extends Host(HTMLElement, MediaProvider) {
: document.createElement('video');

const { controls, crossorigin, poster } = this._media.$state,
{ $iosControls } = this._media,
$poster = computed(() => (poster() && controls() ? poster() : null));

effect(() => {
setAttribute(video, 'controls', controls());
setAttribute(video, 'controls', controls() || $iosControls());
setAttribute(video, 'crossorigin', crossorigin());
setAttribute(video, 'poster', $poster());
});
Expand Down

0 comments on commit 5820094

Please sign in to comment.