Skip to content

Commit

Permalink
优化注释
Browse files Browse the repository at this point in the history
  • Loading branch information
Caldis committed Sep 2, 2019
1 parent f4c053a commit c53376c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
15 changes: 6 additions & 9 deletions src/Zmage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,28 @@ export default class ReactZmage extends React.PureComponent {
super(props)

this.coverRef = React.createRef()
this.isControlled = this.props.hasOwnProperty('browsing')
this.isBrowsingControlled = this.props.hasOwnProperty('browsing')

this.state = {
// 浏览
browsing: false,
}

// TODO:FEATURE 懒加载
// TODO:FEATURE 翻页动画
// TODO:FEATURE 移动端的拖拽翻页
// TODO:ENHANCE 禁用移动端的滑动退出及禁用滚动
// TODO:ENHANCE 移动端下点击隐藏的背景按下时会变暗
// TODO:ENHANCE 禁用移动端的滑动退出
// TODO:BUG 移动端下左右按钮
}

/* 切换查看状态 */
inBrowsing = () => {
if (this.isControlled) {
if (this.isBrowsingControlled) {
this.props.onBrowsing(true)
} else {
this.setState({ browsing: true })
}
}
outBrowsing = () => {
if (this.isControlled) {
if (this.isBrowsingControlled) {
this.props.onBrowsing(false)
} else {
this.setState({ browsing: false })
Expand Down Expand Up @@ -93,8 +90,8 @@ export default class ReactZmage extends React.PureComponent {
{/*查看叠层*/}
<Browser
// Controlled status
isControlled={this.isControlled}
browsing={this.isControlled ? controlledBrowsing : internalBrowsing}
isBrowsingControlled={this.isBrowsingControlled}
browsing={this.isBrowsingControlled ? controlledBrowsing : internalBrowsing}
// Internal
coverRef={this.coverRef}
outBrowsing={this.outBrowsing}
Expand Down
12 changes: 6 additions & 6 deletions src/components/Browser/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default class Browser extends React.PureComponent {

constructor(props) {
super(props)

const { page, pageIsCover } = pageSet(props.coverRef, props.defaultPage, props.set)

this.state = {
Expand Down Expand Up @@ -74,21 +73,21 @@ export default class Browser extends React.PureComponent {
* 载入/卸载
**/
init = () => {
const { isControlled, coverRef, set, onBrowsing } = this.props
const { isBrowsingControlled, coverRef, set, onBrowsing } = this.props
const { show, page, pageIsCover } = this.state
if (!show) {
window.addEventListener('keydown', this.handleKeyDown)
window.addEventListener('scroll', this.handleScroll)
window.requestAnimationFrame(() => {
this.setState({ show:true, zoom:false, rotate:0, }, () => {
pageIsCover && hideCover(coverRef, set, page)
!isControlled && typeof onBrowsing === "function" && onBrowsing(true)
!isBrowsingControlled && typeof onBrowsing === "function" && onBrowsing(true)
})
})
}
}
unInit = ({ force }={}) => {
const { isControlled, coverRef, set, onBrowsing } = this.props
const { isBrowsingControlled, coverRef, set, onBrowsing } = this.props
const { show, page, pageIsCover } = this.state
if (show || force) {
window.removeEventListener('keydown', this.handleKeyDown)
Expand All @@ -97,7 +96,7 @@ export default class Browser extends React.PureComponent {
this.setState({ show:false, zoom:false, rotate:0 }, () => setTimeout(() => {
this.setState({ mount:false }, () => {
pageIsCover && showCover(coverRef, set, page)
!isControlled && typeof onBrowsing === "function" && onBrowsing(false)
!isBrowsingControlled && typeof onBrowsing === "function" && onBrowsing(false)
})
}, animationDuration))
}
Expand All @@ -108,6 +107,7 @@ export default class Browser extends React.PureComponent {
* 事件处理
**/
handleKeyDown = (e) => {
console.log('handleKeyDown')
const { preset, set, hotKey:userHotKey, loop, outBrowsing } = this.props
const { zoom, page } = this.state
// 合并熱鍵設定
Expand Down Expand Up @@ -284,7 +284,7 @@ Browser.contextType = Context
Browser.defaultProps = {

// Controlled status
isControlled: false,
isBrowsingControlled: false,
browsing: false,
// Internal
coverRef: React.createRef(),
Expand Down
2 changes: 2 additions & 0 deletions src/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export const defType = {
]),
// 动画
animate: PropTypes.shape({
// 缩放动画 (未实现)
browsing: PropTypes.bool,
// 翻页动画
flip: PropTypes.oneOf([
// 渐变 (set小於3時强制使用)
"fade",
Expand Down

0 comments on commit c53376c

Please sign in to comment.