Skip to content

Scrolling with animation to the next focusable node #83175

@websiddu

Description

@websiddu

Use case

When building for TV apps, the most common widget is a horizontal list (or row of cards), that can react to the D'Pad navigation. Flutter unlocks the D'pad navigation by using the Shortcuts widget. But currently when moving from one node to the other node, there is no smooth animation the whole row flashes to the next item.

It is desired to have a smooth horizontal animation or at latest as an option to so we don't have to build our own, scrolling.

More context

Proposal

This can be achieved by exposing the duration and curve arguments in the _focusAndEnsureVisible method.

void _focusAndEnsureVisible(
    FocusNode node, {
      ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicit,
    }) {
  node.requestFocus();
  Scrollable.ensureVisible(node.context!, alignment: 1.0, alignmentPolicy: alignmentPolicy);
}

Will become

void _focusAndEnsureVisible(FocusNode node, { Duration duration, Curve curve,
    ScrollPositionAlignmentPolicy alignmentPolicy =
        ScrollPositionAlignmentPolicy.explicit}) {
  node.requestFocus();
  Scrollable.ensureVisible(
    node.context!,
    alignment: 1.0,
    alignmentPolicy: alignmentPolicy,
    duration: duration,
    curve: curve,
  );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: animationAnimation APIsc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Fluttercustomer: googleVarious Google teamsf: focusFocus traversal, gaining or losing focusf: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions