Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jumping height in WavyAnimation. #307

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/src/wavy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class WavyAnimatedText extends AnimatedText {
String text, {
TextAlign textAlign = TextAlign.start,
TextStyle? textStyle,
this.jumpHeight,
this.speed = const Duration(milliseconds: 300),
}) : super(
text: text,
Expand All @@ -25,6 +26,7 @@ class WavyAnimatedText extends AnimatedText {
);

late Animation<double> _waveAnim;
final double? jumpHeight;

@override
void initAnimation(AnimationController controller) {
Expand All @@ -43,6 +45,7 @@ class WavyAnimatedText extends AnimatedText {
text: text,
textStyle: defaultTextStyle.merge(textStyle),
scaleFactor: scaleFactor,
jumpHeight:jumpHeight
),
child: Text(
text,
Expand Down Expand Up @@ -115,13 +118,15 @@ class _WTextPainter extends CustomPainter {
required this.text,
required this.textStyle,
required this.scaleFactor,
this.jumpHeight
});

final double progress, scaleFactor;
final String text;
// Private class to store text information
final _textLayoutInfo = <_TextLayoutInfo>[];
final TextStyle textStyle;
final double? jumpHeight;
@override
void paint(Canvas canvas, Size size) {
if (_textLayoutInfo.isEmpty) {
Expand Down Expand Up @@ -185,14 +190,14 @@ class _WTextPainter extends CustomPainter {
// percent < .5 creates an phase difference between odd and even chars
_textLayoutInfo[txtInMoOdd + (txtInMoOdd + 1)].riseHeight = progress < .5
? 0
: -1.3 * height * math.sin((progress - .5) * math.pi).abs();
: -1.3 * (jumpHeight??height) * math.sin((progress - .5) * math.pi).abs();
}

// Calculating movement of the char at even place
if (txtInMoEven < text.length) {
_textLayoutInfo[txtInMoEven].isMoving = true;
_textLayoutInfo[txtInMoEven].riseHeight =
-1.3 * height * math.sin(percent * math.pi);
-1.3 * (jumpHeight??height) * math.sin(percent * math.pi);
}
}

Expand Down