π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Create a widget (yet to be stateful) that acts as a 'pinned header' for each group in gallery when gallery is scrolled
ashilkn372c4d9086bc
diff --git a/mobile/lib/ui/viewer/gallery/component/group/group_header_widget.dart b/mobile/lib/ui/viewer/gallery/component/group/group_header_widget.dartindex 490bf81a4d..6785494eeb 100644--- a/mobile/lib/ui/viewer/gallery/component/group/group_header_widget.dart+++ b/mobile/lib/ui/viewer/gallery/component/group/group_header_widget.dart@@ -1,4 +1,4 @@-import "package:flutter/cupertino.dart";+import "package:flutter/widgets.dart";import 'package:photos/core/constants.dart';import "package:photos/generated/l10n.dart";import "package:photos/theme/ente_theme.dart";@@ -6,11 +6,13 @@ import "package:photos/theme/ente_theme.dart";class GroupHeaderWidget extends StatelessWidget {final String title;final int gridSize;+ final double? height;const GroupHeaderWidget({super.key,required this.title,required this.gridSize,+ this.height,});@override@@ -22,21 +24,24 @@ class GroupHeaderWidget extends StatelessWidget {final double horizontalPadding = gridSize < photoGridSizeMax ? 12.0 : 8.0;final double verticalPadding = gridSize < photoGridSizeMax ? 12.0 : 14.0;- return Padding(- padding: EdgeInsets.symmetric(- horizontal: horizontalPadding,- vertical: verticalPadding,- ),- child: Container(- alignment: Alignment.centerLeft,- child: Text(- title,- style: (title == S.of(context).dayToday)- ? textStyle- : textStyle.copyWith(color: colorScheme.textMuted),- maxLines: 1,- // TODO: Make it possible to see the full title if overflowing- overflow: TextOverflow.ellipsis,+ return SizedBox(+ height: height,+ child: Padding(+ padding: EdgeInsets.symmetric(+ horizontal: horizontalPadding,+ vertical: verticalPadding,+ ),+ child: Container(+ alignment: Alignment.centerLeft,+ child: Text(+ title,+ style: (title == S.of(context).dayToday)+ ? textStyle+ : textStyle.copyWith(color: colorScheme.textMuted),+ maxLines: 1,+ // TODO: Make it possible to see the full title if overflowing+ overflow: TextOverflow.ellipsis,+ ),),),);diff --git a/mobile/lib/ui/viewer/gallery/custom_scroll_bar.dart b/mobile/lib/ui/viewer/gallery/custom_scroll_bar.dartindex 391235c696..08f3eff169 100644--- a/mobile/lib/ui/viewer/gallery/custom_scroll_bar.dart+++ b/mobile/lib/ui/viewer/gallery/custom_scroll_bar.dart@@ -18,6 +18,7 @@ import 'package:flutter/material.dart';import "package:logging/logging.dart";import "package:photos/models/gallery/gallery_sections.dart";import "package:photos/ui/viewer/gallery/component/group/type.dart";+import "package:photos/utils/misc_util.dart";class PositionConstraints {final double top;@@ -191,38 +192,12 @@ class CustomScrollBarState extends State<CustomScrollBar> {final renderBox = _key.currentContext?.findRenderObject() as RenderBox?;assert(renderBox != null, "RenderBox is null");// Retry for : https://github.com/flutter/flutter/issues/25827- return _getNonZeroDoubleWithRetry(+ return MiscUtil().getNonZeroDoubleWithRetry(() => renderBox!.size.height,id: "getHeightOfVisualTrack",);}- Future<double> _getNonZeroDoubleWithRetry(- double Function() getValue, {- Duration retryInterval = const Duration(milliseconds: 8),- String? id,- }) async {- final value = getValue();- if (value != 0) {- return value;- } else {- return await Future.delayed(retryInterval, () {- if (id != null) {- _logger.info(- "Retrying to get non-zero double value for $id after ${retryInterval.inMilliseconds} ms",- );- print(- "Retrying to get non-zero double value for $id after ${retryInterval.inMilliseconds} ms",- );- }- return _getNonZeroDoubleWithRetry(- getValue,- retryInterval: retryInterval,- );- });- }- }-bool _isSortedAscending(List<double> list) {if (list.length <= 1) {return true;diff --git a/mobile/lib/ui/viewer/gallery/gallery.dart b/mobile/lib/ui/viewer/gallery/gallery.dartindex bdb1916e66..8a5d44e265 100644--- a/mobile/lib/ui/viewer/gallery/gallery.dart+++ b/mobile/lib/ui/viewer/gallery/gallery.dart@@ -13,6 +13,7 @@ import 'package:photos/models/file_load_result.dart';import "package:photos/models/gallery/gallery_sections.dart";import 'package:photos/models/selected_files.dart';import "package:photos/service_locator.dart";+import "package:photos/theme/ente_theme.dart";import 'package:photos/ui/common/loading_widget.dart';import "package:photos/ui/viewer/gallery/component/group/group_header_widget.dart";import "package:photos/ui/viewer/gallery/component/group/type.dart";@@ -23,6 +24,7 @@ import "package:photos/ui/viewer/gallery/state/gallery_context_state.dart";import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";import "package:photos/ui/viewer/gallery/state/inherited_search_filter_data.dart";import "package:photos/utils/hierarchical_search_util.dart";+import "package:photos/utils/misc_util.dart";import "package:photos/utils/standalone/date_time.dart";import "package:photos/utils/standalone/debouncer.dart";import "package:photos/utils/widget_util.dart";@@ -81,11 +83,9 @@ class Gallery extends StatefulWidget {this.forceReloadEvents,this.removalEventTypes = const {},this.header,- // this.footer = const SizedBox(height: 212),- this.footer = const SizedBox.shrink(),+ this.footer = const SizedBox(height: 212),this.emptyState = const EmptyState(),- // this.scrollBottomSafeArea = 120.0,- this.scrollBottomSafeArea = 0.0,+ this.scrollBottomSafeArea = 120.0,this.albumName = '',this.groupType = GroupType.day,this.enableFileGrouping = true,@@ -123,6 +123,21 @@ class GalleryState extends State<Gallery> {bool _sortOrderAsc = false;List<EnteFile> _allGalleryFiles = [];final _scrollController = ScrollController();+ final _sectionedListSliverKey = GlobalKey();+ final _stackKey = GlobalKey();+ double? _stackRenderBoxYOffset;+ double? _sectionedListSliverRenderBoxYOffset;+ double? get _sectionedListSliverRenderBoxYOffsetRelativeToStackRenderBox {+ if (_sectionedListSliverRenderBoxYOffset != null &&+ _stackRenderBoxYOffset != null) {+ return _sectionedListSliverRenderBoxYOffset! - _stackRenderBoxYOffset!;+ }+ return null;+ }++ final miscUtil = MiscUtil();++ final _showPinnedHeader = ValueNotifier<bool>(false);@overridevoid initState() {@@ -220,6 +235,51 @@ class GalleryState extends State<Gallery> {groupHeaderExtent = size.height;});});++ WidgetsBinding.instance.addPostFrameCallback((_) async {+ try {+ final sectionedListSliverRenderBox = await miscUtil+ .getNonNullValueWithRetry(+ () => _sectionedListSliverKey.currentContext?.findRenderObject(),+ retryInterval: const Duration(milliseconds: 750),+ id: "sectionedListSliverRenderBox",+ )+ .then((value) => value as RenderBox);+ final stackRenderBox = await miscUtil+ .getNonNullValueWithRetry(+ () => _stackKey.currentContext?.findRenderObject(),+ retryInterval: const Duration(milliseconds: 750),+ id: "stackRenderBox",+ )+ .then((value) => value as RenderBox);++ _sectionedListSliverRenderBoxYOffset =+ sectionedListSliverRenderBox.localToGlobal(Offset.zero).dy;+ _stackRenderBoxYOffset = stackRenderBox.localToGlobal(Offset.zero).dy;+ } catch (e, s) {+ _logger.warning("Error getting renderBox offset", e, s);+ }+ setState(() {});+ });++ _scrollController.addListener(_scrollControllerListener);+ }++ void _scrollControllerListener() {+ if (_sectionedListSliverRenderBoxYOffsetRelativeToStackRenderBox == null) {+ return;+ }++ if (_scrollController.offset >=+ _sectionedListSliverRenderBoxYOffsetRelativeToStackRenderBox!) {+ if (!_showPinnedHeader.value) {+ _showPinnedHeader.value = true;+ }+ } else {+ if (_showPinnedHeader.value) {+ _showPinnedHeader.value = false;+ }+ }}void _setFilesAndReload(List<EnteFile> files) {@@ -395,6 +455,7 @@ class GalleryState extends State<Gallery> {if (groupHeaderExtent == null) return const SliverFillRemaining();_logger.info("Building Gallery ${widget.tagPrefix}");+ final colorScheme = getEnteColorScheme(context);final galleryGroups = GalleryGroups(allFiles: _allGalleryFiles,@@ -438,16 +499,44 @@ class GalleryState extends State<Gallery> {child: CustomScrollBar(scrollController: _scrollController,galleryGroups: galleryGroups,- child: CustomScrollView(- // physics: const BouncingScrollPhysics(),- controller: _scrollController,- slivers: [- SliverToBoxAdapter(child: widget.header ?? const SizedBox.shrink()),- SectionedListSliver(- sectionLayouts: galleryGroups.groupLayouts,+ child: Stack(+ key: _stackKey,+ clipBehavior: Clip.none,+ children: [+ CustomScrollView(+ // physics: const BouncingScrollPhysics(),+ controller: _scrollController,+ slivers: [+ SliverToBoxAdapter(+ child: widget.header ?? const SizedBox.shrink(),+ ),+ SliverToBoxAdapter(+ child: SizedBox.shrink(+ key: _sectionedListSliverKey,+ ),+ ),+ SectionedListSliver(+ sectionLayouts: galleryGroups.groupLayouts,+ ),+ SliverToBoxAdapter(+ child: widget.footer,+ ),+ ],),- SliverToBoxAdapter(- child: widget.footer,+ ValueListenableBuilder(+ valueListenable: _showPinnedHeader,+ builder: (context, value, _) {+ return value+ ? Container(+ color: colorScheme.backgroundBase,+ child: GroupHeaderWidget(+ title: "Temp title",+ gridSize: localSettings.getPhotoGridSize(),+ height: groupHeaderExtent,+ ),+ )+ : const SizedBox.shrink();+ },),],),diff --git a/mobile/lib/utils/misc_util.dart b/mobile/lib/utils/misc_util.dartnew file mode 100644index 0000000000..fa4705919f--- /dev/null+++ b/mobile/lib/utils/misc_util.dart@@ -0,0 +1,50 @@+import "package:logging/logging.dart";++class MiscUtil {+ final logger = Logger("MiscUtil");+ Future<double> getNonZeroDoubleWithRetry(+ double Function() getValue, {+ Duration retryInterval = const Duration(milliseconds: 8),+ String? id,+ }) async {+ final value = getValue();+ if (value != 0) {+ return value;+ } else {+ return await Future.delayed(retryInterval, () {+ if (id != null) {+ logger.info(+ "Retrying to get non-zero double value for $id after ${retryInterval.inMilliseconds} ms",+ );+ }+ return getNonZeroDoubleWithRetry(+ getValue,+ retryInterval: retryInterval,+ );+ });+ }+ }++ Future<dynamic> getNonNullValueWithRetry(+ dynamic Function() getValue, {+ Duration retryInterval = const Duration(milliseconds: 8),+ String? id,+ }) async {+ final value = getValue();+ if (value != null) {+ return value;+ } else {+ return await Future.delayed(retryInterval, () {+ if (id != null) {+ logger.info(+ "Retrying to get non-zero double value for $id after ${retryInterval.inMilliseconds} ms",+ );+ }+ return getNonNullValueWithRetry(+ getValue,+ retryInterval: retryInterval,+ );+ });+ }+ }+}