mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-22 03:31:09 +08:00
@@ -14,6 +14,8 @@ abstract class CommonDynController extends ReplyController<MainListReply> {
|
||||
late final horizontalPreview = Pref.horizontalPreview;
|
||||
late final List<double> ratio = Pref.dynamicDetailRatio;
|
||||
|
||||
late final showDynActionBar = Pref.showDynActionBar;
|
||||
|
||||
@override
|
||||
Future<LoadingState<MainListReply>> customGetData() => ReplyGrpc.mainList(
|
||||
type: replyType,
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:PiliPlus/grpc/bilibili/main/community/reply/v1.pb.dart'
|
||||
show ReplyInfo;
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/pages/common/dyn/common_dyn_controller.dart';
|
||||
import 'package:PiliPlus/pages/common/fab_mixin.dart';
|
||||
import 'package:PiliPlus/pages/video/reply/widgets/reply_item_grpc.dart';
|
||||
import 'package:PiliPlus/pages/video/reply_reply/view.dart';
|
||||
import 'package:PiliPlus/utils/extension/num_ext.dart';
|
||||
@@ -22,7 +23,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
abstract class CommonDynPageState<T extends StatefulWidget> extends State<T>
|
||||
with SingleTickerProviderStateMixin {
|
||||
with SingleTickerProviderStateMixin, FabMixin {
|
||||
CommonDynController get controller;
|
||||
|
||||
late final ScrollController scrollController;
|
||||
@@ -36,26 +37,9 @@ abstract class CommonDynPageState<T extends StatefulWidget> extends State<T>
|
||||
late double maxWidth;
|
||||
late double maxHeight;
|
||||
|
||||
bool _showFab = true;
|
||||
|
||||
final fabOffset = const Offset(0, 1);
|
||||
|
||||
late final AnimationController _fabAnimationCtr;
|
||||
late final Animation<Offset> fabAnim;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_fabAnimationCtr = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
)..forward();
|
||||
fabAnim = _fabAnimationCtr.drive(
|
||||
Tween<Offset>(
|
||||
begin: fabOffset,
|
||||
end: Offset.zero,
|
||||
).chain(CurveTween(curve: Curves.easeInOut)),
|
||||
);
|
||||
scrollController = ScrollController()..addListener(listener);
|
||||
}
|
||||
|
||||
@@ -69,20 +53,6 @@ abstract class CommonDynPageState<T extends StatefulWidget> extends State<T>
|
||||
}
|
||||
}
|
||||
|
||||
void showFab() {
|
||||
if (!_showFab) {
|
||||
_showFab = true;
|
||||
_fabAnimationCtr.forward();
|
||||
}
|
||||
}
|
||||
|
||||
void hideFab() {
|
||||
if (_showFab) {
|
||||
_showFab = false;
|
||||
_fabAnimationCtr.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
@@ -98,7 +68,6 @@ abstract class CommonDynPageState<T extends StatefulWidget> extends State<T>
|
||||
scrollController
|
||||
..removeListener(listener)
|
||||
..dispose();
|
||||
_fabAnimationCtr.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -304,6 +273,16 @@ abstract class CommonDynPageState<T extends StatefulWidget> extends State<T>
|
||||
),
|
||||
);
|
||||
|
||||
FloatingActionButtonLocation get floatingActionButtonLocation =>
|
||||
controller.showDynActionBar
|
||||
? const ActionBarLocation()
|
||||
: const NoBottomPaddingFabLocation();
|
||||
|
||||
Widget get fabButton => Padding(
|
||||
padding: .only(bottom: padding.bottom + kFloatingActionButtonMargin),
|
||||
child: replyButton,
|
||||
);
|
||||
|
||||
Widget get replyButton => FloatingActionButton(
|
||||
heroTag: null,
|
||||
onPressed: () {
|
||||
|
||||
78
lib/pages/common/fab_mixin.dart
Normal file
78
lib/pages/common/fab_mixin.dart
Normal file
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
mixin FabMixin<T extends StatefulWidget> on State<T>, TickerProvider {
|
||||
bool _isFabVisible = true;
|
||||
late final AnimationController _fabAnimationCtr;
|
||||
late final Animation<Offset> fabAnimation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_fabAnimationCtr = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 100),
|
||||
);
|
||||
fabAnimation = _fabAnimationCtr.drive(
|
||||
Tween<Offset>(
|
||||
begin: Offset.zero,
|
||||
end: const Offset(0.0, 1.0),
|
||||
).chain(CurveTween(curve: Curves.easeInOut)),
|
||||
);
|
||||
}
|
||||
|
||||
void showFab() {
|
||||
if (!_isFabVisible) {
|
||||
_isFabVisible = true;
|
||||
_fabAnimationCtr.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
void hideFab() {
|
||||
if (_isFabVisible) {
|
||||
_isFabVisible = false;
|
||||
_fabAnimationCtr.forward();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_fabAnimationCtr.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
mixin _NoRightMarginMixin on StandardFabLocation {
|
||||
@override
|
||||
double getOffsetX(scaffoldGeometry, _) {
|
||||
return scaffoldGeometry.scaffoldSize.width -
|
||||
scaffoldGeometry.minInsets.right -
|
||||
scaffoldGeometry.floatingActionButtonSize.width;
|
||||
}
|
||||
}
|
||||
|
||||
mixin _NoBottomPaddingMixin on StandardFabLocation {
|
||||
@override
|
||||
double getOffsetY(scaffoldGeometry, _) {
|
||||
return scaffoldGeometry.contentBottom -
|
||||
scaffoldGeometry.floatingActionButtonSize.height;
|
||||
}
|
||||
}
|
||||
|
||||
class NoRightMarginFabLocation extends StandardFabLocation
|
||||
with FabFloatOffsetY, _NoRightMarginMixin {
|
||||
const NoRightMarginFabLocation();
|
||||
}
|
||||
|
||||
class NoBottomPaddingFabLocation extends StandardFabLocation
|
||||
with FabEndOffsetX, _NoBottomPaddingMixin {
|
||||
const NoBottomPaddingFabLocation();
|
||||
}
|
||||
|
||||
class ActionBarLocation extends StandardFabLocation with _NoBottomPaddingMixin {
|
||||
const ActionBarLocation();
|
||||
|
||||
@override
|
||||
double getOffsetX(scaffoldGeometry, _) {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user