-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (57 loc) · 1.54 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
/**
* Created by jialing on 2019-08-01.
*/
import React from 'react'
import {LayoutAnimation, StyleSheet, View, ViewPropTypes} from 'react-native'
import PropTypes from 'prop-types'
/**
* Created by jialing on 2018-11-25.
*/
export default class Accordion extends React.Component {
static propTypes = {
style: ViewPropTypes.style,
children: PropTypes.any,
expand: PropTypes.bool,
animationType: PropTypes.oneOf(['default', 'slide', 'none']),
duration: PropTypes.number
}
static defaultProps = {
style: {},
animationType: 'default',
duration: 300
}
componentWillReceiveProps (nextProps, nextContext) {
if (nextProps.animationType !== 'none' && nextProps.expand !== this.props.expand) {
LayoutAnimation.configureNext({
duration: nextProps.duration, // 动画持续时间
create: {type: 'linear', property: 'opacity'},
delete: {type: 'linear', property: 'opacity'},
update: {type: 'easeInEaseOut'}
})
}
}
render () {
const {expand, style, children, animationType} = this.props
return (
<View style={{overflow: 'hidden', height: expand ? undefined : 0}}>
<View style={style}>
{
animationType === 'slide'
? <View style={[styles.slider, {position: expand ? undefined : 'absolute'}]}>
{children}
</View>
: children
}
</View>
</View>
)
}
}
const styles = StyleSheet.create({
slider: {
flex: 1,
bottom: 0,
left: 0,
right: 0
}
})