Moved RecyclableViewWidget and NonRecyclableViewWidget to separate files
This commit is contained in:
parent
ca1ef1798c
commit
793ee17955
4 changed files with 139 additions and 126 deletions
|
@ -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<File> files;
|
||||
|
@ -358,126 +357,3 @@ class GalleryGridViewWidget extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RecyclableViewWidget extends StatefulWidget {
|
||||
final bool shouldRender;
|
||||
final List<File> 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<RecyclableViewWidget> createState() => _RecyclableViewWidgetState();
|
||||
}
|
||||
|
||||
class _RecyclableViewWidgetState extends State<RecyclableViewWidget> {
|
||||
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<File> 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<NonRecyclableViewWidget> createState() =>
|
||||
_NonRecyclableViewWidgetState();
|
||||
}
|
||||
|
||||
class _NonRecyclableViewWidgetState extends State<NonRecyclableViewWidget> {
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<File> 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<NonRecyclableViewWidget> createState() =>
|
||||
_NonRecyclableViewWidgetState();
|
||||
}
|
||||
|
||||
class _NonRecyclableViewWidgetState extends State<NonRecyclableViewWidget> {
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
67
lib/ui/viewer/gallery/component/recyclable_view_widget.dart
Normal file
67
lib/ui/viewer/gallery/component/recyclable_view_widget.dart
Normal file
|
@ -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<File> 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<RecyclableViewWidget> createState() => _RecyclableViewWidgetState();
|
||||
}
|
||||
|
||||
class _RecyclableViewWidgetState extends State<RecyclableViewWidget> {
|
||||
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),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue