Skip to content

Commit

Permalink
fix: The indicator does not retract when the height of the list chang…
Browse files Browse the repository at this point in the history
…es (#618).
  • Loading branch information
xuelongqy committed Jan 12, 2023
1 parent c0dc8b5 commit 3ddb4be
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Next
- fix: The indicator does not retract when the height of the list changes [#618](https://github.com/xuelongqy/flutter_easy_refresh/issues/618).

## 3.2.2+1
- fix: CupertinoActivityIndicator renamed to avoid conflicts.

Expand Down
4 changes: 2 additions & 2 deletions example/lib/page/style/halloween_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class _HalloweenPageState extends State<HalloweenPage> {
return Scaffold(
body: EasyRefresh(
controller: _controller,
header: HalloweenHeader(
header: const HalloweenHeader(
position: IndicatorPosition.locator,
),
footer: HalloweenFooter(
footer: const HalloweenFooter(
position: IndicatorPosition.locator,
),
onRefresh: () async {
Expand Down
2 changes: 2 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import FlutterMacOS
import Foundation

import rive_common
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
RivePlugin.register(with: registry.registrar(forPlugin: "RivePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:
get: ^4.6.5
convert: ^3.1.1
carousel_slider: ^4.2.1
rive: 0.9.1
rive: ^0.10.1
qr_flutter: ^4.0.0
flutter_svg: ^1.1.6
flutter_sticky_header: ^0.6.5
Expand Down
3 changes: 3 additions & 0 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

#include "generated_plugin_registrant.h"

#include <rive_common/rive_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
RivePluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("RivePlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
rive_common
url_launcher_windows
)

Expand Down
39 changes: 22 additions & 17 deletions lib/src/notifier/indicator_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ abstract class IndicatorNotifier extends ChangeNotifier {
double get offset => _offset;

/// The current scroll position.
ScrollMetrics get position => _position;
ScrollMetrics get position => _position!;

set position(ScrollMetrics value) {
if (value.isNestedOuter) {
Expand All @@ -152,9 +152,14 @@ abstract class IndicatorNotifier extends ChangeNotifier {
_viewportDimension = null;
}
_position = value;
_lastMaxScrollExtent = value.maxScrollExtent;
}

late ScrollMetrics _position;
ScrollMetrics? _position;

/// Cache maxScrollExtent.
/// Used to compare the last value.
double? _lastMaxScrollExtent;

/// The current scroll velocity.
double _velocity = 0;
Expand Down Expand Up @@ -422,7 +427,7 @@ abstract class IndicatorNotifier extends ChangeNotifier {
/// Animation listener for [clamping].
void _clampingTick() {
final mOffset = calculateOffsetWithPixels(
_position, _clampingAnimationController!.value);
position, _clampingAnimationController!.value);
if (hasSecondary &&
!noMoreLocked &&
mOffset > secondaryDimension &&
Expand Down Expand Up @@ -509,7 +514,7 @@ abstract class IndicatorNotifier extends ChangeNotifier {
if (_mode == IndicatorMode.done ||
// Handling infinite scroll
(infiniteOffset != null &&
(!_position.isNestedOuter && edgeOffset < infiniteOffset!) &&
(!position.isNestedOuter && edgeOffset < infiniteOffset!) &&
!bySimulation &&
!_infiniteExclude(position, value))) {
// Update mode
Expand Down Expand Up @@ -571,9 +576,9 @@ abstract class IndicatorNotifier extends ChangeNotifier {
}
// Infinite scroll
if (infiniteOffset != null &&
(!_position.isNestedOuter && edgeOffset < infiniteOffset!)) {
(!position.isNestedOuter && edgeOffset < infiniteOffset!)) {
if (_mode == IndicatorMode.done &&
_position.maxScrollExtent != _position.minScrollExtent) {
position.maxScrollExtent != position.minScrollExtent) {
// The state does not change until the end
return;
} else {
Expand Down Expand Up @@ -746,7 +751,7 @@ abstract class IndicatorNotifier extends ChangeNotifier {
if (clamping && !userOffsetNotifier.value) {
// Sucks. When clamping, the position will not change after the task is completed.
// Temporary solution like this, there is a better way to replace.
double pixels = _position.pixels;
double pixels = position.pixels;
const tiny = 0.001;
pixels -= tiny;
(_position as ScrollPosition).jumpTo(pixels);
Expand Down Expand Up @@ -800,7 +805,7 @@ abstract class IndicatorNotifier extends ChangeNotifier {
// Actively update the offset if the user does not release
if (!clamping && userOffsetNotifier.value) {
Future(() {
_updateOffset(_position, _position.pixels, false);
_updateOffset(position, position.pixels, false);
});
}
}
Expand Down Expand Up @@ -958,7 +963,7 @@ class HeaderNotifier extends IndicatorNotifier {

/// See [IndicatorNotifier.edgeOffset].
@override
double get edgeOffset => _position.pixels;
double get edgeOffset => position.pixels;

@override
bool _infiniteExclude(ScrollMetrics position, double value) {
Expand Down Expand Up @@ -988,21 +993,21 @@ class HeaderNotifier extends IndicatorNotifier {
scrollController
.jumpTo(scrollController.positions.first.minScrollExtent);
} else {
(_position as ScrollPosition).jumpTo(_position.minScrollExtent);
(_position as ScrollPosition).jumpTo(position.minScrollExtent);
}
}
if (clamping) {
if (duration == null) {
_offset = offset;
_mode = mode;
_updateBySimulation(_position, 0);
_updateBySimulation(position, 0);
} else {
userOffsetNotifier.value = true;
_clampingAnimationController!.value = position.minScrollExtent;
await _clampingAnimationController!
.animateTo(scrollTo, duration: duration, curve: curve);
userOffsetNotifier.value = false;
_updateBySimulation(_position, 0);
_updateBySimulation(position, 0);
}
} else {
if (_position is ScrollPosition) {
Expand Down Expand Up @@ -1122,7 +1127,7 @@ class FooterNotifier extends IndicatorNotifier {

/// See [IndicatorNotifier.edgeOffset].
@override
double get edgeOffset => _position.maxScrollExtent - _position.pixels;
double get edgeOffset => position.maxScrollExtent - position.pixels;

@override
bool _infiniteExclude(ScrollMetrics position, double value) {
Expand All @@ -1145,28 +1150,28 @@ class FooterNotifier extends IndicatorNotifier {
} catch (_) {
return;
}
final scrollTo = _position.maxScrollExtent + offset;
final scrollTo = position.maxScrollExtent + offset;
_releaseOffset = offset;
if (jumpToEdge) {
if (scrollController != null) {
scrollController
.jumpTo(scrollController.positions.first.maxScrollExtent);
} else {
(_position as ScrollPosition).jumpTo(_position.maxScrollExtent);
(_position as ScrollPosition).jumpTo(position.maxScrollExtent);
}
}
if (clamping) {
if (duration == null) {
_offset = offset;
_mode = mode;
_updateBySimulation(_position, 0);
_updateBySimulation(position, 0);
} else {
userOffsetNotifier.value = true;
_clampingAnimationController!.value = position.maxScrollExtent;
await _clampingAnimationController!
.animateTo(scrollTo, duration: duration, curve: curve);
userOffsetNotifier.value = false;
_updateBySimulation(_position, 0);
_updateBySimulation(position, 0);
}
} else {
if (_position is ScrollPosition) {
Expand Down
3 changes: 3 additions & 0 deletions lib/src/physics/scroll_physics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ class _ERScrollPhysics extends BouncingScrollPhysics {
// User stopped scrolling.
final oldUserOffset = userOffsetNotifier.value;
userOffsetNotifier.value = false;
final oldMaxScrollExtent =
headerNotifier._lastMaxScrollExtent ?? position.maxScrollExtent;
// Simulation update.
headerNotifier._updateBySimulation(position, velocity);
footerNotifier._updateBySimulation(position, velocity);
Expand All @@ -462,6 +464,7 @@ class _ERScrollPhysics extends BouncingScrollPhysics {
footerNotifier._mode == IndicatorMode.secondaryOpen);
bool secondary = hSecondary || fSecondary;
if (velocity.abs() >= tolerance.velocity ||
(oldMaxScrollExtent != position.maxScrollExtent) ||
(position.outOfRange || (secondary && oldUserOffset)) &&
(oldUserOffset ||
_headerSimulationCreationState.value.needCreation(hState) ||
Expand Down

0 comments on commit 3ddb4be

Please sign in to comment.