Skip to content

Commit

Permalink
Fix flutter validate() problem with drawable layouts
Browse files Browse the repository at this point in the history
This is a bit of an odd one related to not updating the flutter runtime since we moved to rive_native.

@drawsgood and I observed that sometimes nested artboards weren't rendering properly to the stage (the nested artboard would appear as an empty node). I narrowed this down to whenever a file contained a layout with either a fill or stroke.

The reason this was happening is because when we add a nested artboard, we use genRuntimeFile, which exports, then imports and validates the objects in the file. During the validation, if the file had a layout with a fill, the fill would attempt to validate, one of the conditions of which is that it's parent is a ShapePaintContainer. LayoutComponent IS a ShapePaintContainer, BUT the validate() happens against the flutter object, and since we haven't pushed updates to flutter, LayoutComponent there is NOT a ShapePaintContainer.

The easiest fix for this is to just add the bits to LayoutComponent in flutter related to extending ShapePaintContainer. I think this should be ok since the added code doesn't have anything to do with rive_native and the new rendering pathway.

One question I have is whether we should be continuing to validate against the flutter objects when it comes to nested artboards, now that we're using rive_native. @luigi-rosso perhaps we can discuss further when you are back in office.

Diffs=
c3137b923 Fix flutter validate() problem with drawable layouts (#7727)
d9f5701ec add listener actions support for databind (#7710)
dcb165130 Fix alignment when flex wrap enabled (#7722)
fbfa3b545 Buildsystem fixes for build_rive.sh and PLS shaders (#7716)
405ca998b add click event support (#7668)
4732c37b5 Improve layout animation (#7712)
a56419984 Simple procedural text rendering API (#7701)
d6d79132b Add a test for nested events triggering listener in parent (#7709)
657f65e1c Fix for nested events in CPP (#7708)
0a11e599f Add a build_rive.sh script to unify the premake5 build process (#7691)
d25b9097d viewmodel transitions runtime (#7680)

Co-authored-by: Philip Chung <philterdesign@gmail.com>
  • Loading branch information
philter and philter committed Aug 1, 2024
1 parent 2eb6dbe commit 2ab7604
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
462725b0766c65fe6b69530e86cd0de46a8795b3
c3137b923ca5d62771f85dcae10afcba6de083d3
31 changes: 30 additions & 1 deletion lib/src/rive_core/layout_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import 'package:rive/src/rive_core/component_dirt.dart';
import 'package:rive/src/rive_core/container_component.dart';
import 'package:rive/src/rive_core/layout/layout_component_style.dart';
import 'package:rive/src/rive_core/node.dart';
import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart';
import 'package:rive/src/rive_core/shapes/shape_paint_container.dart';
import 'package:rive/src/rive_core/world_transform_component.dart';
import 'package:rive_common/layout_engine.dart';
import 'package:rive_common/math.dart';
Expand All @@ -36,7 +38,7 @@ class LayoutAnimationData {
LayoutAnimationData(this.fromBounds, this.toBounds);
}

class LayoutComponent extends LayoutComponentBase {
class LayoutComponent extends LayoutComponentBase with ShapePaintContainer {
bool _forceUpdateLayoutBounds = false;

LayoutComponentStyle? _style;
Expand Down Expand Up @@ -139,6 +141,33 @@ class LayoutComponent extends LayoutComponentBase {
interpolationTime > 0;
}

@override
void onPaintMutatorChanged(ShapePaintMutator mutator) {
// The transform affects stroke property may have changed as we have a new
// mutator.
paintChanged();
}

@override
void onStrokesChanged() => paintChanged();

@override
void onFillsChanged() => paintChanged();

void paintChanged() {
addDirt(ComponentDirt.path);

// Add world transform dirt to the direct dependents (don't recurse) as
// things like ClippingShape directly depend on their referenced Shape. This
// allows them to recompute any stored values which can change when the
// transformAffectsStroke property changes (whether the path is in world
// space or not). Consider using a different dirt type if this pattern is
// repeated.
for (final d in dependents) {
d.addDirt(ComponentDirt.worldTransform);
}
}

void markLayoutNodeDirty() {
_layoutNode.markDirty();
artboard?.markLayoutDirty(this);
Expand Down

0 comments on commit 2ab7604

Please sign in to comment.