Skip to content
This repository has been archived by the owner on Jan 17, 2025. It is now read-only.

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 Jan 12, 2025
1 parent 130bf36 commit 2fad0d3
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ class InteractiveviewerGallery<T> extends StatefulWidget {
this.onPageChanged,
this.onDismissed,
this.setStatusBar,
this.onClose,
});

final VoidCallback? onClose;

final bool? setStatusBar;

/// The sources to show.
Expand Down Expand Up @@ -222,6 +225,15 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>
? '${widget.sources[index]}@${_quality}q.webp'.http2https
: widget.sources[index].http2https;

void onClose() {
if (widget.onClose != null) {
widget.onClose!();
} else {
Get.back();
widget.onDismissed?.call(_pageController!.page!.floor());
}
}

@override
Widget build(BuildContext context) {
return Stack(
Expand All @@ -235,10 +247,7 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>
onNoBoundaryHit: _onNoBoundaryHit,
maxScale: widget.maxScale,
minScale: widget.minScale,
onDismissed: () {
Get.back();
widget.onDismissed?.call(_pageController!.page!.floor());
},
onDismissed: onClose,
onReset: () {
if (!_enablePageView) {
setState(() {
Expand All @@ -255,7 +264,7 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: Get.back,
onTap: onClose,
onDoubleTapDown: (TapDownDetails details) {
_doubleTapLocalPosition = details.localPosition;
},
Expand Down Expand Up @@ -301,10 +310,7 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>
children: [
IconButton(
icon: const Icon(Icons.close, color: Colors.white),
onPressed: () {
Get.back();
widget.onDismissed?.call(_pageController!.page!.floor());
},
onPressed: onClose,
),
widget.sources.length > 1
? Text(
Expand Down Expand Up @@ -493,7 +499,7 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>
Get.back();
DownloadUtils.downloadImg(
context,
widget.sources as List<String>,
widget.sources,
);
},
dense: true,
Expand Down
28 changes: 17 additions & 11 deletions lib/pages/dynamics/detail/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:math';

import 'package:PiliPlus/common/widgets/custom_sliver_persistent_header_delegate.dart';
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart';
import 'package:PiliPlus/common/widgets/loading_widget.dart';
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
import 'package:PiliPlus/http/loading_state.dart';
Expand Down Expand Up @@ -61,17 +60,24 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>

get _getImageCallback => _horizontalPreview
? (imgList, index) {
_key.currentState?.showBottomSheet(
(context) {
return InteractiveviewerGallery(
sources: imgList,
initIndex: index,
setStatusBar: false,
);
final ctr = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 200),
)..forward();
Utils.onHorizontalPreview(
_key,
AnimationController(
vsync: this,
duration: Duration.zero,
),
ctr,
imgList,
index,
() async {
await ctr.reverse();
ctr.dispose();
Get.back();
},
enableDrag: false,
elevation: 0,
backgroundColor: Colors.transparent,
);
}
: null;
Expand Down
28 changes: 17 additions & 11 deletions lib/pages/html/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:math';

import 'package:PiliPlus/common/widgets/article_content.dart';
import 'package:PiliPlus/common/widgets/http_error.dart';
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart';
import 'package:PiliPlus/common/widgets/loading_widget.dart';
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/pages/video/detail/reply/widgets/reply_item.dart';
Expand Down Expand Up @@ -54,17 +53,24 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>

get _getImageCallback => _horizontalPreview
? (imgList, index) {
_key.currentState?.showBottomSheet(
(context) {
return InteractiveviewerGallery(
sources: imgList,
initIndex: index,
setStatusBar: false,
);
final ctr = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 200),
)..forward();
Utils.onHorizontalPreview(
_key,
AnimationController(
vsync: this,
duration: Duration.zero,
),
ctr,
imgList,
index,
() async {
await ctr.reverse();
ctr.dispose();
Get.back();
},
enableDrag: false,
elevation: 0,
backgroundColor: Colors.transparent,
);
}
: null;
Expand Down
31 changes: 19 additions & 12 deletions lib/pages/video/detail/reply_reply/view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart';
import 'package:PiliPlus/common/widgets/loading_widget.dart';
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
Expand Down Expand Up @@ -50,7 +49,8 @@ class VideoReplyReplyPanel extends StatefulWidget {
State<VideoReplyReplyPanel> createState() => _VideoReplyReplyPanelState();
}

class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel>
with SingleTickerProviderStateMixin {
late VideoReplyReplyController _videoReplyReplyController;
late final _savedReplies = {};
late final itemPositionsListener = ItemPositionsListener.create();
Expand Down Expand Up @@ -280,17 +280,24 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {

get _getImageCallback => _horizontalPreview
? (imgList, index) {
_key.currentState?.showBottomSheet(
(context) {
return InteractiveviewerGallery(
sources: imgList,
initIndex: index,
setStatusBar: false,
);
final ctr = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 200),
)..forward();
Utils.onHorizontalPreview(
_key,
AnimationController(
vsync: this,
duration: Duration.zero,
),
ctr,
imgList,
index,
() async {
await ctr.reverse();
ctr.dispose();
Get.back();
},
enableDrag: false,
elevation: 0,
backgroundColor: Colors.transparent,
);
}
: null;
Expand Down
28 changes: 17 additions & 11 deletions lib/pages/video/detail/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:math';

import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/common/widgets/icon_button.dart';
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart';
import 'package:PiliPlus/common/widgets/list_sheet.dart';
import 'package:PiliPlus/common/widgets/segment_progress_bar.dart';
import 'package:PiliPlus/http/loading_state.dart';
Expand Down Expand Up @@ -1610,17 +1609,24 @@ class _VideoDetailPageState extends State<VideoDetailPage>
onDismissed: videoDetailController.onDismissed,
callback: _horizontalPreview
? (imgList, index) {
videoDetailController.childKey.currentState?.showBottomSheet(
(context) {
return InteractiveviewerGallery(
sources: imgList,
initIndex: index,
setStatusBar: false,
);
final ctr = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 200),
)..forward();
Utils.onHorizontalPreview(
videoDetailController.childKey,
AnimationController(
vsync: this,
duration: Duration.zero,
),
ctr,
imgList,
index,
() async {
await ctr.reverse();
ctr.dispose();
Get.back();
},
enableDrag: false,
elevation: 0,
backgroundColor: Colors.transparent,
);
}
: null,
Expand Down
23 changes: 23 additions & 0 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'package:PiliPlus/build_config.dart';
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart';
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
import 'package:PiliPlus/http/api.dart';
import 'package:PiliPlus/http/constants.dart';
Expand Down Expand Up @@ -40,6 +41,28 @@ class Utils {

static const channel = MethodChannel("PiliPlus");

static void onHorizontalPreview(GlobalKey<ScaffoldState> key,
transitionAnimationController, ctr, imgList, index, onClose) {
key.currentState?.showBottomSheet(
(context) {
return FadeTransition(
opacity: Tween<double>(begin: 0, end: 1).animate(ctr),
child: InteractiveviewerGallery(
sources: imgList,
initIndex: index,
setStatusBar: false,
onClose: onClose,
),
);
},
enableDrag: false,
elevation: 0,
backgroundColor: Colors.transparent,
transitionAnimationController: transitionAnimationController,
sheetAnimationStyle: AnimationStyle(duration: Duration.zero),
);
}

static void handleWebview(String url, {bool off = false}) {
if (GStorage.openInBrowser) {
launchURL(url);
Expand Down

0 comments on commit 2fad0d3

Please sign in to comment.