Skip to content

Commit 4e8f3c9

Browse files
authored
feat(video): 兼容taro Component属性 (#3185)
* feat(video): 兼容taro Component属性 * refactor: 优化逻辑
1 parent f80257b commit 4e8f3c9

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

src/packages/video/video.taro.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { FunctionComponent } from 'react'
22
import classNames from 'classnames'
3-
import { Video as VideoTaro, View } from '@tarojs/components'
3+
import { Video as VideoTaro, VideoProps, View } from '@tarojs/components'
44
import { mergeProps } from '@/utils/merge-props'
55
import { TaroVideoProps } from '@/types'
66

@@ -19,30 +19,43 @@ const defaultProps = {
1919
},
2020
} as TaroVideoProps
2121

22-
const classPrefix = `nut-video`
23-
export const Video: FunctionComponent<Partial<TaroVideoProps>> = (props) => {
22+
const classPrefix = 'nut-video'
23+
24+
export const Video: FunctionComponent<Partial<TaroVideoProps & VideoProps>> = (
25+
props
26+
) => {
2427
const {
2528
source,
2629
options,
2730
className,
2831
style,
32+
src,
33+
muted,
34+
loop,
35+
poster,
36+
controls,
37+
autoplay,
2938
onPlay,
3039
onPause,
3140
onPlayEnd,
3241
...restProps
3342
} = mergeProps(defaultProps, props)
43+
3444
const classes = classNames(classPrefix, className)
3545

46+
const effectiveControls =
47+
props.options?.controls ?? controls ?? options.controls
48+
3649
return (
3750
<View className={classes} style={style}>
3851
<VideoTaro
3952
className={`${classPrefix}-player`}
40-
muted={options.muted}
41-
autoplay={options.autoplay}
42-
loop={options.loop}
43-
poster={options.poster}
44-
controls={options.controls}
45-
src={source.src}
53+
muted={options.muted || muted}
54+
autoplay={options.autoplay || autoplay}
55+
loop={options.loop || loop}
56+
poster={options.poster || poster}
57+
controls={effectiveControls}
58+
src={source.src || (src as string)}
4659
onPlay={onPlay}
4760
onPause={onPause}
4861
onEnded={onPlayEnd}

src/sites/sites-react/doc/docs/taro/migrate-from-v2.en-US.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,11 @@ If your project uses these components, please read the documentation carefully a
290290
[//]: # '#### Table'
291291
[//]: # '#### Tag'
292292
[//]: # '#### TrendArrow'
293-
[//]: # '#### Video'
293+
294+
#### Video
295+
296+
- Compatible with Taro Component properties, you can directly use attributes such as src, loop, and so on.
297+
294298
[//]: # '#### VirtualList'
295299
[//]: # '#### WaterMark'
296300
[//]: # '### 特色组件'

src/sites/sites-react/doc/docs/taro/migrate-from-v2.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,11 @@ plugins: [
306306
[//]: # '#### Table'
307307
[//]: # '#### Tag'
308308
[//]: # '#### TrendArrow'
309-
[//]: # '#### Video'
309+
310+
#### Video
311+
312+
- 兼容 Taro Component 属性,直接可以使用 `src``loop` 等属性。
313+
310314
[//]: # '#### VirtualList'
311315
[//]: # '#### WaterMark'
312316
[//]: # '### 特色组件'

0 commit comments

Comments
 (0)