-
Notifications
You must be signed in to change notification settings - Fork 747
/
Copy pathindex.js
140 lines (123 loc) · 3.37 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* eslint-disable taro/function-naming */
import Taro from '@tarojs/taro'
import { View, Text, ScrollView } from '@tarojs/components'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import _isFunction from 'lodash/isFunction'
import AtComponent from '../../common/component'
import { handleTouchScroll } from '../../common/utils'
export default class AtFloatLayout extends AtComponent {
constructor (props) {
super(...arguments)
const { isOpened } = props
this.state = {
_isOpened: isOpened
}
}
componentWillReceiveProps (nextProps) {
const { isOpened } = nextProps
if (this.props.isOpened !== isOpened) {
handleTouchScroll(isOpened)
}
if (isOpened !== this.state._isOpened) {
this.setState({
_isOpened: isOpened
})
}
}
handleClose = () => {
if (_isFunction(this.props.onClose)) {
this.props.onClose()
}
}
close = () => {
this.setState(
{
_isOpened: false
},
this.handleClose
)
}
handleTouchMove = e => {
e.stopPropagation()
}
render () {
const { _isOpened } = this.state
const {
title,
scrollY,
scrollX,
scrollTop,
scrollLeft,
upperThreshold,
lowerThreshold,
scrollWithAnimation,
top
} = this.props
const rootClass = classNames(
'at-float-layout',
{
'at-float-layout--active': _isOpened
},
this.props.className
)
return (
<View className={rootClass} onTouchMove={this.handleTouchMove}>
<View onClick={this.close} className='at-float-layout__overlay' />
<View className={top ? 'at-float-layout__container at-float-layout__container--top layout' : 'at-float-layout__container layout'}>
{title ? (
<View className='layout-header'>
<Text className='layout-header__title'>{title}</Text>
<View className='layout-header__btn-close' onClick={this.close} />
</View>
) : null}
<View className='layout-body'>
<ScrollView
scrollY={scrollY}
scrollX={scrollX}
scrollTop={scrollTop}
scrollLeft={scrollLeft}
upperThreshold={upperThreshold}
lowerThreshold={lowerThreshold}
scrollWithAnimation={scrollWithAnimation}
onScroll={this.props.onScroll}
onScrollToLower={this.props.onScrollToLower}
onScrollToUpper={this.props.onScrollToUpper}
className='layout-body__content'
>
{this.props.children}
</ScrollView>
</View>
</View>
</View>
)
}
}
AtFloatLayout.defaultProps = {
title: '',
isOpened: false,
scrollY: true,
scrollX: false,
scrollWithAnimation: false,
top: false,
onClose: () => {},
onScroll: () => {},
onScrollToLower: () => {},
onScrollToUpper: () => {}
}
AtFloatLayout.propType = {
title: PropTypes.string,
isOpened: PropTypes.bool,
scrollY: PropTypes.bool,
scrollX: PropTypes.bool,
scrollTop: PropTypes.number,
scrollLeft: PropTypes.number,
upperThreshold: PropTypes.number,
lowerThreshold: PropTypes.number,
scrollWithAnimation: PropTypes.bool,
top: PropTypes.bool,
onClose: PropTypes.func,
onScroll: PropTypes.func,
onScrollToLower: PropTypes.func,
onScrollToUpper: PropTypes.func
}