💄 Adjust upload overlay auto show and hide logic
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
@@ -29,7 +28,8 @@ class UploadOverlay extends HookConsumerWidget {
|
|||||||
.toList()
|
.toList()
|
||||||
..sort((a, b) => b.createdAt.compareTo(a.createdAt)); // Newest first
|
..sort((a, b) => b.createdAt.compareTo(a.createdAt)); // Newest first
|
||||||
|
|
||||||
final isVisible = activeTasks.isNotEmpty;
|
final isVisibleOverride = useState<bool?>(null);
|
||||||
|
final isVisible = isVisibleOverride.value ?? activeTasks.isNotEmpty;
|
||||||
final slideController = useAnimationController(
|
final slideController = useAnimationController(
|
||||||
duration: const Duration(milliseconds: 300),
|
duration: const Duration(milliseconds: 300),
|
||||||
);
|
);
|
||||||
@@ -63,6 +63,7 @@ class UploadOverlay extends HookConsumerWidget {
|
|||||||
position: slideAnimation,
|
position: slideAnimation,
|
||||||
child: _UploadOverlayContent(
|
child: _UploadOverlayContent(
|
||||||
activeTasks: activeTasks,
|
activeTasks: activeTasks,
|
||||||
|
onVisibilityChanged: (bool? v) => isVisibleOverride.value = v,
|
||||||
).padding(bottom: 16 + MediaQuery.of(context).padding.bottom),
|
).padding(bottom: 16 + MediaQuery.of(context).padding.bottom),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -71,12 +72,15 @@ class UploadOverlay extends HookConsumerWidget {
|
|||||||
|
|
||||||
class _UploadOverlayContent extends HookConsumerWidget {
|
class _UploadOverlayContent extends HookConsumerWidget {
|
||||||
final List<DriveTask> activeTasks;
|
final List<DriveTask> activeTasks;
|
||||||
|
final void Function(bool?) onVisibilityChanged;
|
||||||
|
|
||||||
const _UploadOverlayContent({required this.activeTasks});
|
const _UploadOverlayContent({
|
||||||
|
required this.activeTasks,
|
||||||
|
required this.onVisibilityChanged,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final isExpanded = useState(false);
|
|
||||||
final animationController = useAnimationController(
|
final animationController = useAnimationController(
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 200),
|
||||||
initialValue: 0.0,
|
initialValue: 0.0,
|
||||||
@@ -90,12 +94,15 @@ class _UploadOverlayContent extends HookConsumerWidget {
|
|||||||
CurvedAnimation(parent: animationController, curve: Curves.easeInOut),
|
CurvedAnimation(parent: animationController, curve: Curves.easeInOut),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final isExpanded = useState(false);
|
||||||
|
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
if (isExpanded.value) {
|
if (isExpanded.value) {
|
||||||
animationController.forward();
|
animationController.forward();
|
||||||
} else {
|
} else {
|
||||||
animationController.reverse();
|
animationController.reverse();
|
||||||
}
|
}
|
||||||
|
onVisibilityChanged.call(isExpanded.value);
|
||||||
return null;
|
return null;
|
||||||
}, [isExpanded.value]);
|
}, [isExpanded.value]);
|
||||||
|
|
||||||
@@ -256,6 +263,7 @@ class _UploadOverlayContent extends HookConsumerWidget {
|
|||||||
ref
|
ref
|
||||||
.read(uploadTasksProvider.notifier)
|
.read(uploadTasksProvider.notifier)
|
||||||
.clearCompletedTasks();
|
.clearCompletedTasks();
|
||||||
|
isExpanded.value = false;
|
||||||
},
|
},
|
||||||
tileColor:
|
tileColor:
|
||||||
Theme.of(
|
Theme.of(
|
||||||
|
|||||||
Reference in New Issue
Block a user