pageview jumpto而不会解散用户的动画 /输入

发布于 2025-01-25 07:30:05 字数 452 浏览 4 评论 0原文

我正在尝试在用户更改页面时纠正我的页面浏览量的页面。 不幸的是,所有可能的页面更改操作(jumpto()animateto()jumptopage())解散当前的用户输入(或animation) 。看起来像:

  • 输入:用户将下一页拖动到
  • 编程更改:在页面更改期间调整操作称为
  • 当前输出:当前的阻力被置于并且页面跳跃(或动画)无需考虑进一步的用户输入所需页面的进一步输入

,而用户对pageview进行动画操作,是否有任何方法可以更改页面?因此,输出可能看起来像:

  • 所需的输出:当前阻力正在保留,并且页面只会更改。用户仍然可以继续拖动。

I am trying to correct a page of my PageView, while the user is changing pages.
Unfortunately, all possible page change operations (jumpTo(), animateTo(), jumpToPage()) dismiss the current user input (or animation). Which looks like:

  • Input: user drags to next page
  • Programatical change: during page change page adjust operation is called
  • Current Output: Current drag is dismissed and the page jumps ( or animates) without any regard to further user input to the desired page

Is there any way to change pages, while the user animates the pageview? So that the output might look like:

  • Desired Output: Current drag is being kept and the page only changes. User still can continue to drag.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩心态 2025-02-01 07:30:05

通常的操作否定了所有动画和用户输入。如文档中所述:

取消任何活动动画。如果用户当前滚动,则该操作被取消。

为了归档您要做的事情,您可以使用以下类扩展名:

class SmoothPageController extends PageController {
  SmoothPageController({
    int initialPage = 0,
    bool keepPage = true,
    double viewportFraction = 1.0,
  }) : super(
          initialPage: initialPage,
          keepPage: keepPage,
          viewportFraction: viewportFraction,
        );

  /// Jumps the scroll position from its current value to the given value,
  /// without animation, and without checking if the new value is in range.
  /// Any active animation is being kept. If the user is currently scrolling,
  /// that action is kept and will proceed as expected.
  /// Copied from ScrollController.
  void smoothJumpTo(double value) {
    assert(positions.isNotEmpty,
        'ScrollController not attached to any scroll views.');
    for (final ScrollPosition position in List<ScrollPosition>.of(positions)) {
      position.correctPixels(value);
    }
  }
}

现在您可以调用SmoothJumpto()就像jumpto(),但无需解雇活动动画,例如用户输入。

final SmoothPageController pageController = SmoothPageController(initialPage: 0);

The usual operations dismiss all animation and user inputs. As also described in the documentation:

Any active animation is canceled. If the user is currently scrolling, that action is canceled.

In order to archive what you are trying to do you can use the following class extension:

class SmoothPageController extends PageController {
  SmoothPageController({
    int initialPage = 0,
    bool keepPage = true,
    double viewportFraction = 1.0,
  }) : super(
          initialPage: initialPage,
          keepPage: keepPage,
          viewportFraction: viewportFraction,
        );

  /// Jumps the scroll position from its current value to the given value,
  /// without animation, and without checking if the new value is in range.
  /// Any active animation is being kept. If the user is currently scrolling,
  /// that action is kept and will proceed as expected.
  /// Copied from ScrollController.
  void smoothJumpTo(double value) {
    assert(positions.isNotEmpty,
        'ScrollController not attached to any scroll views.');
    for (final ScrollPosition position in List<ScrollPosition>.of(positions)) {
      position.correctPixels(value);
    }
  }
}

Now you can call smoothJumpTo() just like jumpTo() but without dismissing active animations, such as the user input.

final SmoothPageController pageController = SmoothPageController(initialPage: 0);
巴黎夜雨 2025-02-01 07:30:05

我改进了@Paul的答案,感谢他。在DART中,在这种情况下,使用扩展程序更方便。正确的像素不会取消任何动画或动作。

extension SmoothPageController on PageController {    
  /// Jumps the scroll position from its current value to the given value,
  /// without animation, and without checking if the new value is in range.
  /// Any active animation is being kept. If the user is currently scrolling,
  /// that action is kept and will proceed as expected.
  /// Copied from ScrollController.
  void smoothJumpTo(double value) {
    assert(positions.isNotEmpty,
        'ScrollController not attached to any scroll views.');
    for (final ScrollPosition position in List<ScrollPosition>.of(positions)) {
      position.correctPixels(value);
    }
  }
}

I improved @Paul's answer, thanks to him. In dart, it's more convenient to use extension in this case. Correct pixels doesn't cancel any animations or actions.

extension SmoothPageController on PageController {    
  /// Jumps the scroll position from its current value to the given value,
  /// without animation, and without checking if the new value is in range.
  /// Any active animation is being kept. If the user is currently scrolling,
  /// that action is kept and will proceed as expected.
  /// Copied from ScrollController.
  void smoothJumpTo(double value) {
    assert(positions.isNotEmpty,
        'ScrollController not attached to any scroll views.');
    for (final ScrollPosition position in List<ScrollPosition>.of(positions)) {
      position.correctPixels(value);
    }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文