Skip to content

Commit

Permalink
opt: horizontal preview
Browse files Browse the repository at this point in the history
Signed-off-by: bggRGjQaUbCoE <[email protected]>
  • Loading branch information
bggRGjQaUbCoE committed Feb 22, 2025
1 parent f94cb2a commit 61ca7bc
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class InteractiveviewerGallery<T> extends StatefulWidget {
this.onClose,
});

final VoidCallback? onClose;
final ValueChanged? onClose;

final bool? setStatusBar;

Expand Down Expand Up @@ -152,6 +152,7 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>

@override
void dispose() async {
widget.onClose?.call(true);
_player?.dispose();
_pageController?.dispose();
_animationController.removeListener(() {});
Expand Down Expand Up @@ -259,7 +260,7 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>

void onClose() {
if (widget.onClose != null) {
widget.onClose!();
widget.onClose!(false);
} else {
Get.back();
widget.onDismissed?.call(_pageController!.page!.floor());
Expand Down
42 changes: 36 additions & 6 deletions lib/pages/dynamics/detail/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>

get _getImageCallback => _horizontalPreview
? (imgList, index) {
bool needReverse =
_fabAnimationCtr?.status.isForwardOrCompleted == true;
if (needReverse) {
_fabAnimationCtr?.reverse();
}
final ctr = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 200),
Expand All @@ -77,10 +82,20 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
ctr,
imgList,
index,
() async {
await ctr.reverse();
ctr.dispose();
Get.back();
(value) async {
if (needReverse) {
needReverse = false;
_fabAnimationCtr?.forward();
}
if (value == false) {
await ctr.reverse();
}
try {
ctr.dispose();
} catch (_) {}
if (value == false) {
Get.back();
}
},
);
}
Expand Down Expand Up @@ -155,7 +170,9 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
EasyThrottle.throttle('replyReply', const Duration(milliseconds: 500), () {
int oid = replyItem.oid.toInt();
int rpid = GlobalData().grpcReply ? replyItem.id.toInt() : replyItem.rpid;
Widget replyReplyPage([bool automaticallyImplyLeading = true]) =>
Widget replyReplyPage(
[bool automaticallyImplyLeading = true,
VoidCallback? onDispose]) =>
Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
Expand All @@ -171,19 +188,32 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
replyType: ReplyType.values[replyType],
firstFloor: replyItem,
isTop: isTop ?? false,
onDispose: onDispose,
),
);
if (this.context.orientation == Orientation.portrait) {
Get.to(replyReplyPage);
} else {
ScaffoldState? scaffoldState = Scaffold.maybeOf(context);
if (scaffoldState != null) {
bool needReverse =
_fabAnimationCtr?.status.isForwardOrCompleted == true;
if (needReverse) {
_fabAnimationCtr?.reverse();
}
scaffoldState.showBottomSheet(
backgroundColor: Colors.transparent,
(context) => MediaQuery.removePadding(
context: context,
removeLeft: true,
child: replyReplyPage(false),
child: replyReplyPage(
false,
() {
if (needReverse) {
_fabAnimationCtr?.forward();
}
},
),
),
);
} else {
Expand Down
42 changes: 36 additions & 6 deletions lib/pages/html/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>

get _getImageCallback => _horizontalPreview
? (imgList, index) {
bool needReverse =
fabAnimationCtr.status.isForwardOrCompleted == true;
if (needReverse) {
fabAnimationCtr.reverse();
}
final ctr = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 200),
Expand All @@ -70,10 +75,20 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
ctr,
imgList,
index,
() async {
await ctr.reverse();
ctr.dispose();
Get.back();
(value) async {
if (needReverse) {
needReverse = false;
fabAnimationCtr.forward();
}
if (value == false) {
await ctr.reverse();
}
try {
ctr.dispose();
} catch (_) {}
if (value == false) {
Get.back();
}
},
);
}
Expand Down Expand Up @@ -144,7 +159,9 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
EasyThrottle.throttle('replyReply', const Duration(milliseconds: 500), () {
int oid = replyItem.oid.toInt();
int rpid = GlobalData().grpcReply ? replyItem.id.toInt() : replyItem.rpid;
Widget replyReplyPage([bool automaticallyImplyLeading = true]) =>
Widget replyReplyPage(
[bool automaticallyImplyLeading = true,
VoidCallback? onDispose]) =>
Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
Expand All @@ -160,19 +177,32 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
replyType: ReplyType.values[type],
firstFloor: replyItem,
isTop: isTop ?? false,
onDispose: onDispose,
),
);
if (this.context.orientation == Orientation.portrait) {
Get.to(replyReplyPage);
} else {
ScaffoldState? scaffoldState = Scaffold.maybeOf(context);
if (scaffoldState != null) {
bool needReverse =
fabAnimationCtr.status.isForwardOrCompleted == true;
if (needReverse) {
fabAnimationCtr.reverse();
}
scaffoldState.showBottomSheet(
backgroundColor: Colors.transparent,
(context) => MediaQuery.removePadding(
context: context,
removeLeft: true,
child: replyReplyPage(false),
child: replyReplyPage(
false,
() {
if (needReverse) {
fabAnimationCtr.forward();
}
},
),
),
);
} else {
Expand Down
19 changes: 14 additions & 5 deletions lib/pages/video/detail/reply_reply/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class VideoReplyReplyPanel extends StatefulWidget {
this.isTop = false,
this.onViewImage,
this.onDismissed,
this.onDispose,
});
final int? id;
final int oid;
Expand All @@ -44,13 +45,14 @@ class VideoReplyReplyPanel extends StatefulWidget {
final bool isTop;
final VoidCallback? onViewImage;
final ValueChanged<int>? onDismissed;
final VoidCallback? onDispose;

@override
State<VideoReplyReplyPanel> createState() => _VideoReplyReplyPanelState();
}

class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel>
with SingleTickerProviderStateMixin {
with TickerProviderStateMixin {
late VideoReplyReplyController _videoReplyReplyController;
late final _savedReplies = {};
late final itemPositionsListener = ItemPositionsListener.create();
Expand Down Expand Up @@ -82,6 +84,7 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel>

@override
void dispose() {
widget.onDispose?.call();
_videoReplyReplyController.controller?.stop();
_videoReplyReplyController.controller?.dispose();
_videoReplyReplyController.controller = null;
Expand Down Expand Up @@ -305,10 +308,16 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel>
ctr,
imgList,
index,
() async {
await ctr.reverse();
ctr.dispose();
Get.back();
(value) async {
if (value == false) {
await ctr.reverse();
}
try {
ctr.dispose();
} catch (_) {}
if (value == false) {
Get.back();
}
},
);
}
Expand Down
14 changes: 10 additions & 4 deletions lib/pages/video/detail/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1736,10 +1736,16 @@ class _VideoDetailPageState extends State<VideoDetailPage>
ctr,
imgList,
index,
() async {
await ctr.reverse();
ctr.dispose();
Get.back();
(value) async {
if (value == false) {
await ctr.reverse();
}
try {
ctr.dispose();
} catch (_) {}
if (value == false) {
Get.back();
}
},
);
}
Expand Down

0 comments on commit 61ca7bc

Please sign in to comment.