mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-22 19:40:10 +08:00
opt iOS ScrollPhysics
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -5,9 +5,11 @@
|
||||
// ignore_for_file: prefer_initializing_formals
|
||||
|
||||
import 'dart:async' show Completer;
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
import 'package:PiliPlus/common/widgets/scroll_behavior.dart';
|
||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart'
|
||||
show BouncingScrollPhysicsExt;
|
||||
import 'package:PiliPlus/utils/platform_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:extended_nested_scroll_view/src/refresh.dart';
|
||||
import 'package:flutter/foundation.dart' show clampDouble;
|
||||
@@ -543,8 +545,19 @@ class RefreshIndicatorState extends State<RefreshIndicator>
|
||||
),
|
||||
],
|
||||
);
|
||||
if (!widget.isClampingScrollPhysics &&
|
||||
(Platform.isIOS || Platform.isMacOS)) {
|
||||
if (PlatformUtils.isDarwin) {
|
||||
if (widget.isClampingScrollPhysics) {
|
||||
return ScrollConfiguration(
|
||||
behavior: RefreshScrollBehavior(
|
||||
desktopDragDevices,
|
||||
scrollPhysics: RefreshScrollPhysicsIOS(
|
||||
parent: const RangeMaintainingScrollPhysics(),
|
||||
onDrag: _onDrag,
|
||||
),
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
return ScrollConfiguration(
|
||||
@@ -640,3 +653,19 @@ class RefreshScrollPhysics extends ClampingScrollPhysics
|
||||
return RefreshScrollPhysics(parent: buildParent(ancestor), onDrag: onDrag);
|
||||
}
|
||||
}
|
||||
|
||||
class RefreshScrollPhysicsIOS extends BouncingScrollPhysicsExt
|
||||
with RefreshScrollPhysicsMixin {
|
||||
const RefreshScrollPhysicsIOS({super.parent, required this.onDrag});
|
||||
|
||||
@override
|
||||
final OnDrag onDrag;
|
||||
|
||||
@override
|
||||
RefreshScrollPhysicsIOS applyTo(ScrollPhysics? ancestor) {
|
||||
return RefreshScrollPhysicsIOS(
|
||||
parent: buildParent(ancestor),
|
||||
onDrag: onDrag,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPlus/common/widgets/flutter/page/tabs.dart';
|
||||
import 'package:PiliPlus/common/widgets/gesture/horizontal_drag_gesture_recognizer.dart';
|
||||
import 'package:PiliPlus/utils/platform_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:flutter/material.dart' hide TabBarView;
|
||||
|
||||
@@ -76,3 +77,49 @@ class ReloadScrollPhysics extends AlwaysScrollableScrollPhysics {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final platformClampingPhysics = PlatformUtils.isDarwin
|
||||
? const BouncingScrollPhysicsExt()
|
||||
: const ClampingScrollPhysics();
|
||||
|
||||
final platformAlwaysClampingPhysics = PlatformUtils.isDarwin
|
||||
? const AlwaysScrollableScrollPhysics(parent: BouncingScrollPhysicsExt())
|
||||
: const AlwaysScrollableScrollPhysics(parent: ClampingScrollPhysics());
|
||||
|
||||
class BouncingScrollPhysicsExt extends BouncingScrollPhysics
|
||||
with ClampingBoundaryMixin {
|
||||
const BouncingScrollPhysicsExt({super.parent});
|
||||
|
||||
@override
|
||||
BouncingScrollPhysicsExt applyTo(ScrollPhysics? ancestor) {
|
||||
return BouncingScrollPhysicsExt(parent: buildParent(ancestor));
|
||||
}
|
||||
}
|
||||
|
||||
/// [ClampingScrollPhysics.applyBoundaryConditions]
|
||||
mixin ClampingBoundaryMixin on ScrollPhysics {
|
||||
@override
|
||||
double applyBoundaryConditions(ScrollMetrics position, double value) {
|
||||
if (value < position.pixels &&
|
||||
position.pixels <= position.minScrollExtent) {
|
||||
// Underscroll.
|
||||
return value - position.pixels;
|
||||
}
|
||||
if (position.maxScrollExtent <= position.pixels &&
|
||||
position.pixels < value) {
|
||||
// Overscroll.
|
||||
return value - position.pixels;
|
||||
}
|
||||
if (value < position.minScrollExtent &&
|
||||
position.minScrollExtent < position.pixels) {
|
||||
// Hit top edge.
|
||||
return value - position.minScrollExtent;
|
||||
}
|
||||
if (position.pixels < position.maxScrollExtent &&
|
||||
position.maxScrollExtent < value) {
|
||||
// Hit bottom edge.
|
||||
return value - position.maxScrollExtent;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user