fixed section layout for multiline headers with leading icon

This commit is contained in:
Thibault Deckers 2020-04-12 10:42:48 +09:00
parent 1478f1add3
commit a094ebeaf1
2 changed files with 23 additions and 9 deletions

View file

@ -29,13 +29,15 @@ class CollectionListSliver extends StatelessWidget {
@override
Widget build(BuildContext context) {
final sectionLayouts = <SectionLayout>[];
final sectionKeys = collection.sections.keys.toList();
final source = collection.source;
final sections = collection.sections;
final sectionKeys = sections.keys.toList();
var currentIndex = 0, currentOffset = 0.0;
sectionKeys.forEach((sectionKey) {
final sectionEntryCount = collection.sections[sectionKey].length;
final sectionEntryCount = sections[sectionKey].length;
final sectionChildCount = 1 + (sectionEntryCount / columnCount).ceil();
final headerExtent = showHeader ? SectionHeader.computeHeaderExtent(collection, sectionKey, scrollableWidth) : 0.0;
final headerExtent = showHeader ? SectionHeader.computeHeaderHeight(source, sectionKey, scrollableWidth) : 0.0;
final sectionFirstIndex = currentIndex;
currentIndex += sectionChildCount;
@ -59,13 +61,13 @@ class CollectionListSliver extends StatelessWidget {
if (listIndex == 0) {
return SectionHeader(
collection: collection,
sections: collection.sections,
sections: sections,
sectionKey: sectionKey,
);
}
listIndex--;
final section = collection.sections[sectionKey];
final section = sections[sectionKey];
final minEntryIndex = listIndex * columnCount;
final maxEntryIndex = min(sectionEntryCount, minEntryIndex + columnCount);
final children = <Widget>[];

View file

@ -1,7 +1,9 @@
import 'dart:math';
import 'package:aves/model/collection_lens.dart';
import 'package:aves/model/collection_source.dart';
import 'package:aves/model/image_entry.dart';
import 'package:aves/utils/android_file_utils.dart';
import 'package:aves/utils/constants.dart';
import 'package:aves/widgets/album/grid/header_album.dart';
import 'package:aves/widgets/album/grid/header_date.dart';
@ -64,17 +66,27 @@ class SectionHeader extends StatelessWidget {
}
// TODO TLAD cache header extent computation?
static double computeHeaderExtent(CollectionLens collection, dynamic sectionKey, double scrollableWidth) {
static double computeHeaderHeight(CollectionSource source, dynamic sectionKey, double scrollableWidth) {
var headerExtent = 0.0;
if (sectionKey is String) {
// only compute height for album headers, as they're the only likely ones to split on multiple lines
final text = collection.source.getUniqueAlbumName(sectionKey);
final hasIcon = androidFileUtils.getAlbumType(sectionKey) != AlbumType.Default;
final text = source.getUniqueAlbumName(sectionKey);
final maxWidth = scrollableWidth - TitleSectionHeader.padding.horizontal;
final para = RenderParagraph(
TextSpan(
children: [
if (hasIcon)
// `RenderParagraph` fails to lay out `WidgetSpan` offscreen as of Flutter v1.17.0
// so we use a hair space times a magic number to match leading width
// 23 hair spaces match a width of 40.0
TextSpan(text: '\u200A' * 23),
TextSpan(
text: text,
style: Constants.titleTextStyle,
),
],
),
textDirection: TextDirection.ltr,
)..layout(BoxConstraints(maxWidth: maxWidth), parentUsesSize: true);
headerExtent = para.getMaxIntrinsicHeight(maxWidth);