Skip to content

Commit cde669a

Browse files
committed
fix: 🐛 fire onMount event before attempting to play video
1 parent fca598f commit cde669a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/Media/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,20 @@ export class Media<P extends IMediaProps<M>, S extends IMediaState, M extends IM
8787
};
8888

8989
componentDidMount () {
90-
if (this.props.autoPlay && this.el.paused) {
91-
this.play();
92-
}
90+
this.el.setAttribute('playsinline', '');
9391

9492
this.setState({
9593
volume: this.el.volume,
9694
muted: this.el.muted,
9795
});
9896

9997
this.event('onMount')(this);
98+
99+
// We run this code after `onMount` event to allow user
100+
// to set `playsinline` attribute, if needed.
101+
if (this.props.autoPlay && this.el.paused) {
102+
this.play();
103+
}
100104
}
101105

102106
componentWillUnmount () {
@@ -251,9 +255,9 @@ export class Media<P extends IMediaProps<M>, S extends IMediaState, M extends IM
251255
const {tag = this.tag, children, render, noJs, onMount, onUnmount, ...rest} = props as any;
252256

253257
return h(tag, {
258+
controls: false,
254259
...rest,
255260
ref: this.ref,
256-
controls: false,
257261
onAbort: event('onAbort'),
258262
onCanPlay: this.onCanPlay,
259263
onCanPlayThrough: event('onCanPlayThrough'),

src/Video/__story__/story.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,17 @@ storiesOf('UI/Video', module)
7373
border: '1px solid tomato'
7474
}}
7575
/>
76+
)
77+
.add('autoplay on iOS', () =>
78+
<Video
79+
src={src}
80+
autoPlay
81+
onMount={(event, {el}) => {
82+
el.setAttribute('playsinline', '');
83+
}}
84+
style={{
85+
width: 400,
86+
border: '1px solid tomato'
87+
}}
88+
/>
7689
);

0 commit comments

Comments
 (0)