From 8b4e4b468fae5074fc8ca5a4c6eb4cf1065d0dff Mon Sep 17 00:00:00 2001 From: Zach Plata Date: Tue, 27 Sep 2022 12:40:54 -0500 Subject: [PATCH] adding example in for listener issue with scrolling view --- CHANGELOG.md | 4 +++ example/lib/simple_state_machine.dart | 30 ++++++++--------- .../animation/nested_state_machine.dart | 7 ++-- .../rive_core/state_machine_controller.dart | 32 +++++++++++++++---- lib/src/runtime_nested_artboard.dart | 4 +-- lib/src/widgets/rive_animation.dart | 2 +- pubspec.yaml | 2 +- 7 files changed, 50 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b4c633..e2ccd75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.2 + +- Prevents scroll views from scrolling when dragging listeners. + ## 0.9.1 - Support for Nested Inputs. diff --git a/example/lib/simple_state_machine.dart b/example/lib/simple_state_machine.dart index a5fcf56..76a5a95 100644 --- a/example/lib/simple_state_machine.dart +++ b/example/lib/simple_state_machine.dart @@ -9,16 +9,6 @@ class SimpleStateMachine extends StatefulWidget { } class _SimpleStateMachineState extends State { - SMITrigger? _bump; - - void _onRiveInit(Artboard artboard) { - final controller = StateMachineController.fromArtboard(artboard, 'bumpy'); - artboard.addController(controller!); - _bump = controller.findInput('bump') as SMITrigger; - } - - void _hitBump() => _bump?.fire(); - @override Widget build(BuildContext context) { return Scaffold( @@ -26,13 +16,19 @@ class _SimpleStateMachineState extends State { title: const Text('Simple Animation'), ), body: Center( - child: GestureDetector( - child: RiveAnimation.network( - 'https://cdn.rive.app/animations/vehicles.riv', - fit: BoxFit.cover, - onInit: _onRiveInit, - ), - onTap: _hitBump, + child: ListView( + children: const [ + SizedBox( + width: 500, + height: 500, + child: RiveAnimation.asset( + 'assets/simple.riv', + stateMachines: ["State Machine 1"], + ), + ), + SizedBox(height: 2000, width: 500, child: Text("hi")), + SizedBox(height: 2000, width: 500, child: Text("bye")) + ], ), ), ); diff --git a/lib/src/rive_core/animation/nested_state_machine.dart b/lib/src/rive_core/animation/nested_state_machine.dart index 6663cdc..ce2364d 100644 --- a/lib/src/rive_core/animation/nested_state_machine.dart +++ b/lib/src/rive_core/animation/nested_state_machine.dart @@ -1,4 +1,5 @@ import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; import 'package:rive/src/core/core.dart'; import 'package:rive/src/generated/animation/nested_state_machine_base.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; @@ -14,7 +15,7 @@ abstract class NestedStateMachineInstance { void pointerMove(Vec2D position); - void pointerDown(Vec2D position); + void pointerDown(Vec2D position, PointerDownEvent event); void pointerUp(Vec2D position); @@ -57,8 +58,8 @@ class NestedStateMachine extends NestedStateMachineBase { void pointerMove(Vec2D position) => _stateMachineInstance?.pointerMove(position); - void pointerDown(Vec2D position) => - _stateMachineInstance?.pointerDown(position); + void pointerDown(Vec2D position, PointerDownEvent event) => + _stateMachineInstance?.pointerDown(position, event); void pointerUp(Vec2D position) => _stateMachineInstance?.pointerUp(position); diff --git a/lib/src/rive_core/state_machine_controller.dart b/lib/src/rive_core/state_machine_controller.dart index 8098ada..c22db6f 100644 --- a/lib/src/rive_core/state_machine_controller.dart +++ b/lib/src/rive_core/state_machine_controller.dart @@ -1,5 +1,6 @@ import 'dart:collection'; +import 'package:flutter/gestures.dart'; import 'package:flutter/scheduler.dart'; import 'package:rive/src/core/core.dart'; import 'package:rive/src/rive_core/animation/animation_state.dart'; @@ -256,6 +257,8 @@ class StateMachineController extends RiveAnimationController { late CoreContext core; + final _recognizer = ImmediateMultiDragGestureRecognizer(); + @override bool init(CoreContext core) { this.core = core; @@ -344,10 +347,15 @@ class StateMachineController extends RiveAnimationController { isActive = keepGoing; } - void _processEvent(Vec2D position, {ListenerType? hitEvent}) { + bool _processEvent( + Vec2D position, { + PointerDownEvent? event, + ListenerType? hitEvent, + }) { + assert(hitEvent != ListenerType.down || event != null); var artboard = this.artboard; if (artboard == null) { - return; + return false; } if (artboard.frameOrigin) { // ignore: parameter_assignments @@ -365,6 +373,8 @@ class StateMachineController extends RiveAnimationController { (position.y + hitRadius).round(), ); + bool foundTarget = false; + for (final hitShape in hitShapes) { // for (final hitShape in event.shapes) { var shape = hitShape.shape; @@ -383,6 +393,7 @@ class StateMachineController extends RiveAnimationController { // user-selectable value in the inspector? // Just use bounds for now + foundTarget = true; isOver = hitTester.test(); } @@ -418,7 +429,7 @@ class StateMachineController extends RiveAnimationController { in nestedArtboard.animations.whereType()) { switch (hitEvent) { case ListenerType.down: - nestedStateMachine.pointerDown(nestedPosition); + nestedStateMachine.pointerDown(nestedPosition, event!); break; case ListenerType.up: nestedStateMachine.pointerUp(nestedPosition); @@ -429,6 +440,7 @@ class StateMachineController extends RiveAnimationController { } } } + return foundTarget; } void pointerMove(Vec2D position) => _processEvent( @@ -436,10 +448,16 @@ class StateMachineController extends RiveAnimationController { hitEvent: ListenerType.move, ); - void pointerDown(Vec2D position) => _processEvent( - position, - hitEvent: ListenerType.down, - ); + void pointerDown(Vec2D position, PointerDownEvent event) { + final foundTarget = _processEvent( + position, + event: event, + hitEvent: ListenerType.down, + ); + if (foundTarget) { + _recognizer.addPointer(event); + } + } void pointerUp(Vec2D position) => _processEvent( position, diff --git a/lib/src/runtime_nested_artboard.dart b/lib/src/runtime_nested_artboard.dart index e04d712..4b9f3a7 100644 --- a/lib/src/runtime_nested_artboard.dart +++ b/lib/src/runtime_nested_artboard.dart @@ -113,8 +113,8 @@ class RuntimeNestedStateMachineInstance extends NestedStateMachineInstance { stateMachineController.isActiveChanged; @override - void pointerDown(Vec2D position) => - stateMachineController.pointerDown(position); + void pointerDown(Vec2D position, PointerDownEvent event) => + stateMachineController.pointerDown(position, event); @override void pointerMove(Vec2D position) => diff --git a/lib/src/widgets/rive_animation.dart b/lib/src/widgets/rive_animation.dart index 1c4aafd..3538c66 100644 --- a/lib/src/widgets/rive_animation.dart +++ b/lib/src/widgets/rive_animation.dart @@ -272,7 +272,7 @@ class RiveAnimationState extends State { onPointerDown: (details) => hitHelper( details, (controller, artboardPosition) => - controller.pointerDown(artboardPosition), + controller.pointerDown(artboardPosition, details), ), onPointerUp: (details) => hitHelper( details, diff --git a/pubspec.yaml b/pubspec.yaml index 1918a24..a768541 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.9.1 +version: 0.9.2 repository: https://github.com/rive-app/rive-flutter homepage: https://rive.app