Skip to content

Commit

Permalink
feat: Support light and dark modes for the eye animation (#4885)
Browse files Browse the repository at this point in the history
* Support light and dark modes for the eye animation

* Minor fix

* Reformat file

* Refix
  • Loading branch information
g123k authored Dec 8, 2023
1 parent f0c26da commit 05a1328
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Binary file modified packages/smooth_app/assets/animations/off.riv
Binary file not shown.
40 changes: 31 additions & 9 deletions packages/smooth_app/lib/resources/app_animations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:rive/rive.dart';
import 'package:smooth_app/services/smooth_services.dart';
import 'package:smooth_app/themes/theme_provider.dart';

/// Widget to inject in the hierarchy to have a single instance of the RiveFile
class AnimationsLoader extends StatefulWidget {
Expand Down Expand Up @@ -132,28 +133,49 @@ class _DoubleChevronAnimationState extends State<DoubleChevronAnimation> {
}
}

class SearchEyeAnimation extends StatelessWidget {
class SearchEyeAnimation extends StatefulWidget {
const SearchEyeAnimation({
this.size,
super.key,
});

final double? size;

@override
State<SearchEyeAnimation> createState() => _SearchEyeAnimationState();
}

class _SearchEyeAnimationState extends State<SearchEyeAnimation> {
StateMachineController? _controller;

@override
Widget build(BuildContext context) {
final double size = this.size ?? IconTheme.of(context).size ?? 24.0;
final double size = widget.size ?? IconTheme.of(context).size ?? 24.0;
final bool lightTheme = context.watch<ThemeProvider>().isLightTheme;

return ExcludeSemantics(
child: SizedBox(
width: size,
height: (80 / 87) * size,
child: RiveAnimation.direct(AnimationsLoader.of(context),
artboard: 'Search eye', onInit: (Artboard artboard) {
_controller = StateMachineController.fromArtboard(
artboard,
'LoopMachine',
);

return SizedBox(
width: size,
height: (80 / 87) * size,
child: RiveAnimation.direct(
AnimationsLoader.of(context),
artboard: 'Search eye',
stateMachines: const <String>['LoopMachine'],
artboard.addController(_controller!);
_controller!.findInput<bool>('light')?.value = !lightTheme;
}),
),
);
}

@override
void dispose() {
_controller?.dispose();
super.dispose();
}
}

class SearchAnimation extends StatefulWidget {
Expand Down

0 comments on commit 05a1328

Please sign in to comment.