Skip to content

Commit

Permalink
feat: Added EasyRefresh.isNested parameter to determine whether to ha…
Browse files Browse the repository at this point in the history
…ndle NestedScrollView.
  • Loading branch information
xuelongqy committed Jul 28, 2024
1 parent 343f08f commit 424b8e2
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Next
- feat: Added EasyRefresh.isNested parameter to determine whether to handle NestedScrollView. In versions 3.4.0 and earlier, no setting is required.
- fix: Adjust the Flutter version, Flutter >=3.10.0.

## 3.4.0
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
15 changes: 10 additions & 5 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -166,7 +166,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "The Chromium Authors";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -214,10 +214,12 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand All @@ -228,6 +230,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -265,10 +268,12 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/rive_common/rive_common.framework",
"${BUILT_PRODUCTS_DIR}/url_launcher_ios/url_launcher_ios.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/rive_common.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/url_launcher_ios.framework",
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -351,7 +356,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -432,7 +437,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -479,7 +484,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
1 change: 1 addition & 0 deletions example/lib/page/sample/tab_bar_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TabBarViewPageState extends State<TabBarViewPage>
final themeData = Theme.of(context);
return Scaffold(
body: EasyRefresh.builder(
isNested: true,
header: ClassicHeader(
clamping: true,
position: IndicatorPosition.locator,
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :osx, '10.11'
platform :osx, '10.14'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
13 changes: 8 additions & 5 deletions example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXAggregateTarget section */
Expand Down Expand Up @@ -205,7 +205,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "The Flutter Authors";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down Expand Up @@ -261,6 +261,7 @@
/* Begin PBXShellScriptBuildPhase section */
3399D490228B24CF009A79C7 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -325,10 +326,12 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/rive_common/rive_common.framework",
"${BUILT_PRODUCTS_DIR}/url_launcher_macos/url_launcher_macos.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/rive_common.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/url_launcher_macos.framework",
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -414,7 +417,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down Expand Up @@ -499,7 +502,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -547,7 +550,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1000"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
13 changes: 12 additions & 1 deletion lib/src/easy_refresh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class EasyRefresh extends StatefulWidget {
/// See [Stack.clipBehavior].
final Clip clipBehavior;

/// use [ERScrollBehavior] by default.
/// Use [ERScrollBehavior] by default.
///
/// example:
/// ```dart
Expand All @@ -157,6 +157,13 @@ class EasyRefresh extends StatefulWidget {
/// Other scroll directions will not show indicators and perform task.
final Axis? triggerAxis;

/// Use false by default.
/// When true, EasyRefresh handles NestedScrollView.
/// In versions 3.4.0 and earlier, no setting is required.
/// Because of automatic judgment, it will add burden to scenes that do not
/// need NestedScrollView.
final bool isNested;

/// Default header indicator.
static Header Function() defaultHeaderBuilder = _defaultHeaderBuilder;

Expand Down Expand Up @@ -203,6 +210,7 @@ class EasyRefresh extends StatefulWidget {
this.scrollBehaviorBuilder,
this.scrollController,
this.triggerAxis,
this.isNested = false,
}) : childBuilder = null,
assert(callRefreshOverOffset > 0,
'callRefreshOverOffset must be greater than 0.'),
Expand Down Expand Up @@ -234,6 +242,7 @@ class EasyRefresh extends StatefulWidget {
this.scrollBehaviorBuilder,
this.scrollController,
this.triggerAxis,
this.isNested = false,
}) : child = null,
assert(callRefreshOverOffset > 0,
'callRefreshOverOffset must be greater than 0.'),
Expand Down Expand Up @@ -361,13 +370,15 @@ class _EasyRefreshState extends State<EasyRefresh>
triggerAxis: widget.triggerAxis,
task: _onRefresh,
waitTaskRefresh: _waitRefreshResult,
isNested: widget.isNested,
);
_footerNotifier._update(
indicator: _footer,
canProcessAfterNoMore: widget.canLoadAfterNoMore,
triggerAxis: widget.triggerAxis,
task: widget.onLoad,
waitTaskRefresh: _waitLoadResult,
isNested: widget.isNested,
);
// Update controller.
if (widget.controller != null &&
Expand Down
5 changes: 5 additions & 0 deletions lib/src/indicator/indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ class IndicatorState {
axisDirection.hashCode ^
viewportDimension.hashCode ^
actualTriggerOffset.hashCode;

@override
String toString() {
return 'IndicatorState{indicator: $indicator, notifier: $notifier, userOffsetNotifier: $userOffsetNotifier, mode: $mode, result: $result, offset: $offset, safeOffset: $safeOffset, axis: $axis, axisDirection: $axisDirection, viewportDimension: $viewportDimension, actualTriggerOffset: $actualTriggerOffset}';
}
}

/// Indicator widget builder.
Expand Down
33 changes: 23 additions & 10 deletions lib/src/notifier/indicator_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,22 @@ abstract class IndicatorNotifier extends ChangeNotifier {
/// The current scroll position.
ScrollMetrics get position => _position!;

/// Handling NestedScrollView
bool _isNested = false;

bool get isNested => _isNested;

set position(ScrollMetrics value) {
if (value.isNestedOuter) {
_viewportDimension = value.viewportDimension;
} else if (value.isNestedInner) {
if (WidgetsBinding.instance.schedulerPhase !=
SchedulerPhase.persistentCallbacks) {
_viewportDimension = value.axis == Axis.vertical
? vsync.context.size?.height
: vsync.context.size?.width;
if (_isNested) {
if (value.isNestedOuter) {
_viewportDimension = value.viewportDimension;
} else if (value.isNestedInner) {
if (WidgetsBinding.instance.schedulerPhase !=
SchedulerPhase.persistentCallbacks) {
_viewportDimension = value.axis == Axis.vertical
? vsync.context.size?.height
: vsync.context.size?.width;
}
}
} else {
_viewportDimension = null;
Expand Down Expand Up @@ -389,6 +396,7 @@ abstract class IndicatorNotifier extends ChangeNotifier {
Axis? triggerAxis,
FutureOr Function()? task,
bool? waitTaskRefresh,
bool? isNested,
}) {
if (indicator != null) {
if (indicator.listenable == _indicator.listenable) {
Expand All @@ -412,6 +420,9 @@ abstract class IndicatorNotifier extends ChangeNotifier {
_clampingAnimationController?.dispose();
_clampingAnimationController = null;
}
if (isNested != null) {
_isNested = isNested;
}
notifyListeners();
}

Expand Down Expand Up @@ -548,7 +559,8 @@ abstract class IndicatorNotifier extends ChangeNotifier {
if (_mode == IndicatorMode.done ||
// Handling infinite scroll
(infiniteOffset != null &&
(!position.isNestedOuter && edgeOffset < infiniteOffset!) &&
(!(_isNested && position.isNestedOuter) &&
edgeOffset < infiniteOffset!) &&
!bySimulation &&
!_infiniteExclude(position, value))) {
// Update mode
Expand Down Expand Up @@ -616,7 +628,8 @@ abstract class IndicatorNotifier extends ChangeNotifier {
}
// Infinite scroll
if (infiniteOffset != null &&
(!position.isNestedOuter && edgeOffset < infiniteOffset!)) {
(!(_isNested && position.isNestedOuter) &&
edgeOffset < infiniteOffset!)) {
if (_mode == IndicatorMode.done &&
position.maxScrollExtent != position.minScrollExtent) {
if ((_result == IndicatorResult.fail ||
Expand Down
5 changes: 3 additions & 2 deletions lib/src/physics/scroll_physics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class _ERScrollPhysics extends BouncingScrollPhysics {

// Scrollable viewport dimension;
double viewportDimension = position.viewportDimension;
if (position.isNestedInner) {
if ((headerNotifier.isNested && position.isNestedInner)) {
if (headerNotifier._viewportDimension != null) {
viewportDimension = headerNotifier._viewportDimension!;
} else {
Expand Down Expand Up @@ -408,7 +408,8 @@ class _ERScrollPhysics extends BouncingScrollPhysics {
void _updateIndicatorOffset(
ScrollMetrics position, double offset, double value) {
// NestedScrollView special handling.
if (position.isNestedOuter &&
if (headerNotifier.isNested &&
position.isNestedOuter &&
headerNotifier._offset > 0 &&
value > position.minScrollExtent &&
!headerNotifier.modeLocked) {
Expand Down

0 comments on commit 424b8e2

Please sign in to comment.