From 9363d4edbfee769991a165071a9b1040889f359c Mon Sep 17 00:00:00 2001 From: dab246 Date: Thu, 3 Apr 2025 22:03:38 +0700 Subject: [PATCH] TF-3507 Improve `PullToRefreshWidget` to increase performance Signed-off-by: dab246 --- .../pull_to_refresh/pull_to_refresh_widget.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/core/lib/presentation/views/pull_to_refresh/pull_to_refresh_widget.dart b/core/lib/presentation/views/pull_to_refresh/pull_to_refresh_widget.dart index 1cf7fe032..b3125e2f0 100644 --- a/core/lib/presentation/views/pull_to_refresh/pull_to_refresh_widget.dart +++ b/core/lib/presentation/views/pull_to_refresh/pull_to_refresh_widget.dart @@ -53,9 +53,18 @@ class _PullToRefreshWidgetState extends State { return NotificationListener( onNotification: (notification) { if (notification is ScrollUpdateNotification) { - setState(() { - _scrollOffset = notification.metrics.pixels; - }); + final newOffset = notification.metrics.pixels; + final crossedThreshold = + (_scrollOffset.abs() <= widget.deepRefreshThreshold && + newOffset.abs() > widget.deepRefreshThreshold) || + (_scrollOffset.abs() > widget.deepRefreshThreshold && + newOffset.abs() <= widget.deepRefreshThreshold); + + if (crossedThreshold || _scrollOffset != newOffset) { + setState(() { + _scrollOffset = newOffset; + }); + } } return false; },