presentationFor method

ShowcasePresentation? presentationFor(
  1. String anchorKey
)

The presentation for anchorKey under the active guide, or null when no guide is active or no step targets this anchor.

Implementation

ShowcasePresentation? presentationFor(String anchorKey) {
  final state = _orchestrator.state;
  if (state == null) return null;
  final scope = VariableScope.fromSchemas(
    state.campaign.config.defaultVariables,
    state.payload.variables,
  );
  final config = state.config;

  final behavior = config.outsideTapBehavior.trim().toLowerCase();
  final disableBarrier = behavior == 'nothing';
  final onBarrier = behavior == 'dismiss' ? () => _view.dismiss() : null;

  if (config is TooltipGuideConfig) {
    final step = _firstWhere(config.steps, (s) => s.anchorKey == anchorKey);
    if (step == null) return null;
    final stickyHold = config.sticky && step.actions.isNotEmpty;
    return ShowcasePresentation(
      container: GuideBubble.tooltip(
          step: step, scope: scope, onAction: handleAction),
      // Tooltip = no dim (RN renders the bubble over a transparent scrim).
      overlayColor: const Color(0x00000000),
      overlayOpacity: 0,
      targetShapeBorder:
          RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
      targetPadding: EdgeInsets.zero,
      tooltipPosition: _tooltipPosition(step.placement),
      showArrow: step.showArrow,
      // RN: arrowColor ?? backgroundColor — the arrow matches the bubble.
      arrowColor: step.arrowColor ?? step.backgroundColor,
      // RN: arrowBorderColor ?? borderColor; border width follows the bubble.
      arrowBorderColor: step.arrowBorderColor ?? step.borderColor,
      arrowBorderWidth: step.borderWidth,
      arrowSize: step.arrowSize,
      // RN tooltip: gap = showArrow ? arrowSize + 4 : 8. The arrow height is
      // reserved by the renderer, so we pass only the clearance beyond it.
      targetTooltipGap: step.showArrow ? 4 : 8,
      disableBarrierInteraction: stickyHold || disableBarrier,
      onBarrierClick: stickyHold ? null : onBarrier,
    );
  }
  if (config is SpotlightGuideConfig) {
    final step = _firstWhere(config.steps, (s) => s.anchorKey == anchorKey);
    if (step == null) return null;
    return ShowcasePresentation(
      container: GuideBubble.spotlight(
          step: step, scope: scope, onAction: handleAction),
      overlayColor: step.overlayColor,
      overlayOpacity: step.overlayOpacity,
      targetShapeBorder: _highlightShape(step),
      targetPadding: EdgeInsets.all(step.highlightPadding),
      tooltipPosition: _calloutPosition(step.calloutPosition),
      showArrow: step.showArrow,
      arrowColor: step.arrowColor ?? step.calloutBackgroundColor,
      arrowBorderColor: step.arrowBorderColor ?? step.calloutBorderColor,
      arrowBorderWidth: step.calloutBorderWidth,
      arrowSize: step.arrowSize,
      // RN spotlight: gap = calloutGap + (showArrow ? arrowSize : 0). The
      // arrow height is reserved by the renderer, so we pass calloutGap.
      targetTooltipGap: step.calloutGap,
      disableBarrierInteraction: disableBarrier,
      onBarrierClick: onBarrier,
    );
  }
  return null;
}