Skip to content

Commit

Permalink
feat: Added the scroll up animation. (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhalakupadhyay authored Oct 6, 2024
1 parent cdebe46 commit 7b087ca
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
25 changes: 25 additions & 0 deletions lib/badge_animation/ani_up.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:badgemagic/badge_animation/animation_abstract.dart';

class UpAnimation extends BadgeAnimation {
@override
void processAnimation(int badgeHeight, int badgeWidth, int animationIndex,
List<List<bool>> processGrid, List<List<bool>> canvas) {
int newWidth = processGrid[0].length;
int newHeight = processGrid.length;
for (int i = 0; i < badgeHeight; i++) {
for (int j = 0; j < badgeWidth; j++) {
if (j < badgeWidth && i < badgeHeight) {
int newGridRow = (i + animationIndex + newHeight) % newHeight;

bool upCondition = (i >= 0 &&
i < newHeight &&
j >= 0 &&
j < newWidth &&
processGrid[newGridRow][j]);

canvas[i][j] = upCondition;
}
}
}
}
}
14 changes: 12 additions & 2 deletions lib/providers/badgeview_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import 'dart:async';

import 'package:badgemagic/badge_animation/ani_left.dart';
import 'package:badgemagic/badge_animation/ani_right.dart';
import 'package:badgemagic/badge_animation/ani_up.dart';
import 'package:badgemagic/badge_animation/animation_abstract.dart';
import 'package:badgemagic/constants.dart';
import 'package:flutter/material.dart';

class DrawBadgeProvider extends ChangeNotifier {
bool _isDisposed = false;

@override
void dispose() {
_isDisposed = true;
timer?.cancel();
super.dispose();
}

int animationIndex = 0;
int animationSpeed = aniSpeedStrategy(0);
int counter = 0;
Expand Down Expand Up @@ -85,7 +95,6 @@ class DrawBadgeProvider extends ChangeNotifier {
}

void startTimer() {
setAnimationMode(animationIndex);
timer =
Timer.periodic(Duration(microseconds: animationSpeed), (Timer timer) {
renderGrid(newGrid);
Expand All @@ -96,7 +105,7 @@ class DrawBadgeProvider extends ChangeNotifier {
Map<int, BadgeAnimation?> animationMap = {
0: LeftAnimation(),
1: RightAnimation(),
// 2: UpAnimation(),
2: UpAnimation(),
// 3: DownAnimation(),
// 4: FixedAnimation(),
// 5: SnowFlakeAnimation(),
Expand All @@ -111,6 +120,7 @@ class DrawBadgeProvider extends ChangeNotifier {
}

void renderGrid(List<List<bool>> newGrid) {
if (_isDisposed) return;
int badgeWidth = homeViewGrid[0].length;
int badgeHeight = homeViewGrid.length;
var canvas = List.generate(
Expand Down

0 comments on commit 7b087ca

Please sign in to comment.