hitTestSelf method

  1. @override
bool hitTestSelf(
  1. Offset screenOffset
)

Override this method if this render object can be hit even if its children were not hit.

Returns true if the specified position should be considered a hit on this render object.

The caller is responsible for transforming position from global coordinates to its location relative to the origin of this RenderBox. This RenderBox is responsible for checking whether the given position is within its bounds.

Used by hitTest. If you override hitTest and do not call this function, then you don't need to implement this function.

Implementation

@override
bool hitTestSelf(Offset screenOffset) {
  switch (behavior) {
    case RiveHitTestBehavior.opaque:
      return true; // Always hit
    case RiveHitTestBehavior.translucent:
    case RiveHitTestBehavior.transparent:
      {
        // test to see if any Rive animation listeners were hit
        final artboardPosition = _toArtboard(screenOffset);
        final stateMachineControllers = _artboard.animationControllers
            .whereType<StateMachineController>();
        for (final stateMachineController in stateMachineControllers) {
          if (stateMachineController.hitTest(artboardPosition)) {
            return true;
          }
        }
      }
  }
  return false;
}