From a13be5f2e27f839e9da24c0bff774867ee3e4811 Mon Sep 17 00:00:00 2001 From: Matt Sullivan <matt@rive.app> Date: Tue, 10 Nov 2020 18:52:16 -0800 Subject: [PATCH 1/2] Adds artboardByName to RiveFile and tests --- .gitignore | 1 + example/pubspec.lock | 160 ----------------------- lib/src/rive_file.dart | 10 +- pubspec.lock | 153 ---------------------- test/assets/multiple_artboards_0_6_2.riv | Bin 0 -> 249 bytes test/rive_file_test.dart | 56 ++++++++ 6 files changed, 66 insertions(+), 314 deletions(-) delete mode 100644 example/pubspec.lock delete mode 100644 pubspec.lock create mode 100644 test/assets/multiple_artboards_0_6_2.riv create mode 100644 test/rive_file_test.dart diff --git a/.gitignore b/.gitignore index bb431f0..5c27990 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ .pub-cache/ .pub/ build/ +pubspec.lock # Android related **/android/**/gradle-wrapper.jar diff --git a/example/pubspec.lock b/example/pubspec.lock deleted file mode 100644 index db8d062..0000000 --- a/example/pubspec.lock +++ /dev/null @@ -1,160 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.5.0-nullsafety.1" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.1" - characters: - dependency: transitive - description: - name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.3" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.1" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.1" - collection: - dependency: transitive - description: - name: collection - url: "https://pub.dartlang.org" - source: hosted - version: "1.15.0-nullsafety.3" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.1" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - graphs: - dependency: transitive - description: - name: graphs - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.0" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.10-nullsafety.1" - meta: - dependency: transitive - description: - name: meta - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0-nullsafety.3" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0-nullsafety.1" - rive: - dependency: "direct main" - description: - path: ".." - relative: true - source: path - version: "0.6.2" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0-nullsafety.2" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.10.0-nullsafety.1" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.1" - string_scanner: - dependency: transitive - description: - name: string_scanner - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.1" - term_glyph: - dependency: transitive - description: - name: term_glyph - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.1" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.19-nullsafety.2" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0-nullsafety.3" - vector_math: - dependency: transitive - description: - name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.3" -sdks: - dart: ">=2.10.0-110 <2.11.0" diff --git a/lib/src/rive_file.dart b/lib/src/rive_file.dart index 7928aa7..a2f18a8 100644 --- a/lib/src/rive_file.dart +++ b/lib/src/rive_file.dart @@ -21,11 +21,19 @@ class RiveFile { Backboard _backboard; Backboard get backboard => _backboard; - final List<Artboard> _artboards = []; + final _artboards = <Artboard>[]; + + /// Returns all artboards in the file List<Artboard> get artboards => _artboards; + /// Returns the first (main) artboard Artboard get mainArtboard => _artboards.first; + /// Returns an artboard from the specified name, or null if no artboard with + /// that name exists in the file + Artboard artboardByName(String name) => + _artboards.firstWhere((a) => a.name == name, orElse: () => null); + bool import(ByteData bytes) { assert(_header == null, 'can only import once'); var reader = BinaryReader(bytes); diff --git a/pubspec.lock b/pubspec.lock deleted file mode 100644 index 6af7cad..0000000 --- a/pubspec.lock +++ /dev/null @@ -1,153 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.5.0-nullsafety.1" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.1" - characters: - dependency: transitive - description: - name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.3" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.1" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.1" - collection: - dependency: transitive - description: - name: collection - url: "https://pub.dartlang.org" - source: hosted - version: "1.15.0-nullsafety.3" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.1" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - graphs: - dependency: "direct main" - description: - name: graphs - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.0" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.10-nullsafety.1" - meta: - dependency: "direct main" - description: - name: meta - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0-nullsafety.3" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0-nullsafety.1" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0-nullsafety.2" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.10.0-nullsafety.1" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.1" - string_scanner: - dependency: transitive - description: - name: string_scanner - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.1" - term_glyph: - dependency: transitive - description: - name: term_glyph - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.1" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.19-nullsafety.2" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0-nullsafety.3" - vector_math: - dependency: transitive - description: - name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.3" -sdks: - dart: ">=2.10.0-110 <2.11.0" diff --git a/test/assets/multiple_artboards_0_6_2.riv b/test/assets/multiple_artboards_0_6_2.riv new file mode 100644 index 0000000000000000000000000000000000000000..6db385e1117b95463d76326d9a5fd96c8c6189cd GIT binary patch literal 249 zcmWIY40B~;VtB^IAkM(T%*ev!SX7dfpIDTlV93tE@XMJ4L~t?y0T+ni1`#|Uf<c6p wfkB9sQPt4U@IM0sidG{etq%I?E+l9*M$!thh3kO6f(voBnjmQf+lp5!08~aNUH||9 literal 0 HcmV?d00001 diff --git a/test/rive_file_test.dart b/test/rive_file_test.dart new file mode 100644 index 0000000..2d81712 --- /dev/null +++ b/test/rive_file_test.dart @@ -0,0 +1,56 @@ +import 'dart:io'; +import 'dart:typed_data'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:rive/rive.dart'; + +void main() { + ByteData multipleArtboardsBytes; + + void loadTestAssets() { + multipleArtboardsBytes = ByteData.sublistView( + File('assets/multiple_artboards_0_6_2.riv').readAsBytesSync()); + } + + setUp(() { + loadTestAssets(); + }); + + test('Rive files load', () { + // Create a dummy RiveFile + final riveFile = RiveFile(); + expect(riveFile.import(multipleArtboardsBytes), true); + }); + + test('Rive files contain the correct number of artboards', () { + // Create a dummy RiveFile + final riveFile = RiveFile(); + riveFile.import(multipleArtboardsBytes); + expect(riveFile.artboards.length, 4); + }); + + test('A default artboard is available in a Rive file', () { + // Create a dummy RiveFile + final riveFile = RiveFile(); + riveFile.import(multipleArtboardsBytes); + expect(riveFile.mainArtboard, isNotNull); + expect(riveFile.mainArtboard.name, 'Artboard 1'); + }); + + test('Artboards can be retrieved by name', () { + // Create a dummy RiveFile + final riveFile = RiveFile(); + riveFile.import(multipleArtboardsBytes); + + var artboard = riveFile.artboardByName('Artboard 1'); + expect(artboard, isNotNull); + expect(artboard.name, 'Artboard 1'); + + artboard = riveFile.artboardByName('Artboard 3'); + expect(artboard, isNotNull); + expect(artboard.name, 'Artboard 3'); + + artboard = riveFile.artboardByName('Nonexistant'); + expect(artboard, isNull); + }); +} From 0efe3cddb1bd087907ceaa929e7bb671b87bf4f7 Mon Sep 17 00:00:00 2001 From: Matt Sullivan <matt@rive.app> Date: Tue, 10 Nov 2020 18:59:38 -0800 Subject: [PATCH 2/2] Version bump --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index e3820c1..5ab47b5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: rive description: Rive 2 Flutter Runtime. This package provides runtime functionality for playing back and interacting with animations built with the Rive editor available at https://rive.app. -version: 0.6.2+1 +version: 0.6.2+2 repository: https://github.com/rive-app/rive-flutter homepage: https://rive.app