mirror of
https://github.com/immich-app/immich.git
synced 2025-07-08 18:54:18 -04:00
refactor: animate bottom sheet (#19655)
* refactor: animate bottom sheet * rebase on main --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
parent
a3d588f6bd
commit
a5c431fbf5
@ -31,8 +31,9 @@ class HomeBottomAppBar extends ConsumerWidget {
|
|||||||
return BaseBottomSheet(
|
return BaseBottomSheet(
|
||||||
initialChildSize: 0.25,
|
initialChildSize: 0.25,
|
||||||
minChildSize: 0.22,
|
minChildSize: 0.22,
|
||||||
|
expand: false,
|
||||||
actions: [
|
actions: [
|
||||||
const ShareActionButton(),
|
if (multiselect.isEnabled) const ShareActionButton(),
|
||||||
if (multiselect.hasRemote) ...[
|
if (multiselect.hasRemote) ...[
|
||||||
const ShareLinkActionButton(source: ActionSource.timeline),
|
const ShareLinkActionButton(source: ActionSource.timeline),
|
||||||
const ArchiveActionButton(source: ActionSource.timeline),
|
const ArchiveActionButton(source: ActionSource.timeline),
|
||||||
|
@ -43,15 +43,26 @@ class Timeline extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SliverTimeline extends StatefulWidget {
|
class _SliverTimeline extends ConsumerStatefulWidget {
|
||||||
const _SliverTimeline();
|
const _SliverTimeline();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State createState() => _SliverTimelineState();
|
ConsumerState createState() => _SliverTimelineState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SliverTimelineState extends State<_SliverTimeline> {
|
class _SliverTimelineState extends ConsumerState<_SliverTimeline> {
|
||||||
final _scrollController = ScrollController();
|
final _scrollController = ScrollController();
|
||||||
|
PersistentBottomSheetController? _bottomSheetController;
|
||||||
|
bool _isMultiSelectEnabled = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
ref.listenManual(
|
||||||
|
multiSelectProvider.select((s) => s.isEnabled),
|
||||||
|
_onMultiSelectChanged,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
@ -59,15 +70,33 @@ class _SliverTimelineState extends State<_SliverTimeline> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onMultiSelectChanged(bool? previous, bool current) {
|
||||||
|
if (context.mounted && current != _isMultiSelectEnabled) {
|
||||||
|
setState(() {
|
||||||
|
_isMultiSelectEnabled = current;
|
||||||
|
if (current) {
|
||||||
|
_bottomSheetController = showBottomSheet(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => const HomeBottomAppBar(),
|
||||||
|
);
|
||||||
|
_bottomSheetController?.closed.then((_) {
|
||||||
|
_bottomSheetController = null;
|
||||||
|
// Reset the multi-select state when the bottom sheet is closed
|
||||||
|
ref.read(multiSelectProvider.notifier).reset();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
_bottomSheetController?.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext _) {
|
Widget build(BuildContext _) {
|
||||||
return Consumer(
|
|
||||||
builder: (context, ref, child) {
|
|
||||||
final asyncSegments = ref.watch(timelineSegmentProvider);
|
final asyncSegments = ref.watch(timelineSegmentProvider);
|
||||||
final maxHeight =
|
final maxHeight =
|
||||||
ref.watch(timelineArgsProvider.select((args) => args.maxHeight));
|
ref.watch(timelineArgsProvider.select((args) => args.maxHeight));
|
||||||
final isMultiSelectEnabled =
|
|
||||||
ref.watch(multiSelectProvider.select((s) => s.isEnabled));
|
|
||||||
return asyncSegments.widgetWhen(
|
return asyncSegments.widgetWhen(
|
||||||
onData: (segments) {
|
onData: (segments) {
|
||||||
final childCount = (segments.lastOrNull?.lastIndex ?? -1) + 1;
|
final childCount = (segments.lastOrNull?.lastIndex ?? -1) + 1;
|
||||||
@ -83,15 +112,14 @@ class _SliverTimelineState extends State<_SliverTimeline> {
|
|||||||
layoutSegments: segments,
|
layoutSegments: segments,
|
||||||
timelineHeight: maxHeight,
|
timelineHeight: maxHeight,
|
||||||
topPadding: totalAppBarHeight + 10,
|
topPadding: totalAppBarHeight + 10,
|
||||||
bottomPadding:
|
bottomPadding: context.padding.bottom + scrubberBottomPadding,
|
||||||
context.padding.bottom + scrubberBottomPadding,
|
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
primary: true,
|
primary: true,
|
||||||
cacheExtent: maxHeight * 2,
|
cacheExtent: maxHeight * 2,
|
||||||
slivers: [
|
slivers: [
|
||||||
SliverAnimatedOpacity(
|
SliverAnimatedOpacity(
|
||||||
duration: Durations.medium1,
|
duration: Durations.medium1,
|
||||||
opacity: isMultiSelectEnabled ? 0 : 1,
|
opacity: _isMultiSelectEnabled ? 0 : 1,
|
||||||
sliver: const ImmichSliverAppBar(
|
sliver: const ImmichSliverAppBar(
|
||||||
floating: true,
|
floating: true,
|
||||||
pinned: false,
|
pinned: false,
|
||||||
@ -121,21 +149,17 @@ class _SliverTimelineState extends State<_SliverTimeline> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (isMultiSelectEnabled) ...[
|
if (_isMultiSelectEnabled)
|
||||||
const Positioned(
|
const Positioned(
|
||||||
top: 60,
|
top: 60,
|
||||||
left: 25,
|
left: 25,
|
||||||
child: _MultiSelectStatusButton(),
|
child: _MultiSelectStatusButton(),
|
||||||
),
|
),
|
||||||
const HomeBottomAppBar(),
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user