Skip to content

Commit ac9e215

Browse files
author
Kamil Klyta
committed
Fixed a bug causing the onRefresh method not being triggered on the iOS
1 parent ea9acf8 commit ac9e215

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Trigger mode support added. Equivalent to trigger mode of the built-in **RefreshIndicator** widget.
1414
- The **PositionedIndicatorContainer** class is no longer exported from this package, however the source code is available in the example application.
1515
- Now the *onRefresh* function will be triggered immediately when the indicator is released in the armed state. Previously, the *onRefresh* function was triggered when the indicator reached a target value in the loading state of `1.0`.
16+
- Fixed a bug causing the *onRefresh* method not being triggered on the iOS platform due to the use of bounce physics.
1617
- Multiple minor fixes, improvements and optimizations.
1718
## 1.2.1
1819
- Flutter 3.0.0 migration backward compatibility fix ([#31](https://github.com/gonuit/flutter-custom-refresh-indicator/pull/31)) by [Jordan1122](https://github.com/Jordan1122)

lib/src/custom_refresh_indicator.dart

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,25 @@ class CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
277277
}
278278

279279
bool _handleScrollUpdateNotification(ScrollUpdateNotification notification) {
280-
/// hide when list starts to scroll
281-
if (controller.isDragging || controller.isArmed) {
280+
// Calculate the edge if not defined and possible.
281+
// This may apply to two-way lists on the iOS platform with bouncing physics.
282+
if (!controller.hasEdge) {
283+
if (notification.metrics.extentBefore == 0 &&
284+
notification.scrollDelta?.isNegative == true) {
285+
controller.setIndicatorEdge(IndicatorEdge.start);
286+
} else if (notification.metrics.extentAfter == 0 &&
287+
notification.scrollDelta?.isNegative == false) {
288+
controller.setIndicatorEdge(IndicatorEdge.end);
289+
}
290+
}
291+
292+
/// When the controller is armed, but the scroll update event is not triggered
293+
/// by the user, the refresh action should be triggered
294+
if (controller.isArmed && notification.dragDetails == null) {
295+
_start();
296+
297+
/// Handle the indicator state depending on scrolling direction
298+
} else if (controller.isDragging || controller.isArmed) {
282299
switch (controller.edge) {
283300
case IndicatorEdge.start:
284301
if (notification.metrics.extentBefore > 0.0) {
@@ -304,10 +321,6 @@ class CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
304321
_hide();
305322
break;
306323
}
307-
308-
if (controller.isArmed && notification.dragDetails == null) {
309-
_start();
310-
}
311324
}
312325

313326
return false;

0 commit comments

Comments
 (0)