Skip to content

Commit

Permalink
Merge branch 'master' of github.com:NervJS/taro
Browse files Browse the repository at this point in the history
  • Loading branch information
Pines-Cheng committed Apr 11, 2019
2 parents 4a921a0 + 3fc0ec0 commit 1c285f3
Show file tree
Hide file tree
Showing 23 changed files with 1,299 additions and 144 deletions.
2 changes: 1 addition & 1 deletion packages/taro-cli/templates/wxcloud/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module.exports = function (creater, params, helper, cb) {
typescript: true
})
} else {
creater.template(template, path.join(clientDirName, 'pagejs'), path.join(sourceDir, 'pages', 'index', 'index.weapp.js'), {
creater.template(template, path.join(clientDirName, 'pagejs'), path.join(sourceDir, 'pages', 'index', 'index.js'), {
css: currentStyleExt
})
creater.template(template, path.join(clientDirName, 'components', 'login', 'index'), path.join(sourceDir, 'components', 'login', 'index.weapp.js'), {
Expand Down
34 changes: 22 additions & 12 deletions packages/taro-components/src/components/canvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,30 @@ import classnames from 'classnames'

import './style/index.css'

// canvas-id String canvas 组件的唯一标识符
// disable-scroll Boolean false 当在 canvas 中移动时且有绑定手势事件时,禁止屏幕滚动以及下拉刷新
// bindtouchstart EventHandle 手指触摸动作开始
// bindtouchmove EventHandle 手指触摸后移动
// bindtouchend EventHandle 手指触摸动作结束
// bindtouchcancel EventHandle 手指触摸动作被打断,如来电提醒,弹窗
// bindlongtap EventHandle 手指长按 500ms 之后触发,触发了长按事件后进行移动不会触发屏幕的滚动
// binderror EventHandle 当发生错误时触发 error 事件,detail = {errMsg: 'something wrong'}
/**
* Canvas组件参数
* @typedef CanvasProps
* @param {String} [canvasId=canvas] 组件的唯一标识符
* @param {Boolean} [disableScroll=false] 当在 canvas 中移动时且有绑定手势事件时,禁止屏幕滚动以及下拉刷新
* @param {EventHandle} onTouchstart 手指触摸动作开始
* @param {EventHandle} onTouchmove 手指触摸后移动
* @param {EventHandle} onTouchend 手指触摸动作结束
* @param {EventHandle} onTouchcancel 手指触摸动作被打断,如来电提醒,弹窗
* @param {EventHandle} onLongtap 手指长按 500ms 之后触发,触发了长按事件后进行移动不会触发屏幕的滚动
* @param {EventHandle} onError 当发生错误时触发 error 事件,detail = {errMsg: 'something wrong'}
*/

@touchable()
export default class Canvas extends Taro.PureComponent {
class Canvas extends Taro.PureComponent {
/** @type {CanvasProps} */
static defaultProps = {
canvasId: '',
disableScroll: false,
bindError: null
onError: null
}

/** @type {CanvasProps} */
props
width = 300
height = 150
getWrapRef = ref => {
Expand All @@ -40,8 +48,8 @@ export default class Canvas extends Taro.PureComponent {
this.height = height
}
componentDidCatch (e) {
const bindError = this.props.bindError
bindError && bindError({
const onError = this.props.onError
onError && onError({
errMsg: e.message
})
}
Expand All @@ -68,3 +76,5 @@ export default class Canvas extends Taro.PureComponent {
)
}
}

export default Canvas
58 changes: 32 additions & 26 deletions packages/taro-components/src/components/navigator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ import './navigator.css'

/* eslint-disable prefer-promise-reject-errors */

/*
*target String self 在哪个目标上发生跳转,默认当前小程序,可选值self/miniProgram
*url String 当前小程序内的跳转链接
*open-type String navigate 跳转方式
*delta Number 当 open-type 为 'navigateBack' 时有效,表示回退的层数
*app-id String 当target="miniProgram"时有效,要打开的小程序 appId
*path String 当target="miniProgram"时有效,打开的页面路径,如果为空则打开首页
*extra-data Object 当target="miniProgram"时有效,需要传递给目标小程序的数据,目标小程序可在 App.onLaunch(),App.onShow() 中获取到这份数据。详情
version version release 当target="miniProgram"时有效,要打开的小程序版本,有效值 develop(开发版),trial(体验版),release(正式版),仅在当前小程序为开发版或体验版时此参数有效;如果当前小程序是 *式版,则打开的小程序必定是正式版。
*bindsuccess String 当target="miniProgram"时有效,跳转小程序成功
*bindfail String 当target="miniProgram"时有效,跳转小程序失败
*bindcomplete String 当target="miniProgram"时有效,跳转小程序完成
*aria-label String 无障碍访问,(属性)元素的额外描述
/**
* Navigator组件参数
* @typedef NavigatorProps
* @property {String} appId 当target="miniProgram"时有效,要打开的小程序 appId
* @property {String} ariaLabel 无障碍访问,(属性)元素的额外描述
* @property {Number} delta 当 openType 为 'navigateBack' 时有效,表示回退的层数
* @property {Object} extraData 当target="miniProgram"时有效,需要传递给目标小程序的数据,目标小程序可在 App.onLaunch(),App.onShow() 中获取到这份数据。详情
* @property {String} [openType=navigate] 跳转方式
* @property {String} path 当target="miniProgram"时有效,打开的页面路径,如果为空则打开首页
* @property {String} [target=self] 在哪个目标上发生跳转,默认当前小程序,可选值self/miniProgram
* @property {String} url 当前小程序内的跳转链接
* @property {version} [version=release] 当target="miniProgram"时有效,要打开的小程序版本,有效值 develop(开发版),trial(体验版),release(正式版),仅在当前小程序为开发版或体验版时此参数有效;如果当前小程序是 *式版,则打开的小程序必定是正式版。
* @property {String} onFail 当target="miniProgram"时有效,跳转小程序失败
* @property {String} onComplete 当target="miniProgram"时有效,跳转小程序完成
* @property {String} onSuccess 当target="miniProgram"时有效,跳转小程序成功
*/

/**
Expand All @@ -29,7 +31,14 @@ import './navigator.css'
* https://developers.weixin.qq.com/miniprogram/dev/component/navigator.html
**/

@hoverable({
hoverClass: 'navigator-hover',
hoverStopPropergation: false,
hoverStartTime: 50,
hoverStayTime: 600
})
class Navigator extends Taro.Component {
/** @type {NavigatorProps} */
static defaultProps = {
target: 'self',
url: null,
Expand All @@ -39,13 +48,15 @@ class Navigator extends Taro.Component {
path: null,
extraData: {},
version: 'release',
bindSuccess: null,
bindFail: null,
bindComplete: null,
onSuccess: null,
onFail: null,
onComplete: null,
isHover: false
}
/** @type {NavigationProps} */
props
onClick = () => {
const { openType, bindSuccess, bindFail, bindComplete } = this.props
const { openType, onSuccess, onFail, onComplete } = this.props
let promise
switch (openType) {
case 'navigate':
Expand Down Expand Up @@ -81,11 +92,11 @@ class Navigator extends Taro.Component {
}
if (promise) {
promise.then(res => {
bindSuccess && bindSuccess(res)
onSuccess && onSuccess(res)
}).catch(res => {
bindFail && bindFail(res)
onFail && onFail(res)
}).finally(res => {
bindComplete && bindComplete(res)
onComplete && onComplete(res)
})
}
}
Expand All @@ -105,9 +116,4 @@ class Navigator extends Taro.Component {
}
}

export default hoverable({
hoverClass: 'navigator-hover',
hoverStopPropergation: false,
hoverStartTime: 50,
hoverStayTime: 600
})(Navigator)
export default Navigator
6 changes: 3 additions & 3 deletions packages/taro-components/src/components/tabbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class Tabbar extends Nerv.Component {
this.customRoutes.push([key, customRoutes[key]])
}

list.forEach( item => {
if (item.pagePath.indexOf('/') !== 0){
item.pagePath = "/" + item.pagePath
list.forEach(item => {
if (item.pagePath.indexOf('/') !== 0) {
item.pagePath = '/' + item.pagePath
}
})

Expand Down
171 changes: 171 additions & 0 deletions packages/taro-components/src/components/video/controls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import Nerv, { Component } from 'nervjs'
import classnames from 'classnames'
import { formatTime, calcDist } from './utils'

/**
* @typedef {Object} ControlsProps
* @property {Boolean} controls={controls}
* @property {Number} currentTime={this.currentTime}
* @property {Number} duration={this.state.duration}
* @property {Boolean} isPlaying={this.state.isPlaying}
* @property {Function} pauseFunc={this.pause}
* @property {Function} playFunc={this.play}
* @property {Function} seekFunc={this.seek}
* @property {Boolean} showPlayBtn={showPlayBtn}
* @property {Boolean} showProgress={showProgress}
*/
class Controls extends Component {
visible = false
isDraggingProgressBall = false

/** @type {number} */
hideControlsTimer

/** @type {ControlsProps} */
props

progressDimentions = {
left: 0,
right: 0,
width: 0
}

calcPercentage = pageX => {
let pos = pageX - this.progressDimentions.left
pos = Math.max(pos, 0)
pos = Math.min(pos, this.progressDimentions.width)
return pos / this.progressDimentions.width
}

getControlsRef = ref => {
if (!ref) return
this.controlsRef = ref
}
getCurrentTimeRef = ref => {
if (!ref) return
this.currentTimeRef = ref
}
getProgressBallRef = ref => {
if (!ref) return
this.progressBallRef = ref
}

setCurrentTime (time) {
this.currentTimeRef.innerHTML = formatTime(time)
}
setProgressBall (percentage) {
this.progressBallRef.style.left = `${percentage * 100}%`
}

toggleVisible (nextVisible) {
const visible = nextVisible === undefined ? !this.visible : nextVisible
if (visible) {
this.hideControlsTimer && clearTimeout(this.hideControlsTimer)
if (this.props.isPlaying) {
this.hideControlsTimer = setTimeout(() => {
this.toggleVisible(false)
}, 2000)
}
this.controlsRef.style.visibility = 'visible'
} else {
this.controlsRef.style.visibility = 'hidden'
}
this.visible = !!visible
}

onDragProgressBallStart = () => {
this.isDraggingProgressBall = true
this.hideControlsTimer && clearTimeout(this.hideControlsTimer)
}
onClickProgress = e => {
e.stopPropagation()
const seekFunc = this.props.seekFunc
const percentage = this.calcPercentage(e.pageX)
seekFunc(percentage * this.props.duration)
this.toggleVisible(true)
}
bindTouchEvents = () => {
let percentage = 0
const touchMove = e => {
if (!this.isDraggingProgressBall) return
const touchX = e.touches[0].pageX
percentage = this.calcPercentage(touchX)
this.setProgressBall(percentage)
}
const touchEnd = e => {
if (!this.isDraggingProgressBall) return
const seekFunc = this.props.seekFunc
this.isDraggingProgressBall = false
seekFunc(percentage * this.props.duration)
this.toggleVisible(true)
}

document.body.addEventListener('touchmove', touchMove)
document.body.addEventListener('touchend', touchEnd)
document.body.addEventListener('touchcancel', touchEnd)
return () => {
document.body.removeEventListener('touchmove', touchMove)
document.body.removeEventListener('touchend', touchEnd)
document.body.removeEventListener('touchcancel', touchEnd)
}
}

componentDidMount () {
this.unbindTouchEvents = this.bindTouchEvents()
}
componentWillUnmount () {
this.unbindTouchEvents()
}

render () {
const { controls, currentTime, duration, isPlaying, pauseFunc, playFunc, showPlayBtn, showProgress } = this.props
const formattedDuration = formatTime(duration)
let playBtn

if (!showPlayBtn) {
return null
} else if (isPlaying) {
playBtn = <div className='taro-video-control-button taro-video-control-button-pause' onClick={pauseFunc} />
} else {
playBtn = <div className='taro-video-control-button taro-video-control-button-play' onClick={playFunc} />
}

return (
<div className='taro-video-bar taro-video-bar-full' ref={this.getControlsRef}>
{controls && (
<div className='taro-video-controls'>
{playBtn}
{showProgress && (
<div className='taro-video-current-time' ref={this.getCurrentTimeRef}>
{formatTime(currentTime)}
</div>
)}
{showProgress && (
<div className='taro-video-progress-container' onClick={this.onClickProgress}>
<div
className='taro-video-progress'
ref={ref => {
if (ref !== null) {
const rect = ref.getBoundingClientRect()
this.progressDimentions.left = rect.left
this.progressDimentions.right = rect.right
this.progressDimentions.width = rect.width
}
}}>
<div className='taro-video-progress-buffered' style='width: 100%;' />
<div className='taro-video-ball' ref={this.getProgressBallRef} onTouchStart={this.onDragProgressBallStart} style={`left: ${formattedDuration ? (this.currentTime / duration) * 100 : 0}%`}>
<div className='taro-video-inner' />
</div>
</div>
</div>
)}
{showProgress && <div className='taro-video-duration'>{formattedDuration}</div>}
</div>
)}
{this.props.children}
</div>
)
}
}

export default Controls
Loading

0 comments on commit 1c285f3

Please sign in to comment.