Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(video): cross-platform compatibility #2720

Merged
merged 22 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/nutui-taro-demo/src/pages/index/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Taro from '@tarojs/taro'
import { View, Image, Text, ScrollView, Button, Input } from '@tarojs/components'
import { View, Image, Text, ScrollView, Button, Input, Video } from '@tarojs/components'
import pkg from '@/packages/../config.json'
import packageJson from '@/packages/../../package.json'
import './index.scss'
Expand All @@ -10,7 +10,7 @@ const navs = pkg.nav


// hack taro load button xml
console.log(Button, Input )
console.log(Button, Input, Video )
Alex-huxiyang marked this conversation as resolved.
Show resolved Hide resolved

// try {
// console.log('xxx', Schema)
Expand Down
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@
"author": "swag~jun"
},
{
"version": "2.0.0",
"version": "3.0.0",
"name": "Video",
"type": "component",
"cName": "视频播放器",
Expand Down
9 changes: 7 additions & 2 deletions src/packages/trendarrow/demo.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Demo5 from './demos/taro/demo5'
import Demo6 from './demos/taro/demo6'
import Demo7 from './demos/taro/demo7'
import Demo8 from './demos/taro/demo8'
import { harmonyAndRn } from '@/utils/platform-taro'

const TrendArrowDemo = () => {
const [translated] = useTranslate({
Expand Down Expand Up @@ -64,8 +65,12 @@ const TrendArrowDemo = () => {
<Demo6 />
<View className="h2">{translated.title7}</View>
<Demo7 />
<View className="h2">{translated.title8}</View>
<Demo8 />
{!harmonyAndRn() && (
<>
<View className="h2">{translated.title8}</View>
<Demo8 />
</>
)}
</ScrollView>
</>
)
Expand Down
4 changes: 2 additions & 2 deletions src/packages/trendarrow/trendarrow.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const defaultProps = {
left: false,
sync: true,
color: '#333',
riseColor: harmony() ? '#ff0f23' : 'var(--nutui-brand-6)',
dropColor: harmony() ? '#14cc33' : 'var(--nutui-secondary-1)',
riseColor: harmony() ? '#ff0f23' : '#ff0f23',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要拉一下最新的代码~

dropColor: harmony() ? '#14cc33' : '#14cc33',
riseIcon: null,
dropIcon: null,
} as TrendArrowProps
Expand Down
5 changes: 2 additions & 3 deletions src/packages/video/demo.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import Taro from '@tarojs/taro'
import { ScrollView, View } from '@tarojs/components'
import { useTranslate } from '@/sites/assets/locale/taro'

import Header from '@/sites/components/header'
import Demo1 from './demos/taro/demo1'
import Demo2 from './demos/taro/demo2'
Expand Down Expand Up @@ -44,9 +45,7 @@ const VideoDemo = () => {
return (
<>
<Header />
<ScrollView
className={`demo full ${Taro.getEnv() === 'WEB' ? 'web' : ''}`}
>
<ScrollView className={`demo ${Taro.getEnv() === 'WEB' ? 'web' : ''}`}>
<View className="h2">{translated.basic}</View>
<Demo1 />
<View className="h2">{translated.autoPlay}</View>
Expand Down
7 changes: 4 additions & 3 deletions src/packages/video/demos/taro/demo1.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState } from 'react'
import { Cell, Video } from '@nutui/nutui-react-taro'
import pxTransform from '@/utils/px-transform'

const Demo1 = () => {
const [source, setSource] = useState({
const [source] = useState({
src: 'https://storage.360buyimg.com/nutui/video/video_NutUI.mp4',
type: 'video/mp4',
})
Expand All @@ -14,14 +15,14 @@ const Demo1 = () => {
const playend = (elm: any) => console.log('playend', elm)
return (
<>
<Cell style={{ padding: '0' }}>
<Cell style={{ padding: 0 }}>
<Video
source={source}
options={options}
onPlay={play}
onPause={pause}
onPlayEnd={playend}
style={{ height: '163px' }}
style={{ height: pxTransform(163) }}
/>
</Cell>
Alex-huxiyang marked this conversation as resolved.
Show resolved Hide resolved
</>
Expand Down
7 changes: 4 additions & 3 deletions src/packages/video/demos/taro/demo2.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState } from 'react'
import { Cell, Video } from '@nutui/nutui-react-taro'
import pxTransform from '@/utils/px-transform'

const Demo2 = () => {
const [source, setSource] = useState({
const [source] = useState({
src: 'https://storage.360buyimg.com/nutui/video/video_NutUI.mp4',
type: 'video/mp4',
})
Expand All @@ -16,14 +17,14 @@ const Demo2 = () => {
const playend = (elm: any) => console.log('playend', elm)
return (
<>
<Cell style={{ padding: '0' }}>
<Cell style={{ padding: 0 }}>
<Video
source={source}
options={options}
onPlay={play}
onPause={pause}
onPlayEnd={playend}
style={{ height: '163px' }}
style={{ height: pxTransform(163) }}
/>
</Cell>
</>
Expand Down
7 changes: 4 additions & 3 deletions src/packages/video/demos/taro/demo3.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState } from 'react'
import { Cell, Video } from '@nutui/nutui-react-taro'
import pxTransform from '@/utils/px-transform'

const Demo3 = () => {
const [source, setSource] = useState({
const [source] = useState({
src: 'https://storage.360buyimg.com/nutui/video/video_NutUI.mp4',
type: 'video/mp4',
})
Expand All @@ -15,14 +16,14 @@ const Demo3 = () => {
const playend = (elm: any) => console.log('playend', elm)
return (
<>
<Cell style={{ padding: '0' }}>
<Cell style={{ padding: 0 }}>
<Video
source={source}
options={options}
onPlay={play}
onPause={pause}
onPlayEnd={playend}
style={{ height: '163px' }}
style={{ height: pxTransform(163) }}
Alex-huxiyang marked this conversation as resolved.
Show resolved Hide resolved
/>
</Cell>
</>
Expand Down
5 changes: 3 additions & 2 deletions src/packages/video/demos/taro/demo4.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState } from 'react'
import { Cell, Video } from '@nutui/nutui-react-taro'
import pxTransform from '@/utils/px-transform'

const Demo4 = () => {
const [source, setSource] = useState({
const [source] = useState({
src: 'https://storage.360buyimg.com/nutui/video/video_NutUI.mp4',
type: 'video/mp4',
})
Expand All @@ -23,7 +24,7 @@ const Demo4 = () => {
onPlay={play}
onPause={pause}
onPlayEnd={playend}
style={{ height: '163px' }}
style={{ height: pxTransform(163) }}
/>
</Cell>
</>
Expand Down
7 changes: 4 additions & 3 deletions src/packages/video/demos/taro/demo5.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState } from 'react'
import { Cell, Video } from '@nutui/nutui-react-taro'
import pxTransform from '@/utils/px-transform'

const Demo5 = () => {
const [source, setSource] = useState({
const [source] = useState({
src: 'https://storage.360buyimg.com/nutui/video/video_NutUI.mp4',
type: 'video/mp4',
})
Expand All @@ -15,14 +16,14 @@ const Demo5 = () => {
const playend = (elm: any) => console.log('playend', elm)
return (
<>
<Cell style={{ padding: '0' }}>
<Cell style={{ padding: 0 }}>
<Video
source={source}
options={options}
onPlay={play}
onPause={pause}
onPlayEnd={playend}
style={{ height: '163px' }}
style={{ height: pxTransform(163) }}
/>
</Cell>
</>
Expand Down
7 changes: 4 additions & 3 deletions src/packages/video/demos/taro/demo6.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState } from 'react'
import { Cell, Video } from '@nutui/nutui-react-taro'
import pxTransform from '@/utils/px-transform'

const Demo6 = () => {
const [source, setSource] = useState({
const [source] = useState({
src: 'https://storage.360buyimg.com/nutui/video/video_NutUI.mp4',
type: 'video/mp4',
})
Expand All @@ -19,14 +20,14 @@ const Demo6 = () => {
const playend = (elm: any) => console.log('playend', elm)
return (
<>
<Cell style={{ padding: '0' }}>
<Cell style={{ padding: 0 }}>
<Video
source={source}
options={options}
onPlay={play}
onPause={pause}
onPlayEnd={playend}
style={{ height: '163px' }}
style={{ height: pxTransform(163) }}
/>
</Cell>
</>
Expand Down
13 changes: 7 additions & 6 deletions src/packages/video/demos/taro/demo7.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState } from 'react'
import { Cell, Video, Button } from '@nutui/nutui-react-taro'
import pxTransform from '@/utils/px-transform'

const Demo7 = () => {
const [source1, setSource1] = useState({
const [source, setSource] = useState({
src: 'https://storage.360buyimg.com/nutui/video/legao-%E6%9D%A8%E8%BF%9B%E5%86%9B.mp4',
type: 'video/mp4',
})
Expand All @@ -14,23 +15,23 @@ const Demo7 = () => {
const playend = (elm: any) => console.log('playend', elm)

const changeVideo = () => {
setSource1({ ...source1, src: 'https://vjs.zencdn.net/v/oceans.mp4' })
setSource({ ...source, src: 'https://vjs.zencdn.net/v/oceans.mp4' })
}
return (
<>
<Cell style={{ padding: '0' }}>
<Cell style={{ padding: 0 }}>
<Video
source={source1}
source={source}
options={options}
onPlay={play}
onPause={pause}
onPlayEnd={playend}
style={{ height: '163px' }}
style={{ height: pxTransform(163) }}
/>
</Cell>
<Button
type="primary"
style={{ marginBottom: '60px' }}
style={{ marginBottom: pxTransform(60) }}
onClick={changeVideo}
>
视频切换
Expand Down
11 changes: 4 additions & 7 deletions src/packages/video/video.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BaseEventOrig,
View,
} from '@tarojs/components'
import { mergeProps } from '@/utils/merge-props'

export interface VideoProps extends Omit<VideoPropsTaro, 'src'> {
source: {
Expand All @@ -32,7 +33,7 @@ const defaultProps = {
},
options: {
controls: true,
muted: false, // 默认不是静音
muted: false,
autoplay: false,
poster: '',
playsinline: false,
Expand All @@ -43,7 +44,6 @@ const defaultProps = {
const classPrefix = `nut-video`
export const Video: FunctionComponent<Partial<VideoProps>> = (props) => {
const {
children,
source,
options,
className,
Expand All @@ -52,16 +52,13 @@ export const Video: FunctionComponent<Partial<VideoProps>> = (props) => {
onPause,
onPlayEnd,
...restProps
} = {
...defaultProps,
...props,
}
} = mergeProps(defaultProps, props)
const classes = classNames(classPrefix, className)

return (
<View className={classes} style={style}>
<VideoTaro
className="nut-video-player"
className={`${classPrefix}-player`}
muted={options.muted}
autoplay={options.autoplay}
loop={options.loop}
Expand Down
Loading