|
| 1 | +import 'package:flare_dart/math/mat2d.dart'; |
| 2 | +import 'package:flare_flutter/flare.dart'; |
| 3 | +import 'package:flare_flutter/flare_controller.dart'; |
| 4 | + |
| 5 | +mixin GSYFlarePullMutliController implements FlareController { |
| 6 | + |
| 7 | + ActorAnimation _loadingAnimation; |
| 8 | + ActorAnimation _successAnimation; |
| 9 | + ActorAnimation _pullAnimation; |
| 10 | + ActorAnimation _cometAnimation; |
| 11 | + |
| 12 | + double pulledExtentFlare = 0; |
| 13 | + bool _isSurround = false; |
| 14 | + |
| 15 | + |
| 16 | + double _refreshTriggerPullDistance = 140; |
| 17 | + |
| 18 | + double _successTime = 0.0; |
| 19 | + double _loadingTime = 0.0; |
| 20 | + double _cometTime = 0.0; |
| 21 | + |
| 22 | + @override |
| 23 | + void initialize(FlutterActorArtboard artboard) { |
| 24 | + _pullAnimation = artboard.getAnimation("pull"); |
| 25 | + _successAnimation = artboard.getAnimation("success"); |
| 26 | + _loadingAnimation = artboard.getAnimation("loading"); |
| 27 | + _cometAnimation = artboard.getAnimation("idle comet"); |
| 28 | + } |
| 29 | + |
| 30 | + @override |
| 31 | + void setViewTransform(Mat2D viewTransform) {} |
| 32 | + |
| 33 | + @override |
| 34 | + bool advance(FlutterActorArtboard artboard, double elapsed) { |
| 35 | + double animationPosition = pulledExtentFlare / _refreshTriggerPullDistance; |
| 36 | + animationPosition *= animationPosition; |
| 37 | + _cometTime += elapsed; |
| 38 | + _cometAnimation.apply(_cometTime % _cometAnimation.duration, artboard, 1.0); |
| 39 | + _pullAnimation.apply( |
| 40 | + _pullAnimation.duration * animationPosition, artboard, 1.0); |
| 41 | + if (_isSurround) { |
| 42 | + _successTime += elapsed; |
| 43 | + if (_successTime >= _successAnimation.duration) { |
| 44 | + _loadingTime += elapsed; |
| 45 | + } |
| 46 | + } else { |
| 47 | + _successTime = _loadingTime = 0.0; |
| 48 | + } |
| 49 | + if (_successTime >= _successAnimation.duration) { |
| 50 | + _loadingAnimation.apply( |
| 51 | + _loadingTime % _loadingAnimation.duration, artboard, 1.0); |
| 52 | + } else if (_successTime > 0.0) { |
| 53 | + _successAnimation.apply(_successTime, artboard, 1.0); |
| 54 | + } |
| 55 | + return true; |
| 56 | + } |
| 57 | + |
| 58 | + void onRefreshing() { |
| 59 | + _isSurround = true; |
| 60 | + } |
| 61 | + |
| 62 | + void onRefreshEnd() { |
| 63 | + _isSurround = false; |
| 64 | + } |
| 65 | + |
| 66 | + bool get getPlayAuto; |
| 67 | +} |
0 commit comments