Simplify app bar extent calculation

This commit is contained in:
Ming Ming 2022-04-09 18:43:50 +08:00
parent 0a3b91fe30
commit d2c84af8a8

View file

@ -35,7 +35,6 @@ import 'package:nc_photos/widget/handler/add_selection_to_album_handler.dart';
import 'package:nc_photos/widget/handler/archive_selection_handler.dart'; import 'package:nc_photos/widget/handler/archive_selection_handler.dart';
import 'package:nc_photos/widget/handler/remove_selection_handler.dart'; import 'package:nc_photos/widget/handler/remove_selection_handler.dart';
import 'package:nc_photos/widget/home_app_bar.dart'; import 'package:nc_photos/widget/home_app_bar.dart';
import 'package:nc_photos/widget/measure.dart';
import 'package:nc_photos/widget/page_visibility_mixin.dart'; import 'package:nc_photos/widget/page_visibility_mixin.dart';
import 'package:nc_photos/widget/photo_list_item.dart'; import 'package:nc_photos/widget/photo_list_item.dart';
import 'package:nc_photos/widget/photo_list_util.dart' as photo_list_util; import 'package:nc_photos/widget/photo_list_util.dart' as photo_list_util;
@ -107,7 +106,7 @@ class _HomePhotosState extends State<HomePhotos>
Widget _buildContent(BuildContext context, ScanAccountDirBlocState state) { Widget _buildContent(BuildContext context, ScanAccountDirBlocState state) {
return LayoutBuilder(builder: (context, constraints) { return LayoutBuilder(builder: (context, constraints) {
final scrollExtent = _getScrollViewExtent(constraints); final scrollExtent = _getScrollViewExtent(context, constraints);
return Stack( return Stack(
children: [ children: [
buildItemStreamListOuter( buildItemStreamListOuter(
@ -122,7 +121,7 @@ class _HomePhotosState extends State<HomePhotos>
controller: _scrollController, controller: _scrollController,
overrideMaxScrollExtent: scrollExtent, overrideMaxScrollExtent: scrollExtent,
// status bar + app bar // status bar + app bar
topOffset: MediaQuery.of(context).padding.top + kToolbarHeight, topOffset: _calcAppBarExtent(context),
child: ScrollConfiguration( child: ScrollConfiguration(
behavior: ScrollConfiguration.of(context) behavior: ScrollConfiguration.of(context)
.copyWith(scrollbars: false), .copyWith(scrollbars: false),
@ -222,11 +221,7 @@ class _HomePhotosState extends State<HomePhotos>
} }
Widget _buildNormalAppBar(BuildContext context) { Widget _buildNormalAppBar(BuildContext context) {
return SliverMeasureExtent( return HomeSliverAppBar(
onChange: (extent) {
_appBarExtent = extent;
},
child: HomeSliverAppBar(
account: widget.account, account: widget.account,
actions: [ actions: [
ZoomMenuButton( ZoomMenuButton(
@ -254,7 +249,6 @@ class _HomePhotosState extends State<HomePhotos>
break; break;
} }
}, },
),
); );
} }
@ -537,10 +531,10 @@ class _HomePhotosState extends State<HomePhotos>
} }
/// Return the estimated scroll extent of the custom scroll view, or null /// Return the estimated scroll extent of the custom scroll view, or null
double? _getScrollViewExtent(BoxConstraints constraints) { double? _getScrollViewExtent(
if (_itemListMaxExtent != null && BuildContext context, BoxConstraints constraints) {
constraints.hasBoundedHeight && if (_itemListMaxExtent != null && constraints.hasBoundedHeight) {
_appBarExtent != null) { final appBarExtent = _calcAppBarExtent(context);
final metadataTaskHeaderExtent = _web?.getHeaderHeight() ?? 0; final metadataTaskHeaderExtent = _web?.getHeaderHeight() ?? 0;
final smartAlbumListHeight = final smartAlbumListHeight =
AccountPref.of(widget.account).isEnableMemoryAlbumOr(true) && AccountPref.of(widget.account).isEnableMemoryAlbumOr(true) &&
@ -552,7 +546,7 @@ class _HomePhotosState extends State<HomePhotos>
// + smart album list height // + smart album list height
final scrollExtent = _itemListMaxExtent! - final scrollExtent = _itemListMaxExtent! -
constraints.maxHeight + constraints.maxHeight +
_appBarExtent! + appBarExtent +
metadataTaskHeaderExtent + metadataTaskHeaderExtent +
smartAlbumListHeight; smartAlbumListHeight;
_log.info( _log.info(
@ -563,6 +557,9 @@ class _HomePhotosState extends State<HomePhotos>
} }
} }
double _calcAppBarExtent(BuildContext context) =>
MediaQuery.of(context).padding.top + kToolbarHeight;
Primitive<bool> get _hasFiredMetadataTask { Primitive<bool> get _hasFiredMetadataTask {
final name = bloc_util.getInstNameForRootAwareAccount( final name = bloc_util.getInstNameForRootAwareAccount(
"HomePhotosState.hasFiredMetadataTask", widget.account); "HomePhotosState.hasFiredMetadataTask", widget.account);
@ -603,7 +600,6 @@ class _HomePhotosState extends State<HomePhotos>
final ScrollController _scrollController = ScrollController(); final ScrollController _scrollController = ScrollController();
double? _appBarExtent;
double? _itemListMaxExtent; double? _itemListMaxExtent;
late final _prefUpdatedListener = late final _prefUpdatedListener =