Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Refine filter bottom sheet scrolling

ashilkn5d43f9e59053
diff --git a/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/filter_options_bottom_sheet.dart b/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/filter_options_bottom_sheet.dart
index b62350363e..ae75aa6ba3 100644
--- a/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/filter_options_bottom_sheet.dart
+++ b/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/filter_options_bottom_sheet.dart
@@ -18,6 +18,7 @@ class FilterOptionsBottomSheet extends StatefulWidget {
class _FilterOptionsBottomSheetState extends State<FilterOptionsBottomSheet> {
static const _maxContentHeightFactor = 0.68;
+ static const _topFadeHeight = 16.0;
late final Map<String, List<HierarchicalSearchFilter>> _filtersByType;
@@ -40,7 +41,8 @@ class _FilterOptionsBottomSheetState extends State<FilterOptionsBottomSheet> {
maxHeight:
MediaQuery.sizeOf(context).height * _maxContentHeightFactor,
),
- child: SingleChildScrollView(
+ child: _TopFadingScrollView(
+ fadeHeight: _topFadeHeight,
child: SizedBox(
width: double.infinity,
child: Column(
@@ -130,6 +132,50 @@ class _FilterOptionsBottomSheetState extends State<FilterOptionsBottomSheet> {
}
}
+class _TopFadingScrollView extends StatefulWidget {
+ const _TopFadingScrollView({required this.fadeHeight, required this.child});
+
+ final double fadeHeight;
+ final Widget child;
+
+ @override
+ State<_TopFadingScrollView> createState() => _TopFadingScrollViewState();
+}
+
+class _TopFadingScrollViewState extends State<_TopFadingScrollView> {
+ bool _hasScrolled = false;
+
+ @override
+ Widget build(BuildContext context) {
+ return ShaderMask(
+ blendMode: BlendMode.dstIn,
+ shaderCallback: (bounds) {
+ final fadeStop = (widget.fadeHeight / bounds.height).clamp(0.0, 1.0);
+ return LinearGradient(
+ begin: Alignment.topCenter,
+ end: Alignment.bottomCenter,
+ colors: _hasScrolled
+ ? const [Colors.transparent, Colors.black, Colors.black]
+ : const [Colors.black, Colors.black, Colors.black],
+ stops: [0, fadeStop.toDouble(), 1],
+ ).createShader(bounds);
+ },
+ child: NotificationListener<ScrollNotification>(
+ onNotification: _updateHasScrolled,
+ child: SingleChildScrollView(child: widget.child),
+ ),
+ );
+ }
+
+ bool _updateHasScrolled(ScrollNotification notification) {
+ final hasScrolled = notification.metrics.pixels > 0;
+ if (hasScrolled != _hasScrolled) {
+ setState(() => _hasScrolled = hasScrolled);
+ }
+ return false;
+ }
+}
+
class _FilterGroup {
final String label;
final List<HierarchicalSearchFilter> filters;
diff --git a/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart b/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart
index fcb88556e9..fabc05a6c0 100644
--- a/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart
+++ b/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart
@@ -22,7 +22,6 @@ class _BottomSheetHeaderComponent extends StatelessWidget {
this.closeTooltip = 'Close',
this.textAlign,
this.isCentered = false,
- this.height = _headerHeight,
});
final String? title;
@@ -36,7 +35,6 @@ class _BottomSheetHeaderComponent extends StatelessWidget {
final String closeTooltip;
final TextAlign? textAlign;
final bool isCentered;
- final double height;
@override
Widget build(BuildContext context) {
@@ -62,7 +60,7 @@ class _BottomSheetHeaderComponent extends StatelessWidget {
final colors = context.componentColors;
return SizedBox(
- height: height,
+ height: _headerHeight,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
@@ -103,7 +101,6 @@ class BottomSheetComponent extends StatelessWidget {
this.textAlign,
this.crossAxisAlignment = CrossAxisAlignment.start,
this.padding = const EdgeInsets.all(Spacing.xl),
- this.headerHeight = _headerHeight,
this.contentSpacing = Spacing.lg,
this.actionsTopSpacing = Spacing.lg,
this.backgroundColor,
@@ -126,11 +123,6 @@ class BottomSheetComponent extends StatelessWidget {
final TextAlign? textAlign;
final CrossAxisAlignment crossAxisAlignment;
final EdgeInsets padding;
-
- /// Height of the default title and close-button header.
- ///
- /// Ignored when [header] is provided.
- final double headerHeight;
final double contentSpacing;
final double actionsTopSpacing;
final Color? backgroundColor;
@@ -155,7 +147,6 @@ class BottomSheetComponent extends StatelessWidget {
closeTooltip: closeTooltip,
textAlign: textAlign,
isCentered: usesCenteredLayout,
- height: headerHeight,
)
: null);
final effectiveContent =
diff --git a/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart b/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart
index e2ae3e4427..8912dd7f71 100644
--- a/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart
+++ b/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart
@@ -55,33 +55,6 @@ void main() {
expect(find.text('Secondary'), findsOneWidget);
});
- testWidgets('BottomSheetComponent supports custom header height', (
- tester,
- ) async {
- await tester.pumpWidget(
- _wrap(
- const BottomSheetComponent(
- title: 'Default header',
- content: Text('Body copy'),
- ),
- ),
- );
-
- expect(_headerWithHeight('Default header', 38), findsOneWidget);
-
- await tester.pumpWidget(
- _wrap(
- const BottomSheetComponent(
- title: 'Custom header',
- headerHeight: 46,
- content: Text('Body copy'),
- ),
- ),
- );
-
- expect(_headerWithHeight('Custom header', 46), findsOneWidget);
- });
-
testWidgets('BottomSheetComponent centers illustration message', (
tester,
) async {
@@ -339,12 +312,3 @@ Future<void> _openLauncher(
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
}
-
-Finder _headerWithHeight(String title, double height) {
- return find.ancestor(
- of: find.text(title),
- matching: find.byWidgetPredicate(
- (widget) => widget is SizedBox && widget.height == height,
- ),
- );
-}