Skip to content

Commit d9d6b54

Browse files
author
June
committed
🔥 more
1 parent 6f45590 commit d9d6b54

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
## 0.0.2
66

77
* add listen mode
8+
9+
## 0.0.3
10+
11+
* more

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
https://user-images.githubusercontent.com/9412501/159013153-79af72be-30e9-4d92-b34e-7af11c772812.mp4
88

99
# how to use
10-
[![pub](https://img.shields.io/badge/pub-v0.0.2-green)](https://pub.dev/packages/parallaxj)
10+
[![pub](https://img.shields.io/badge/pub-v0.0.3-green)](https://pub.dev/packages/parallaxj)
1111
```dart
1212
Parallaxable(
1313
offsetRadio: 1.0 / 10,

lib/src/parallax_touch.dart

+24-14
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,21 @@ class _ParallaxableState extends State<Parallaxable> with SingleTickerProviderSt
3333
double xpercent = 1;
3434
double ypercent = 1;
3535
final rotating = 0;
36-
36+
bool reverse = false;
3737
late AnimationController _aniController;
3838

3939
@override
4040
void initState() {
4141
super.initState();
4242
_aniController = AnimationController(vsync: this, duration: const Duration(milliseconds: 100));
43+
_aniController.addStatusListener((status) {
44+
if(status == AnimationStatus.completed) {
45+
if(reverse) {
46+
reverse = false;
47+
_aniController.reverse();
48+
}
49+
}
50+
});
4351
}
4452

4553
@override
@@ -86,16 +94,16 @@ class _ParallaxableState extends State<Parallaxable> with SingleTickerProviderSt
8694
if (widget.listen) {
8795
return Listener(
8896
onPointerMove: (event) => _panUpdate(event.localPosition.dx, event.localPosition.dy),
89-
onPointerCancel: (event) => _panEnd(),
97+
onPointerCancel: (event) => _tapUp(),
9098
onPointerDown: (event) => _panDown(event.localPosition.dx, event.localPosition.dy),
9199
onPointerUp: (event) => _tapUp(),
92100
child: stack,
93101
);
94102
}
95103

96104
return GestureDetector(
97-
onPanCancel: _panEnd,
98-
onPanEnd: (event) => _panEnd(),
105+
onPanCancel: _tapUp,
106+
onPanEnd: (event) => _tapUp(),
99107
onPanUpdate: (event) => _panUpdate(event.localPosition.dx, event.localPosition.dy),
100108
onTapUp: (event) => _tapUp(),
101109
onPanDown: (event) => _panDown(event.localPosition.dx, event.localPosition.dy),
@@ -115,18 +123,20 @@ class _ParallaxableState extends State<Parallaxable> with SingleTickerProviderSt
115123
}
116124

117125
void _panDown(double dx, double dy) {
118-
_aniController.forward();
119-
setState(() {
120-
ypercent = (halfWidth - dx) / halfWidth;
121-
xpercent = (dy - halfHeight) / halfHeight;
122-
});
126+
ypercent = (halfWidth - dx) / halfWidth;
127+
xpercent = (dy - halfHeight) / halfHeight;
128+
reverse = false;
129+
if (_aniController.isAnimating) {
130+
_aniController.stop();
131+
}
132+
_aniController.forward();
123133
}
124134

125135
void _tapUp() {
126-
_aniController.reverse();
127-
}
128-
129-
void _panEnd() {
130-
_aniController.reverse();
136+
if (!_aniController.isAnimating) {
137+
_aniController.reverse();
138+
}else {
139+
reverse = true;
140+
}
131141
}
132142
}

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: parallaxj
22
description: A new Flutter project.
3-
version: 0.0.2
3+
version: 0.0.3
44
homepage: https://github.com/ZuYun/parallaxj
55

66
environment:

0 commit comments

Comments
 (0)