Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add Rive animation for sharing progress sheet

AmanRajSinghMourya4f8f7dbfdb46
diff --git a/mobile/apps/photos/assets/invite.riv b/mobile/apps/photos/assets/invite.riv
new file mode 100644
index 0000000000..bdc7362869
Binary files /dev/null and b/mobile/apps/photos/assets/invite.riv differ
diff --git a/mobile/apps/photos/lib/ui/sharing/widgets/sharing_progress_sheet.dart b/mobile/apps/photos/lib/ui/sharing/widgets/sharing_progress_sheet.dart
index 33d6ee7de0..8903470d29 100644
--- a/mobile/apps/photos/lib/ui/sharing/widgets/sharing_progress_sheet.dart
+++ b/mobile/apps/photos/lib/ui/sharing/widgets/sharing_progress_sheet.dart
@@ -4,6 +4,7 @@ import "package:ente_components/ente_components.dart";
import "package:ente_strings/ente_strings.dart";
import "package:flutter/material.dart";
import "package:photos/utils/dialog_util.dart";
+import "package:rive/rive.dart" as rive;
Future<bool> showSharingProgressSheet(
BuildContext context, {
@@ -41,14 +42,71 @@ class _SharingProgressSheet extends StatefulWidget {
}
class _SharingProgressSheetState extends State<_SharingProgressSheet> {
- bool _succeeded = false;
+ static const _animationAsset = "assets/invite.riv";
+ static const _stateMachineName = "State Machine 1";
+ static const _successName = "success";
+
+ late final rive.FileLoader _animationLoader;
+ rive.ViewModelInstanceTrigger? _successTrigger;
+ bool _sharingSucceeded = false;
@override
void initState() {
super.initState();
+ _animationLoader = rive.FileLoader.fromAsset(
+ _animationAsset,
+ riveFactory: rive.Factory.flutter,
+ );
unawaited(_runTask());
}
+ @override
+ void dispose() {
+ _animationLoader.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return BottomSheetComponent(
+ showCloseButton: false,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ padding: const EdgeInsets.fromLTRB(Spacing.xl, 51, Spacing.xl, 44),
+ content: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ SizedBox.square(
+ dimension: 143,
+ child: ExcludeSemantics(
+ child: rive.RiveWidgetBuilder(
+ fileLoader: _animationLoader,
+ stateMachineSelector: const rive.StateMachineNamed(
+ _stateMachineName,
+ ),
+ dataBind: rive.DataBind.auto(),
+ onLoaded: _onRiveLoaded,
+ builder: (context, state) => state is rive.RiveLoaded
+ ? rive.RiveWidget(
+ controller: state.controller,
+ fit: rive.Fit.contain,
+ )
+ : const SizedBox.expand(),
+ ),
+ ),
+ ),
+ const SizedBox(height: 30),
+ Text(
+ context.strings.sharing,
+ textAlign: TextAlign.center,
+ style: TextStyles.display2.copyWith(
+ color: context.componentColors.textBase,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
Future<void> _runTask() async {
final succeeded = await widget.task();
if (!mounted) {
@@ -58,31 +116,24 @@ class _SharingProgressSheetState extends State<_SharingProgressSheet> {
Navigator.of(context).pop(false);
return;
}
- setState(() => _succeeded = true);
- await Future<void>.delayed(const Duration(seconds: 1));
- if (mounted) {
- Navigator.of(context).pop(true);
+ _sharingSucceeded = true;
+ _successTrigger?.trigger();
+ }
+
+ void _onRiveLoaded(rive.RiveLoaded state) {
+ state.controller.stateMachine.addEventListener(_onRiveEvent);
+ _successTrigger = state.viewModelInstance?.trigger(_successName);
+ if (_sharingSucceeded) {
+ _successTrigger?.trigger();
}
}
- @override
- Widget build(BuildContext context) {
- return BottomSheetComponent(
- title: _succeeded ? context.strings.success : context.strings.sharing,
- showCloseButton: false,
- illustration: _succeeded
- ? Icon(
- Icons.check_circle,
- color: context.componentColors.primary,
- size: IconSizes.large,
- )
- : SizedBox.square(
- dimension: IconSizes.medium,
- child: CircularProgressIndicator(
- color: context.componentColors.primary,
- strokeWidth: 2,
- ),
- ),
- );
+ Future<void> _onRiveEvent(rive.Event event) async {
+ if (event.name == _successName) {
+ await Future<void>.delayed(const Duration(milliseconds: 250));
+ if (mounted) {
+ Navigator.of(context).pop(true);
+ }
+ }
}
}