mirror of
https://github.com/rive-app/rive-flutter
synced 2025-07-05 21:55:58 +00:00
adding example in for listener issue with scrolling view
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
## 0.9.2
|
||||
|
||||
- Prevents scroll views from scrolling when dragging listeners.
|
||||
|
||||
## 0.9.1
|
||||
|
||||
- Support for Nested Inputs.
|
||||
|
@ -9,16 +9,6 @@ class SimpleStateMachine extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SimpleStateMachineState extends State<SimpleStateMachine> {
|
||||
SMITrigger? _bump;
|
||||
|
||||
void _onRiveInit(Artboard artboard) {
|
||||
final controller = StateMachineController.fromArtboard(artboard, 'bumpy');
|
||||
artboard.addController(controller!);
|
||||
_bump = controller.findInput<bool>('bump') as SMITrigger;
|
||||
}
|
||||
|
||||
void _hitBump() => _bump?.fire();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -26,13 +16,19 @@ class _SimpleStateMachineState extends State<SimpleStateMachine> {
|
||||
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"))
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<CoreContext> {
|
||||
|
||||
late CoreContext core;
|
||||
|
||||
final _recognizer = ImmediateMultiDragGestureRecognizer();
|
||||
|
||||
@override
|
||||
bool init(CoreContext core) {
|
||||
this.core = core;
|
||||
@ -344,10 +347,15 @@ class StateMachineController extends RiveAnimationController<CoreContext> {
|
||||
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<CoreContext> {
|
||||
(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<CoreContext> {
|
||||
// user-selectable value in the inspector?
|
||||
|
||||
// Just use bounds for now
|
||||
foundTarget = true;
|
||||
isOver = hitTester.test();
|
||||
}
|
||||
|
||||
@ -418,7 +429,7 @@ class StateMachineController extends RiveAnimationController<CoreContext> {
|
||||
in nestedArtboard.animations.whereType<NestedStateMachine>()) {
|
||||
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<CoreContext> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return foundTarget;
|
||||
}
|
||||
|
||||
void pointerMove(Vec2D position) => _processEvent(
|
||||
@ -436,10 +448,16 @@ class StateMachineController extends RiveAnimationController<CoreContext> {
|
||||
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,
|
||||
|
@ -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) =>
|
||||
|
@ -272,7 +272,7 @@ class RiveAnimationState extends State<RiveAnimation> {
|
||||
onPointerDown: (details) => hitHelper(
|
||||
details,
|
||||
(controller, artboardPosition) =>
|
||||
controller.pointerDown(artboardPosition),
|
||||
controller.pointerDown(artboardPosition, details),
|
||||
),
|
||||
onPointerUp: (details) => hitHelper(
|
||||
details,
|
||||
|
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user