-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'package:flare_dart/math/mat2d.dart'; | ||
import 'package:flare_flutter/flare.dart'; | ||
import 'package:flare_flutter/flare_controller.dart'; | ||
|
||
mixin GSYFlarePullMutliController implements FlareController { | ||
|
||
ActorAnimation _loadingAnimation; | ||
ActorAnimation _successAnimation; | ||
ActorAnimation _pullAnimation; | ||
ActorAnimation _cometAnimation; | ||
|
||
double pulledExtentFlare = 0; | ||
bool _isSurround = false; | ||
|
||
|
||
double _refreshTriggerPullDistance = 140; | ||
|
||
double _successTime = 0.0; | ||
double _loadingTime = 0.0; | ||
double _cometTime = 0.0; | ||
|
||
@override | ||
void initialize(FlutterActorArtboard artboard) { | ||
_pullAnimation = artboard.getAnimation("pull"); | ||
_successAnimation = artboard.getAnimation("success"); | ||
_loadingAnimation = artboard.getAnimation("loading"); | ||
_cometAnimation = artboard.getAnimation("idle comet"); | ||
} | ||
|
||
@override | ||
void setViewTransform(Mat2D viewTransform) {} | ||
|
||
@override | ||
bool advance(FlutterActorArtboard artboard, double elapsed) { | ||
double animationPosition = pulledExtentFlare / _refreshTriggerPullDistance; | ||
animationPosition *= animationPosition; | ||
_cometTime += elapsed; | ||
_cometAnimation.apply(_cometTime % _cometAnimation.duration, artboard, 1.0); | ||
_pullAnimation.apply( | ||
_pullAnimation.duration * animationPosition, artboard, 1.0); | ||
if (_isSurround) { | ||
_successTime += elapsed; | ||
if (_successTime >= _successAnimation.duration) { | ||
_loadingTime += elapsed; | ||
} | ||
} else { | ||
_successTime = _loadingTime = 0.0; | ||
} | ||
if (_successTime >= _successAnimation.duration) { | ||
_loadingAnimation.apply( | ||
_loadingTime % _loadingAnimation.duration, artboard, 1.0); | ||
} else if (_successTime > 0.0) { | ||
_successAnimation.apply(_successTime, artboard, 1.0); | ||
} | ||
return true; | ||
} | ||
|
||
void onRefreshing() { | ||
_isSurround = true; | ||
} | ||
|
||
void onRefreshEnd() { | ||
_isSurround = false; | ||
} | ||
|
||
bool get getPlayAuto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.