-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathindex.js
58 lines (53 loc) · 1.55 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
import { GestureState } from '../../../common/types';
import { worklet, supportWorklet } from '../../../common/worklet-api';
import { showTips } from '../../../common/tips';
const { shared, derived, spring } = worklet;
Page({
data: {},
onLoad() {
if (this.renderer !== 'skyline' || !supportWorklet()) {
showTips()
return;
}
const x = shared(0);
const y = shared(0);
const pressed = shared(false);
const scale = derived(() => {
'worklet'
return spring(pressed.value ? 1.2 : 1)
});
this.applyAnimatedStyle('.circle', () => {
'worklet';
return {
backgroundColor: pressed.value ? '#5f9ea0' : '#adff2f',
transform: `translate(${x.value}px, ${y.value}px) scale(${scale.value})`,
};
});
this.x = x;
this.y = y;
this.pressed = pressed;
},
handlepan(gestureEvent) {
'worklet';
console.log('gestureEvent--------------', gestureEvent.state)
if (gestureEvent.state === GestureState.POSSIBLE) {
this.pressed.value = true;
} else if (gestureEvent.state === GestureState.END || gestureEvent.state === GestureState.CANCELLED) {
this.pressed.value = false;
this.x.value = spring(0);
this.y.value = spring(0);
} else if (gestureEvent.state === GestureState.ACTIVE) {
this.x.value += gestureEvent.deltaX;
this.y.value += gestureEvent.deltaY;
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
return {
title: '手势系统',
path: 'packageSkyline/pages/worklet/gesture/index'
}
},
});