mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-24 12:32:40 +08:00
improve Dyn/Topic DraggableScrollableSheet
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -2,27 +2,15 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// ignore_for_file: uri_does_not_exist_in_doc_import, depend_on_referenced_packages
|
||||
|
||||
/// @docImport 'package:flutter/material.dart';
|
||||
/// @docImport 'package:flutter_test/flutter_test.dart';
|
||||
///
|
||||
/// @docImport 'primary_scroll_controller.dart';
|
||||
/// @docImport 'scroll_configuration.dart';
|
||||
/// @docImport 'scroll_view.dart';
|
||||
/// @docImport 'scrollable.dart';
|
||||
/// @docImport 'single_child_scroll_view.dart';
|
||||
/// @docImport 'viewport.dart';
|
||||
library;
|
||||
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:PiliPlus/common/widgets/flutter/layout_builder.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart'
|
||||
hide DraggableScrollableSheet, LayoutBuilder;
|
||||
import 'package:flutter/material.dart' hide DraggableScrollableSheet;
|
||||
|
||||
part 'package:PiliPlus/common/widgets/draggable_sheet/dyn.dart';
|
||||
part 'package:PiliPlus/common/widgets/draggable_sheet/topic.dart';
|
||||
|
||||
/// Controls a [DraggableScrollableSheet].
|
||||
///
|
||||
@@ -730,9 +718,7 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
|
||||
/// [_DraggableScrollableSheetScrollController] as the primary controller for
|
||||
/// descendants.
|
||||
class _DraggableScrollableSheetScrollController extends ScrollController {
|
||||
_DraggableScrollableSheetScrollController({
|
||||
required this.extent,
|
||||
});
|
||||
_DraggableScrollableSheetScrollController({required this.extent});
|
||||
|
||||
_DraggableSheetExtent extent;
|
||||
VoidCallback? onPositionDetached;
|
||||
@@ -807,6 +793,7 @@ class _DraggableScrollableSheetScrollPosition
|
||||
required super.context,
|
||||
super.oldPosition,
|
||||
required this.getExtent,
|
||||
super.initialPixels,
|
||||
});
|
||||
|
||||
VoidCallback? _dragCancelCallback;
|
||||
@@ -817,8 +804,6 @@ class _DraggableScrollableSheetScrollPosition
|
||||
|
||||
_DraggableSheetExtent get extent => getExtent();
|
||||
|
||||
bool _isAtTop = true;
|
||||
|
||||
@override
|
||||
void absorb(ScrollPosition other) {
|
||||
super.absorb(other);
|
||||
@@ -846,9 +831,7 @@ class _DraggableScrollableSheetScrollPosition
|
||||
|
||||
@override
|
||||
void applyUserOffset(double delta) {
|
||||
if (!_isAtTop) {
|
||||
super.applyUserOffset(delta);
|
||||
} else if (!listShouldScroll &&
|
||||
if (!listShouldScroll &&
|
||||
(!(extent.isAtMin || extent.isAtMax) ||
|
||||
(extent.isAtMin && delta < 0) ||
|
||||
(extent.isAtMax && delta > 0))) {
|
||||
@@ -883,10 +866,6 @@ class _DraggableScrollableSheetScrollPosition
|
||||
|
||||
@override
|
||||
void goBallistic(double velocity) {
|
||||
if (!_isAtTop) {
|
||||
super.goBallistic(velocity);
|
||||
return;
|
||||
}
|
||||
if ((velocity == 0.0 && !_shouldSnap()) ||
|
||||
(velocity < 0.0 && listShouldScroll) ||
|
||||
(velocity > 0.0 && extent.isAtMax)) {
|
||||
@@ -964,71 +943,12 @@ class _DraggableScrollableSheetScrollPosition
|
||||
|
||||
@override
|
||||
Drag drag(DragStartDetails details, VoidCallback dragCancelCallback) {
|
||||
_isAtTop = pixels == 0;
|
||||
// Save this so we can call it later if we have to [goBallistic] on our own.
|
||||
_dragCancelCallback = dragCancelCallback;
|
||||
return super.drag(details, dragCancelCallback);
|
||||
}
|
||||
}
|
||||
|
||||
/// A widget that can notify a descendent [DraggableScrollableSheet] that it
|
||||
/// should reset its position to the initial state.
|
||||
///
|
||||
/// The [Scaffold] uses this widget to notify a persistent bottom sheet that
|
||||
/// the user has tapped back if the sheet has started to cover more of the body
|
||||
/// than when at its initial position. This is important for users of assistive
|
||||
/// technology, where dragging may be difficult to communicate.
|
||||
///
|
||||
/// This is just a wrapper on top of [DraggableScrollableController]. It is
|
||||
/// primarily useful for controlling a sheet in a part of the widget tree that
|
||||
/// the current code does not control (e.g. library code trying to affect a sheet
|
||||
/// in library users' code). Generally, it's easier to control the sheet
|
||||
/// directly by creating a controller and passing the controller to the sheet in
|
||||
/// its constructor (see [DraggableScrollableSheet.controller]).
|
||||
class DraggableScrollableActuator extends StatefulWidget {
|
||||
/// Creates a widget that can notify descendent [DraggableScrollableSheet]s
|
||||
/// to reset to their initial position.
|
||||
///
|
||||
/// The [child] parameter is required.
|
||||
const DraggableScrollableActuator({super.key, required this.child});
|
||||
|
||||
/// This child's [DraggableScrollableSheet] descendant will be reset when the
|
||||
/// [reset] method is applied to a context that includes it.
|
||||
final Widget child;
|
||||
|
||||
/// Notifies any descendant [DraggableScrollableSheet] that it should reset
|
||||
/// to its initial position.
|
||||
///
|
||||
/// Returns `true` if a [DraggableScrollableActuator] is available and
|
||||
/// some [DraggableScrollableSheet] is listening for updates, `false`
|
||||
/// otherwise.
|
||||
static bool reset(BuildContext context) {
|
||||
final _InheritedResetNotifier? notifier = context
|
||||
.dependOnInheritedWidgetOfExactType<_InheritedResetNotifier>();
|
||||
return notifier?._sendReset() ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
State<DraggableScrollableActuator> createState() =>
|
||||
_DraggableScrollableActuatorState();
|
||||
}
|
||||
|
||||
class _DraggableScrollableActuatorState
|
||||
extends State<DraggableScrollableActuator> {
|
||||
final _ResetNotifier _notifier = _ResetNotifier();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _InheritedResetNotifier(notifier: _notifier, child: widget.child);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_notifier.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// A [ChangeNotifier] to use with [_InheritedResetNotifier] to notify
|
||||
/// descendants that they should reset to initial state.
|
||||
class _ResetNotifier extends ChangeNotifier {
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user