Skip to content

Commit

Permalink
🔥 more
Browse files Browse the repository at this point in the history
  • Loading branch information
June committed Mar 30, 2022
1 parent 6f45590 commit d9d6b54
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
## 0.0.2

* add listen mode

## 0.0.3

* more
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
https://user-images.githubusercontent.com/9412501/159013153-79af72be-30e9-4d92-b34e-7af11c772812.mp4

# how to use
[![pub](https://img.shields.io/badge/pub-v0.0.2-green)](https://pub.dev/packages/parallaxj)
[![pub](https://img.shields.io/badge/pub-v0.0.3-green)](https://pub.dev/packages/parallaxj)
```dart
Parallaxable(
offsetRadio: 1.0 / 10,
Expand Down
38 changes: 24 additions & 14 deletions lib/src/parallax_touch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ class _ParallaxableState extends State<Parallaxable> with SingleTickerProviderSt
double xpercent = 1;
double ypercent = 1;
final rotating = 0;

bool reverse = false;
late AnimationController _aniController;

@override
void initState() {
super.initState();
_aniController = AnimationController(vsync: this, duration: const Duration(milliseconds: 100));
_aniController.addStatusListener((status) {
if(status == AnimationStatus.completed) {
if(reverse) {
reverse = false;
_aniController.reverse();
}
}
});
}

@override
Expand Down Expand Up @@ -86,16 +94,16 @@ class _ParallaxableState extends State<Parallaxable> with SingleTickerProviderSt
if (widget.listen) {
return Listener(
onPointerMove: (event) => _panUpdate(event.localPosition.dx, event.localPosition.dy),
onPointerCancel: (event) => _panEnd(),
onPointerCancel: (event) => _tapUp(),
onPointerDown: (event) => _panDown(event.localPosition.dx, event.localPosition.dy),
onPointerUp: (event) => _tapUp(),
child: stack,
);
}

return GestureDetector(
onPanCancel: _panEnd,
onPanEnd: (event) => _panEnd(),
onPanCancel: _tapUp,
onPanEnd: (event) => _tapUp(),
onPanUpdate: (event) => _panUpdate(event.localPosition.dx, event.localPosition.dy),
onTapUp: (event) => _tapUp(),
onPanDown: (event) => _panDown(event.localPosition.dx, event.localPosition.dy),
Expand All @@ -115,18 +123,20 @@ class _ParallaxableState extends State<Parallaxable> with SingleTickerProviderSt
}

void _panDown(double dx, double dy) {
_aniController.forward();
setState(() {
ypercent = (halfWidth - dx) / halfWidth;
xpercent = (dy - halfHeight) / halfHeight;
});
ypercent = (halfWidth - dx) / halfWidth;
xpercent = (dy - halfHeight) / halfHeight;
reverse = false;
if (_aniController.isAnimating) {
_aniController.stop();
}
_aniController.forward();
}

void _tapUp() {
_aniController.reverse();
}

void _panEnd() {
_aniController.reverse();
if (!_aniController.isAnimating) {
_aniController.reverse();
}else {
reverse = true;
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: parallaxj
description: A new Flutter project.
version: 0.0.2
version: 0.0.3
homepage: https://github.com/ZuYun/parallaxj

environment:
Expand Down

0 comments on commit d9d6b54

Please sign in to comment.