split FullscreenBody
This commit is contained in:
parent
bfe2b4d319
commit
1b6759384e
1 changed files with 103 additions and 67 deletions
|
@ -58,7 +58,6 @@ class FullscreenBody extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProviderStateMixin {
|
class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProviderStateMixin {
|
||||||
bool _isInitialScale = true;
|
|
||||||
int _currentHorizontalPage, _currentVerticalPage = imagePage;
|
int _currentHorizontalPage, _currentVerticalPage = imagePage;
|
||||||
PageController _horizontalPager, _verticalPager;
|
PageController _horizontalPager, _verticalPager;
|
||||||
final ValueNotifier<bool> _overlayVisible = ValueNotifier(true);
|
final ValueNotifier<bool> _overlayVisible = ValueNotifier(true);
|
||||||
|
@ -122,6 +121,8 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final entry = _currentHorizontalPage != null && _currentHorizontalPage < entries.length ? entries[_currentHorizontalPage] : null;
|
final entry = _currentHorizontalPage != null && _currentHorizontalPage < entries.length ? entries[_currentHorizontalPage] : null;
|
||||||
|
final showOverlay = entry != null && _currentVerticalPage == imagePage;
|
||||||
|
final videoController = showOverlay && entry.isVideo ? _videoControllers.firstWhere((kv) => kv.item1 == entry.path, orElse: () => null)?.item2 : null;
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
onWillPop: () {
|
onWillPop: () {
|
||||||
if (_currentVerticalPage == infoPage) {
|
if (_currentVerticalPage == infoPage) {
|
||||||
|
@ -133,44 +134,18 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
|
||||||
},
|
},
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
PageView(
|
FullscreenVerticalPageView(
|
||||||
scrollDirection: Axis.vertical,
|
|
||||||
controller: _verticalPager,
|
|
||||||
physics: _isInitialScale ? const PageScrollPhysics() : const NeverScrollableScrollPhysics(),
|
|
||||||
onPageChanged: _onVerticalPageChanged,
|
|
||||||
children: [
|
|
||||||
const SizedBox(),
|
|
||||||
Container(
|
|
||||||
color: Colors.black,
|
|
||||||
child: ImagePage(
|
|
||||||
collection: collection,
|
collection: collection,
|
||||||
pageController: _horizontalPager,
|
entry: entry,
|
||||||
onTap: () => _overlayVisible.value = !_overlayVisible.value,
|
|
||||||
onPageChanged: _onHorizontalPageChanged,
|
|
||||||
onScaleChanged: (state) => setState(() => _isInitialScale = state == PhotoViewScaleState.initial),
|
|
||||||
videoControllers: _videoControllers,
|
videoControllers: _videoControllers,
|
||||||
|
verticalPager: _verticalPager,
|
||||||
|
horizontalPager: _horizontalPager,
|
||||||
|
onVerticalPageChanged: _onVerticalPageChanged,
|
||||||
|
onHorizontalPageChanged: _onHorizontalPageChanged,
|
||||||
|
onImageTap: () => _overlayVisible.value = !_overlayVisible.value,
|
||||||
|
onImagePageRequested: () => _goToVerticalPage(imagePage),
|
||||||
),
|
),
|
||||||
),
|
if (showOverlay) FullscreenTopOverlay(
|
||||||
NotificationListener(
|
|
||||||
onNotification: (notification) {
|
|
||||||
if (notification is BackUpNotification) _goToVerticalPage(imagePage);
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
child: InfoPage(collection: collection, entry: entry),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
..._buildOverlay(entry)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Widget> _buildOverlay(ImageEntry entry) {
|
|
||||||
if (entry == null || _currentVerticalPage != imagePage) return [];
|
|
||||||
final videoController = entry.isVideo ? _videoControllers.firstWhere((kv) => kv.item1 == entry.path, orElse: () => null)?.item2 : null;
|
|
||||||
return [
|
|
||||||
FullscreenTopOverlay(
|
|
||||||
entries: entries,
|
entries: entries,
|
||||||
index: _currentHorizontalPage,
|
index: _currentHorizontalPage,
|
||||||
scale: _topOverlayScale,
|
scale: _topOverlayScale,
|
||||||
|
@ -178,7 +153,7 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
|
||||||
viewPadding: _frozenViewPadding,
|
viewPadding: _frozenViewPadding,
|
||||||
onActionSelected: (action) => _actionDelegate.onActionSelected(context, entry, action),
|
onActionSelected: (action) => _actionDelegate.onActionSelected(context, entry, action),
|
||||||
),
|
),
|
||||||
Positioned(
|
if (showOverlay) Positioned(
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
|
@ -201,8 +176,10 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
];
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _goToVerticalPage(int page) {
|
Future<void> _goToVerticalPage(int page) {
|
||||||
|
@ -271,3 +248,62 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FullscreenVerticalPageView extends StatefulWidget {
|
||||||
|
final ImageCollection collection;
|
||||||
|
final ImageEntry entry;
|
||||||
|
final List<Tuple2<String, VideoPlayerController>> videoControllers;
|
||||||
|
final PageController horizontalPager, verticalPager;
|
||||||
|
final void Function(int page) onVerticalPageChanged, onHorizontalPageChanged;
|
||||||
|
final VoidCallback onImageTap, onImagePageRequested;
|
||||||
|
|
||||||
|
const FullscreenVerticalPageView({
|
||||||
|
@required this.collection,
|
||||||
|
@required this.entry,
|
||||||
|
@required this.videoControllers,
|
||||||
|
@required this.verticalPager,
|
||||||
|
@required this.horizontalPager,
|
||||||
|
@required this.onVerticalPageChanged,
|
||||||
|
@required this.onHorizontalPageChanged,
|
||||||
|
@required this.onImageTap,
|
||||||
|
@required this.onImagePageRequested,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_FullscreenVerticalPageViewState createState() => _FullscreenVerticalPageViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FullscreenVerticalPageViewState extends State<FullscreenVerticalPageView> {
|
||||||
|
bool _isInitialScale = true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return PageView(
|
||||||
|
scrollDirection: Axis.vertical,
|
||||||
|
controller: widget.verticalPager,
|
||||||
|
physics: _isInitialScale ? const PageScrollPhysics() : const NeverScrollableScrollPhysics(),
|
||||||
|
onPageChanged: widget.onVerticalPageChanged,
|
||||||
|
children: [
|
||||||
|
const SizedBox(),
|
||||||
|
Container(
|
||||||
|
color: Colors.black,
|
||||||
|
child: ImagePage(
|
||||||
|
collection: widget.collection,
|
||||||
|
pageController: widget.horizontalPager,
|
||||||
|
onTap: widget.onImageTap,
|
||||||
|
onPageChanged: widget.onHorizontalPageChanged,
|
||||||
|
onScaleChanged: (state) => setState(() => _isInitialScale = state == PhotoViewScaleState.initial),
|
||||||
|
videoControllers: widget.videoControllers,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
NotificationListener(
|
||||||
|
onNotification: (notification) {
|
||||||
|
if (notification is BackUpNotification) widget.onImagePageRequested();
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
child: InfoPage(collection: widget.collection, entry: widget.entry),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue