Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat: adopt rive native renderer

laurenspriema8efe4a4f90c
diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dart
index 8dfcbad97e..396f7b4176 100644
--- a/mobile/apps/photos/lib/main.dart
+++ b/mobile/apps/photos/lib/main.dart
@@ -49,6 +49,7 @@ import 'package:photos/ui/tools/lock_screen.dart';
import "package:photos/utils/email_util.dart";
import 'package:photos/utils/file_uploader.dart';
import "package:photos/utils/lock_screen_settings.dart";
+import 'package:rive/rive.dart' as rive;
import 'package:shared_preferences/shared_preferences.dart';
final _logger = Logger("main");
@@ -68,6 +69,7 @@ void main() async {
debugRepaintRainbowEnabled = false;
await RustLib.init();
WidgetsFlutterBinding.ensureInitialized();
+ await rive.RiveNative.init();
MediaKit.ensureInitialized();
final savedThemeMode = await AdaptiveTheme.getThemeMode();
diff --git a/mobile/apps/photos/lib/ui/tools/similar_images_page.dart b/mobile/apps/photos/lib/ui/tools/similar_images_page.dart
index 8649f9f8be..5233865d1e 100644
--- a/mobile/apps/photos/lib/ui/tools/similar_images_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/similar_images_page.dart
@@ -28,7 +28,7 @@ import "package:photos/utils/delete_file_util.dart";
import "package:photos/utils/dialog_util.dart";
import "package:photos/utils/navigation_util.dart";
import "package:photos/utils/standalone/data.dart";
-import "package:rive/rive.dart" show RiveAnimation;
+import "package:rive/rive.dart" as rive;
enum SimilarImagesPageState {
setup,
@@ -1216,10 +1216,15 @@ class _LoadingScreenState extends State<_LoadingScreen> {
int _currentTextIndex = 0;
late List<String> _loadingTexts;
+ late final rive.FileLoader _analysisAnimationLoader;
@override
void initState() {
super.initState();
+ _analysisAnimationLoader = rive.FileLoader.fromAsset(
+ 'assets/ducky_analyze_files.riv',
+ riveFactory: rive.Factory.rive,
+ );
_startTextCycling();
}
@@ -1242,6 +1247,7 @@ class _LoadingScreenState extends State<_LoadingScreen> {
@override
void dispose() {
_timer?.cancel();
+ _analysisAnimationLoader.dispose();
super.dispose();
}
@@ -1261,11 +1267,19 @@ class _LoadingScreenState extends State<_LoadingScreen> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
- const SizedBox(
+ SizedBox(
height: 160,
- child: RiveAnimation.asset(
- 'assets/ducky_analyze_files.riv',
- fit: BoxFit.contain,
+ child: rive.RiveWidgetBuilder(
+ fileLoader: _analysisAnimationLoader,
+ builder: (BuildContext context, rive.RiveState state) {
+ if (state is rive.RiveLoaded) {
+ return rive.RiveWidget(
+ controller: state.controller,
+ fit: rive.Fit.contain,
+ );
+ }
+ return const SizedBox.expand();
+ },
),
),
const SizedBox(height: 16),
diff --git a/mobile/apps/photos/lib/ui/wrapped/wrapped_rewind_banner_button.dart b/mobile/apps/photos/lib/ui/wrapped/wrapped_rewind_banner_button.dart
index 270839a0ed..e6485f9689 100644
--- a/mobile/apps/photos/lib/ui/wrapped/wrapped_rewind_banner_button.dart
+++ b/mobile/apps/photos/lib/ui/wrapped/wrapped_rewind_banner_button.dart
@@ -5,7 +5,7 @@ import "package:photos/services/wrapped/wrapped_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/notification/toast.dart";
import "package:photos/ui/wrapped/wrapped_viewer_page.dart";
-import "package:rive/rive.dart" show Artboard, Fill, RiveAnimation;
+import "package:rive/rive.dart" as rive;
class WrappedRewindBannerButton extends StatefulWidget {
const WrappedRewindBannerButton({
@@ -23,8 +23,24 @@ class WrappedRewindBannerButton extends StatefulWidget {
}
class _WrappedRewindBannerButtonState extends State<WrappedRewindBannerButton> {
+ late final rive.FileLoader _riveFileLoader;
double? _artboardAspectRatio;
+ @override
+ void initState() {
+ super.initState();
+ _riveFileLoader = rive.FileLoader.fromAsset(
+ "assets/ente_rewind_banner.riv",
+ riveFactory: rive.Factory.rive,
+ );
+ }
+
+ @override
+ void dispose() {
+ _riveFileLoader.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
final enteColorScheme = getEnteColorScheme(context);
@@ -64,11 +80,25 @@ class _WrappedRewindBannerButtonState extends State<WrappedRewindBannerButton> {
alignment: Alignment.center,
children: [
Positioned.fill(
- child: RiveAnimation.asset(
- "assets/ente_rewind_banner.riv",
- fit: BoxFit.cover,
- stateMachines: const ["State Machine 1"],
- onInit: _onRiveInit,
+ child: rive.RiveWidgetBuilder(
+ fileLoader: _riveFileLoader,
+ stateMachineSelector: const rive.StateMachineNamed(
+ "State Machine 1",
+ ),
+ onLoaded: _handleRiveLoaded,
+ builder:
+ (BuildContext context, rive.RiveState state) {
+ if (state is rive.RiveLoaded) {
+ return rive.RiveWidget(
+ controller: state.controller,
+ fit: rive.Fit.cover,
+ );
+ }
+ if (state is rive.RiveFailed) {
+ return const ColoredBox(color: Colors.black);
+ }
+ return const SizedBox.expand();
+ },
),
),
Container(
@@ -116,11 +146,11 @@ class _WrappedRewindBannerButtonState extends State<WrappedRewindBannerButton> {
);
}
- void _onRiveInit(Artboard artboard) {
- _sanitizeFillRules(artboard);
+ void _handleRiveLoaded(rive.RiveLoaded loaded) {
if (!mounted) return;
- final double height = artboard.height;
- final double width = artboard.width;
+ final rive.AABB bounds = loaded.controller.artboard.bounds;
+ final double height = bounds.height;
+ final double width = bounds.width;
if (height <= 0 || width <= 0) {
return;
}
@@ -133,15 +163,6 @@ class _WrappedRewindBannerButtonState extends State<WrappedRewindBannerButton> {
});
}
- void _sanitizeFillRules(Artboard artboard) {
- artboard.forEachComponent((component) {
- if (component is! Fill) return;
- if (component.fillRule >= PathFillType.values.length) {
- component.fillRule = PathFillType.nonZero.index;
- }
- });
- }
-
void _handleTap(BuildContext context) {
final WrappedEntryState currentState = wrappedService.state;
final WrappedResult? result = currentState.result;
diff --git a/mobile/apps/photos/pubspec.lock b/mobile/apps/photos/pubspec.lock
index c81bf52c83..0cb1522f14 100644
--- a/mobile/apps/photos/pubspec.lock
+++ b/mobile/apps/photos/pubspec.lock
@@ -2200,18 +2200,18 @@ packages:
dependency: "direct main"
description:
name: rive
- sha256: "2551a44fa766a7ed3f52aa2b94feda6d18d00edc25dee5f66e72e9b365bb6d6c"
+ sha256: "20d91e17b1bae5f4030d252336227f990782c942cb44e41685a13ae5f885e641"
url: "https://pub.dev"
source: hosted
- version: "0.13.20"
- rive_common:
+ version: "0.14.0-dev.13"
+ rive_native:
dependency: transitive
description:
- name: rive_common
- sha256: "2ba42f80d37a4efd0696fb715787c4785f8a13361e8aea9227c50f1e78cf763a"
+ name: rive_native
+ sha256: "1b65b473939b008feb30c1f43785996063cefaf4ceddfa1a2ffe6051201e8d3a"
url: "https://pub.dev"
source: hosted
- version: "0.4.15"
+ version: "0.0.16"
rust_lib_photos:
dependency: "direct main"
description:
diff --git a/mobile/apps/photos/pubspec.yaml b/mobile/apps/photos/pubspec.yaml
index 3c9cd7bcd2..dcbf73ed18 100644
--- a/mobile/apps/photos/pubspec.yaml
+++ b/mobile/apps/photos/pubspec.yaml
@@ -188,7 +188,7 @@ dependencies:
git:
url: https://github.com/KasemJaffer/receive_sharing_intent.git
ref: 2cea396
- rive: ^0.13.20
+ rive: 0.14.0-dev.13
rust_lib_photos:
path: rust_builder
screenshot: ^3.0.0