mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
94 lines
2.5 KiB
Dart
94 lines
2.5 KiB
Dart
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
|
import 'package:PiliPlus/utils/storage.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
Widget videoTabBarView({
|
|
required List<Widget> children,
|
|
TabController? controller,
|
|
}) =>
|
|
TabBarView(
|
|
physics: const CustomTabBarViewClampingScrollPhysics(),
|
|
controller: controller,
|
|
children: children,
|
|
);
|
|
|
|
Widget tabBarView({
|
|
required List<Widget> children,
|
|
TabController? controller,
|
|
}) =>
|
|
TabBarView(
|
|
physics: const CustomTabBarViewScrollPhysics(),
|
|
controller: controller,
|
|
children: children,
|
|
);
|
|
|
|
class CustomTabBarViewScrollPhysics extends ScrollPhysics {
|
|
const CustomTabBarViewScrollPhysics({super.parent});
|
|
|
|
@override
|
|
CustomTabBarViewScrollPhysics applyTo(ScrollPhysics? ancestor) {
|
|
return CustomTabBarViewScrollPhysics(parent: buildParent(ancestor));
|
|
}
|
|
|
|
@override
|
|
SpringDescription get spring => SpringDescription(
|
|
mass: GStorage.springDescription[0],
|
|
stiffness: GStorage.springDescription[1],
|
|
damping: GStorage.springDescription[2],
|
|
);
|
|
}
|
|
|
|
class CustomTabBarViewClampingScrollPhysics extends ClampingScrollPhysics {
|
|
const CustomTabBarViewClampingScrollPhysics({super.parent});
|
|
|
|
@override
|
|
CustomTabBarViewClampingScrollPhysics applyTo(ScrollPhysics? ancestor) {
|
|
return CustomTabBarViewClampingScrollPhysics(parent: buildParent(ancestor));
|
|
}
|
|
|
|
@override
|
|
SpringDescription get spring => SpringDescription(
|
|
mass: GStorage.springDescription[0],
|
|
stiffness: GStorage.springDescription[1],
|
|
damping: GStorage.springDescription[2],
|
|
);
|
|
}
|
|
|
|
class CustomScrollPosition extends ScrollPositionWithSingleContext {
|
|
CustomScrollPosition({
|
|
required super.physics,
|
|
required super.context,
|
|
required this.onCancelDrag,
|
|
});
|
|
|
|
final ValueChanged<double> onCancelDrag;
|
|
|
|
@override
|
|
void applyUserOffset(double delta) {
|
|
if (isRefreshing && delta < 0) {
|
|
onCancelDrag(delta);
|
|
return;
|
|
}
|
|
super.applyUserOffset(delta);
|
|
}
|
|
}
|
|
|
|
class CustomScrollController extends ScrollController {
|
|
CustomScrollController(this.onCancelDrag);
|
|
|
|
final ValueChanged<double> onCancelDrag;
|
|
|
|
@override
|
|
CustomScrollPosition createScrollPosition(
|
|
ScrollPhysics physics,
|
|
ScrollContext context,
|
|
ScrollPosition? oldPosition,
|
|
) {
|
|
return CustomScrollPosition(
|
|
physics: physics.applyTo(const AlwaysScrollableScrollPhysics()),
|
|
context: context,
|
|
onCancelDrag: onCancelDrag,
|
|
);
|
|
}
|
|
}
|