-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCircleActionItem.js
80 lines (71 loc) · 1.97 KB
/
CircleActionItem.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
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import {
Animated,
Platform,
Image
} from 'react-native'
const isIOS = Platform.OS === 'ios'
export default class CircleActionItem extends Component {
constructor(props) {
super(props)
this.state = {
openVal: new Animated.Value(0),
scale: new Animated.Value(1),
}
}
componentWillReceiveProps(nextProps) {
if (this.props.isSelecting != nextProps.isSelecting) {
const toVal = (nextProps.isSelecting) ? 1.15 : 1
Animated.timing(
this.state.scale,
{
toValue: toVal,
duration: 100,
// useNativeDriver: true
}
).start(() => {
})
}
}
componentDidMount() {
Animated.spring(
this.state.openVal,
{ toValue: 1, tension: 40, friction: 5, duration: 100 }
).start(() => {
})
}
render() {
const { targetX = 0, targetY = 0, ox = 0, oy = 0, isSelecting = false } = this.props
const { openVal, scale } = this.state
const item = this.props.item
const target = {
top: openVal.interpolate({ inputRange: [0, 1], outputRange: [oy, targetY] }),
left: openVal.interpolate({ inputRange: [0, 1], outputRange: [ox, targetX] })
}
const bgColor = isSelecting ? item.activeColor : this.props.deactiveColor
let tintColor = {}
if (isSelecting) {
tintColor = { tintColor: this.props.deactiveColor }
}
const imageAction = (isSelecting && item.imageActive) ? item.imageActive : item.image
return (
<Animated.View style={{
transform: [
{ scale: scale }
],
zIndex: 100,
position: 'absolute',
width: 50,
height: 50,
borderRadius: 25,
top: target.top,
left: target.left,
alignItems: 'center',
justifyContent: 'center'
}} >
<Image source={imageAction} style={[{ width: 50, height: 50, borderRadius: 25 }]} />
</Animated.View>
)
}
}