Skip to content

Commit

Permalink
fix: joystick handleSource not enabled for flutter runtime
Browse files Browse the repository at this point in the history
Fixes rive-app#331

An inconsistency between the editor and Flutter runtime. External control on a Joystick was not applied.

I used this file to reproduce and test: [joystickdemo2.rev.zip](https://github.com/rive-app/rive/files/12051102/joystickdemo2.rev.zip)

Expected behaviour (the handle is controlled by the position of the top rectangle):

https://github.com/rive-app/rive/assets/13705472/1eae3a71-5f2d-4375-a531-d36b61e5cc61

Diffs=
44f6c4b9c fix: joystick handleSource not enabled for flutter runtime (#5589)
d1f8710f5 Fix dependency order issues for Follow Path (#5595)

Co-authored-by: Gordon <pggordonhayes@gmail.com>
  • Loading branch information
edhom and HayesGordon committed Jul 24, 2023
1 parent 13adb8d commit 97e91e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/src/rive_core/artboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ class Artboard extends ArtboardBase with ShapePaintContainer {

// If joysticks applied, run the update again for the animation changes.
if (!canApplyJoysticksEarly && applyJoysticks()) {
updateComponents();

didUpdate = true;
if (updateComponents()) {
didUpdate = true;
}
}

if (nested) {
Expand Down
19 changes: 15 additions & 4 deletions lib/src/rive_core/joystick.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ class Joystick extends JoystickBase {
if (dirt & (ComponentDirt.transform | ComponentDirt.worldTransform) != 0) {
_worldTransform = computeWorldTransform();
Mat2D.invert(_inverseWorldTransform, _worldTransform);
if (handleSource != null) {
if (isComplex) {
var pos = _inverseWorldTransform * handleSource!.worldTranslation;
var local = localBounds.factorFrom(pos);

// In the editor we don't want to notify changes while we're in the
// update cycle.

x = local.x;
y = local.y;
}
Expand Down Expand Up @@ -96,6 +93,13 @@ class Joystick extends JoystickBase {
context.markNeedsAdvance();
}

@override
void buildDependencies() {
super.buildDependencies();
parent?.addDependent(this);
handleSource?.addDependent(this);
}

Vec2D get position => Vec2D.fromValues(posX, posY);
Mat2D _worldTransform = Mat2D();
final Mat2D _inverseWorldTransform = Mat2D();
Expand Down Expand Up @@ -170,6 +174,13 @@ class Joystick extends JoystickBase {
}
}

@override
void onAddedDirty() {
super.onAddedDirty();

handleSource = context.resolve(handleSourceId);
}

void _transformChanged() {
markTransformDirty();
}
Expand Down

0 comments on commit 97e91e6

Please sign in to comment.