mosaic animation fix

This commit is contained in:
Thibault Deckers 2022-10-01 15:52:45 +02:00
parent e9865aab96
commit ebd6f1c84c
2 changed files with 8 additions and 7 deletions

View file

@ -35,9 +35,9 @@ class MosaicSectionLayoutBuilder<T> extends SectionLayoutBuilder<T> {
required super.tileWidth, required super.tileWidth,
required super.tileHeight, required super.tileHeight,
required super.tileBuilder, required super.tileBuilder,
required super.tileAnimationDelay, required Duration tileAnimationDelay,
required this.coverRatioResolver, required this.coverRatioResolver,
}) { }) : super(tileAnimationDelay: Duration(milliseconds: (tileAnimationDelay.inMilliseconds / columnCount).ceil())) {
final rowWidth = scrollableWidth - horizontalPadding * 2; final rowWidth = scrollableWidth - horizontalPadding * 2;
rowAvailableWidth = (itemCount) => rowWidth - (itemCount - 1) * spacing; rowAvailableWidth = (itemCount) => rowWidth - (itemCount - 1) * spacing;
rowHeightMax = tileWidth * heightMaxFactor; rowHeightMax = tileWidth * heightMaxFactor;
@ -102,19 +102,20 @@ class MosaicSectionLayoutBuilder<T> extends SectionLayoutBuilder<T> {
builder: (context, listIndex) { builder: (context, listIndex) {
final textDirection = Directionality.of(context); final textDirection = Directionality.of(context);
final sectionChildIndex = listIndex - sectionFirstIndex; final sectionChildIndex = listIndex - sectionFirstIndex;
final row = sectionChildIndex == 0 ? null : rows[sectionChildIndex - 1]; final isHeader = sectionChildIndex == 0;
final sectionGridIndex = row != null ? (sectionChildIndex + 1) * columnCount + row.firstIndex : sectionChildIndex * columnCount; final row = isHeader ? rows.first : rows[sectionChildIndex - 1];
final sectionGridIndex = isHeader ? sectionFirstIndex * columnCount : (sectionChildIndex + 1) * columnCount + row.firstIndex;
return buildSectionWidget( return buildSectionWidget(
context: context, context: context,
section: section, section: section,
sectionGridIndex: sectionGridIndex, sectionGridIndex: sectionGridIndex,
sectionChildIndex: sectionChildIndex, sectionChildIndex: sectionChildIndex,
itemIndexRange: () => row == null ? const Tuple2(0, 0) : Tuple2(row.firstIndex, row.lastIndex + 1), itemIndexRange: () => isHeader ? const Tuple2(0, 0) : Tuple2(row.firstIndex, row.lastIndex + 1),
sectionKey: sectionKey, sectionKey: sectionKey,
headerExtent: headerExtent, headerExtent: headerExtent,
animate: animate, animate: animate,
buildGridRow: (children) { buildGridRow: (children) {
return row == null return isHeader
? const SizedBox() ? const SizedBox()
: MosaicGridRow( : MosaicGridRow(
rowLayout: row, rowLayout: row,

View file

@ -85,7 +85,7 @@ abstract class SectionLayoutBuilder<T> {
final durations = context.watch<DurationsData>(); final durations = context.watch<DurationsData>();
return AnimationConfiguration.staggeredGrid( return AnimationConfiguration.staggeredGrid(
position: index, position: index,
columnCount: tileLayout == TileLayout.mosaic ? columnCount * 2 : columnCount, columnCount: tileLayout == TileLayout.mosaic ? 1 : columnCount,
duration: durations.staggeredAnimation, duration: durations.staggeredAnimation,
delay: tileAnimationDelay, delay: tileAnimationDelay,
child: SlideAnimation( child: SlideAnimation(