mirror of
https://github.com/immich-app/immich.git
synced 2025-08-07 09:04:09 -04:00
feat: change grid size with gesture (#20455)
This commit is contained in:
parent
a07531be3b
commit
4bd465e752
@ -3,6 +3,7 @@ import 'dart:math' as math;
|
|||||||
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
@ -88,10 +89,23 @@ class _SliverTimelineState extends ConsumerState<_SliverTimeline> {
|
|||||||
final _scrollController = ScrollController();
|
final _scrollController = ScrollController();
|
||||||
StreamSubscription? _eventSubscription;
|
StreamSubscription? _eventSubscription;
|
||||||
|
|
||||||
|
int _perRow = 4;
|
||||||
|
double _scaleFactor = 3.0;
|
||||||
|
double _baseScaleFactor = 3.0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_eventSubscription = EventStream.shared.listen(_onEvent);
|
_eventSubscription = EventStream.shared.listen(_onEvent);
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
final currentTilesPerRow = ref.read(settingsProvider).get(Setting.tilesPerRow);
|
||||||
|
setState(() {
|
||||||
|
_perRow = currentTilesPerRow;
|
||||||
|
_scaleFactor = 7.0 - _perRow;
|
||||||
|
_baseScaleFactor = _scaleFactor;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onEvent(Event event) {
|
void _onEvent(Event event) {
|
||||||
@ -177,43 +191,72 @@ class _SliverTimelineState extends ConsumerState<_SliverTimeline> {
|
|||||||
|
|
||||||
return PrimaryScrollController(
|
return PrimaryScrollController(
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
child: Stack(
|
child: RawGestureDetector(
|
||||||
children: [
|
gestures: {
|
||||||
Scrubber(
|
CustomScaleGestureRecognizer: GestureRecognizerFactoryWithHandlers<CustomScaleGestureRecognizer>(
|
||||||
layoutSegments: segments,
|
() => CustomScaleGestureRecognizer(),
|
||||||
timelineHeight: maxHeight,
|
(CustomScaleGestureRecognizer scale) {
|
||||||
topPadding: topPadding,
|
scale.onStart = (details) {
|
||||||
bottomPadding: bottomPadding,
|
_baseScaleFactor = _scaleFactor;
|
||||||
monthSegmentSnappingOffset: widget.topSliverWidgetHeight ?? 0 + appBarExpandedHeight,
|
};
|
||||||
child: CustomScrollView(
|
|
||||||
primary: true,
|
scale.onUpdate = (details) {
|
||||||
cacheExtent: maxHeight * 2,
|
final newScaleFactor = math.max(math.min(5.0, _baseScaleFactor * details.scale), 1.0);
|
||||||
slivers: [
|
final newPerRow = 7 - newScaleFactor.toInt();
|
||||||
if (isSelectionMode) const SelectionSliverAppBar() else if (widget.appBar != null) widget.appBar!,
|
|
||||||
if (widget.topSliverWidget != null) widget.topSliverWidget!,
|
if (newPerRow != _perRow) {
|
||||||
_SliverSegmentedList(
|
setState(() {
|
||||||
segments: segments,
|
_scaleFactor = newScaleFactor;
|
||||||
delegate: SliverChildBuilderDelegate(
|
_perRow = newPerRow;
|
||||||
(ctx, index) {
|
});
|
||||||
if (index >= childCount) return null;
|
|
||||||
final segment = segments.findByIndex(index);
|
ref.read(settingsProvider.notifier).set(Setting.tilesPerRow, _perRow);
|
||||||
return segment?.builder(ctx, index) ?? const SizedBox.shrink();
|
}
|
||||||
},
|
};
|
||||||
childCount: childCount,
|
},
|
||||||
addAutomaticKeepAlives: false,
|
|
||||||
// We add repaint boundary around tiles, so skip the auto boundaries
|
|
||||||
addRepaintBoundaries: false,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SliverPadding(padding: EdgeInsets.only(bottom: scrubberBottomPadding)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
if (!isSelectionMode && isMultiSelectEnabled) ...[
|
},
|
||||||
const Positioned(top: 60, left: 25, child: _MultiSelectStatusButton()),
|
child: Stack(
|
||||||
if (widget.bottomSheet != null) widget.bottomSheet!,
|
children: [
|
||||||
|
Scrubber(
|
||||||
|
layoutSegments: segments,
|
||||||
|
timelineHeight: maxHeight,
|
||||||
|
topPadding: topPadding,
|
||||||
|
bottomPadding: bottomPadding,
|
||||||
|
monthSegmentSnappingOffset: widget.topSliverWidgetHeight ?? 0 + appBarExpandedHeight,
|
||||||
|
child: CustomScrollView(
|
||||||
|
primary: true,
|
||||||
|
cacheExtent: maxHeight * 2,
|
||||||
|
slivers: [
|
||||||
|
if (isSelectionMode)
|
||||||
|
const SelectionSliverAppBar()
|
||||||
|
else if (widget.appBar != null)
|
||||||
|
widget.appBar!,
|
||||||
|
if (widget.topSliverWidget != null) widget.topSliverWidget!,
|
||||||
|
_SliverSegmentedList(
|
||||||
|
segments: segments,
|
||||||
|
delegate: SliverChildBuilderDelegate(
|
||||||
|
(ctx, index) {
|
||||||
|
if (index >= childCount) return null;
|
||||||
|
final segment = segments.findByIndex(index);
|
||||||
|
return segment?.builder(ctx, index) ?? const SizedBox.shrink();
|
||||||
|
},
|
||||||
|
childCount: childCount,
|
||||||
|
addAutomaticKeepAlives: false,
|
||||||
|
// We add repaint boundary around tiles, so skip the auto boundaries
|
||||||
|
addRepaintBoundaries: false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SliverPadding(padding: EdgeInsets.only(bottom: scrubberBottomPadding)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (!isSelectionMode && isMultiSelectEnabled) ...[
|
||||||
|
const Positioned(top: 60, left: 25, child: _MultiSelectStatusButton()),
|
||||||
|
if (widget.bottomSheet != null) widget.bottomSheet!,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -443,3 +486,11 @@ class _MultiSelectStatusButton extends ConsumerWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// accepts a gesture even though it should reject it (because child won)
|
||||||
|
class CustomScaleGestureRecognizer extends ScaleGestureRecognizer {
|
||||||
|
@override
|
||||||
|
void rejectGesture(int pointer) {
|
||||||
|
acceptGesture(pointer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user