diff --git a/lib/ui/viewer/gallery/component/lazy_loading_gallery.dart b/lib/ui/viewer/gallery/component/lazy_loading_gallery.dart index b5a977f88..ecd46e4f0 100644 --- a/lib/ui/viewer/gallery/component/lazy_loading_gallery.dart +++ b/lib/ui/viewer/gallery/component/lazy_loading_gallery.dart @@ -14,7 +14,6 @@ import "package:photos/ui/viewer/gallery/component/day_widget.dart"; import "package:photos/ui/viewer/gallery/component/gallery_file_widget.dart"; import 'package:photos/ui/viewer/gallery/component/lazy_loading_grid_view.dart'; import 'package:photos/ui/viewer/gallery/gallery.dart'; -import 'package:visibility_detector/visibility_detector.dart'; class LazyLoadingGallery extends StatefulWidget { final List files; @@ -358,126 +357,3 @@ class GalleryGridViewWidget extends StatelessWidget { ); } } - -class RecyclableViewWidget extends StatefulWidget { - final bool shouldRender; - final List filesInDay; - final int photoGridSize; - final bool limitSelectionToOne; - final String tag; - final GalleryLoader asyncLoader; - final int? currentUserID; - final SelectedFiles? selectedFiles; - const RecyclableViewWidget({ - required this.shouldRender, - required this.filesInDay, - required this.photoGridSize, - required this.limitSelectionToOne, - required this.tag, - required this.asyncLoader, - this.currentUserID, - this.selectedFiles, - super.key, - }); - - @override - State createState() => _RecyclableViewWidgetState(); -} - -class _RecyclableViewWidgetState extends State { - late bool _shouldRender; - @override - void initState() { - _shouldRender = widget.shouldRender; - super.initState(); - } - - @override - Widget build(BuildContext context) { - return VisibilityDetector( - key: Key("gallery" + widget.filesInDay.first.tag), - onVisibilityChanged: (visibility) { - final shouldRender = visibility.visibleFraction > 0; - if (mounted && shouldRender != _shouldRender) { - setState(() { - _shouldRender = shouldRender; - }); - } - }, - child: _shouldRender - ? GalleryGridViewWidget( - filesInDay: widget.filesInDay, - photoGridSize: widget.photoGridSize, - limitSelectionToOne: widget.limitSelectionToOne, - tag: widget.tag, - asyncLoader: widget.asyncLoader, - selectedFiles: widget.selectedFiles, - currentUserID: widget.currentUserID, - ) - : PlaceHolderWidget(widget.filesInDay.length, widget.photoGridSize), - ); - } -} - -class NonRecyclableViewWidget extends StatefulWidget { - final bool shouldRender; - final List filesInDay; - final int photoGridSize; - final bool limitSelectionToOne; - final String tag; - final GalleryLoader asyncLoader; - final int? currentUserID; - final SelectedFiles? selectedFiles; - const NonRecyclableViewWidget({ - required this.shouldRender, - required this.filesInDay, - required this.photoGridSize, - required this.limitSelectionToOne, - required this.tag, - required this.asyncLoader, - this.currentUserID, - this.selectedFiles, - super.key, - }); - - @override - State createState() => - _NonRecyclableViewWidgetState(); -} - -class _NonRecyclableViewWidgetState extends State { - late bool _shouldRender; - @override - void initState() { - _shouldRender = widget.shouldRender; - super.initState(); - } - - @override - Widget build(BuildContext context) { - if (!_shouldRender!) { - return VisibilityDetector( - key: Key("gallery" + widget.filesInDay.first.tag), - onVisibilityChanged: (visibility) { - if (mounted && visibility.visibleFraction > 0 && !_shouldRender) { - setState(() { - _shouldRender = true; - }); - } - }, - child: - PlaceHolderWidget(widget.filesInDay.length, widget.photoGridSize), - ); - } else { - return GalleryGridViewWidget( - filesInDay: widget.filesInDay, - photoGridSize: widget.photoGridSize, - limitSelectionToOne: widget.limitSelectionToOne, - tag: widget.tag, - asyncLoader: widget.asyncLoader, - selectedFiles: widget.selectedFiles, - currentUserID: widget.currentUserID, - ); - } - } -} diff --git a/lib/ui/viewer/gallery/component/lazy_loading_grid_view.dart b/lib/ui/viewer/gallery/component/lazy_loading_grid_view.dart index aab295b1b..02d68dd65 100644 --- a/lib/ui/viewer/gallery/component/lazy_loading_grid_view.dart +++ b/lib/ui/viewer/gallery/component/lazy_loading_grid_view.dart @@ -1,4 +1,3 @@ - import "dart:async"; import "package:flutter/foundation.dart"; @@ -8,7 +7,8 @@ import "package:photos/core/event_bus.dart"; import "package:photos/events/clear_selections_event.dart"; import "package:photos/models/file.dart"; import "package:photos/models/selected_files.dart"; -import "package:photos/ui/viewer/gallery/component/lazy_loading_gallery.dart"; +import "package:photos/ui/viewer/gallery/component/non_recyclable_view_widget.dart"; +import "package:photos/ui/viewer/gallery/component/recyclable_view_widget.dart"; import "package:photos/ui/viewer/gallery/gallery.dart"; class LazyLoadingGridView extends StatefulWidget { diff --git a/lib/ui/viewer/gallery/component/non_recyclable_view_widget.dart b/lib/ui/viewer/gallery/component/non_recyclable_view_widget.dart new file mode 100644 index 000000000..7b97fa71a --- /dev/null +++ b/lib/ui/viewer/gallery/component/non_recyclable_view_widget.dart @@ -0,0 +1,70 @@ +import "package:flutter/material.dart"; +import "package:photos/models/file.dart"; +import "package:photos/models/selected_files.dart"; +import "package:photos/ui/huge_listview/place_holder_widget.dart"; +import "package:photos/ui/viewer/gallery/component/lazy_loading_gallery.dart"; +import "package:photos/ui/viewer/gallery/gallery.dart"; +import "package:visibility_detector/visibility_detector.dart"; + +class NonRecyclableViewWidget extends StatefulWidget { + final bool shouldRender; + final List filesInDay; + final int photoGridSize; + final bool limitSelectionToOne; + final String tag; + final GalleryLoader asyncLoader; + final int? currentUserID; + final SelectedFiles? selectedFiles; + const NonRecyclableViewWidget({ + required this.shouldRender, + required this.filesInDay, + required this.photoGridSize, + required this.limitSelectionToOne, + required this.tag, + required this.asyncLoader, + this.currentUserID, + this.selectedFiles, + super.key, + }); + + @override + State createState() => + _NonRecyclableViewWidgetState(); +} + +class _NonRecyclableViewWidgetState extends State { + late bool _shouldRender; + @override + void initState() { + _shouldRender = widget.shouldRender; + super.initState(); + } + + @override + Widget build(BuildContext context) { + if (!_shouldRender!) { + return VisibilityDetector( + key: Key("gallery" + widget.filesInDay.first.tag), + onVisibilityChanged: (visibility) { + if (mounted && visibility.visibleFraction > 0 && !_shouldRender) { + setState(() { + _shouldRender = true; + }); + } + }, + child: + PlaceHolderWidget(widget.filesInDay.length, widget.photoGridSize), + ); + } else { + return GalleryGridViewWidget( + filesInDay: widget.filesInDay, + photoGridSize: widget.photoGridSize, + limitSelectionToOne: widget.limitSelectionToOne, + tag: widget.tag, + asyncLoader: widget.asyncLoader, + selectedFiles: widget.selectedFiles, + currentUserID: widget.currentUserID, + ); + } + } +} diff --git a/lib/ui/viewer/gallery/component/recyclable_view_widget.dart b/lib/ui/viewer/gallery/component/recyclable_view_widget.dart new file mode 100644 index 000000000..e21c6fc8d --- /dev/null +++ b/lib/ui/viewer/gallery/component/recyclable_view_widget.dart @@ -0,0 +1,67 @@ +import "package:flutter/material.dart"; +import "package:photos/models/file.dart"; +import "package:photos/models/selected_files.dart"; +import "package:photos/ui/huge_listview/place_holder_widget.dart"; +import "package:photos/ui/viewer/gallery/component/lazy_loading_gallery.dart"; +import "package:photos/ui/viewer/gallery/gallery.dart"; +import "package:visibility_detector/visibility_detector.dart"; + +class RecyclableViewWidget extends StatefulWidget { + final bool shouldRender; + final List filesInDay; + final int photoGridSize; + final bool limitSelectionToOne; + final String tag; + final GalleryLoader asyncLoader; + final int? currentUserID; + final SelectedFiles? selectedFiles; + const RecyclableViewWidget({ + required this.shouldRender, + required this.filesInDay, + required this.photoGridSize, + required this.limitSelectionToOne, + required this.tag, + required this.asyncLoader, + this.currentUserID, + this.selectedFiles, + super.key, + }); + + @override + State createState() => _RecyclableViewWidgetState(); +} + +class _RecyclableViewWidgetState extends State { + late bool _shouldRender; + @override + void initState() { + _shouldRender = widget.shouldRender; + super.initState(); + } + + @override + Widget build(BuildContext context) { + return VisibilityDetector( + key: Key("gallery" + widget.filesInDay.first.tag), + onVisibilityChanged: (visibility) { + final shouldRender = visibility.visibleFraction > 0; + if (mounted && shouldRender != _shouldRender) { + setState(() { + _shouldRender = shouldRender; + }); + } + }, + child: _shouldRender + ? GalleryGridViewWidget( + filesInDay: widget.filesInDay, + photoGridSize: widget.photoGridSize, + limitSelectionToOne: widget.limitSelectionToOne, + tag: widget.tag, + asyncLoader: widget.asyncLoader, + selectedFiles: widget.selectedFiles, + currentUserID: widget.currentUserID, + ) + : PlaceHolderWidget(widget.filesInDay.length, widget.photoGridSize), + ); + } +}