mirror of
https://github.com/block/buzz.git
synced 2026-11-07 01:41:06 +00:00
Floating dates in conversations and threads now appear during reader scrolling, then fade to zero over 250 ms after one second idle. Automatic positioning stays quiet, and renewed scrolling reveals the date immediately. Reduced-motion behavior is preserved. Validation: mobile analysis, scroll/timing widget tests, and iPhone Air preview. Full mobile tests run through the push gate. Home and Inbox styling has moved to [#9187](https://github.com/block/buzz/pull/9187); this diff only contains scrolling-date behavior and its supporting tests/helper extraction. --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
45 lines
1.3 KiB
Dart
45 lines
1.3 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
/// Keeps the date anchor visible through a reader's scroll and briefly afterward.
|
|
class DateHeaderScrollActivity extends ValueNotifier<bool> {
|
|
DateHeaderScrollActivity() : super(false);
|
|
|
|
Timer? _idleTimer;
|
|
bool _readerScrolling = false;
|
|
|
|
bool onNotification(ScrollNotification notification) {
|
|
if (notification.depth != 0 || notification.metrics.axis != Axis.vertical) {
|
|
return false;
|
|
}
|
|
if (notification is ScrollStartNotification &&
|
|
notification.dragDetails != null ||
|
|
notification is UserScrollNotification &&
|
|
notification.direction != ScrollDirection.idle) {
|
|
_readerScrolling = true;
|
|
}
|
|
if (_readerScrolling) {
|
|
value = true;
|
|
_idleTimer?.cancel();
|
|
_idleTimer = Timer(const Duration(seconds: 1), () => value = false);
|
|
}
|
|
if (notification is ScrollEndNotification) _readerScrolling = false;
|
|
return false;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_idleTimer?.cancel();
|
|
super.dispose();
|
|
}
|
|
}
|
|
|
|
DateHeaderScrollActivity useDateHeaderScrollActivity(String timelineId) {
|
|
final activity = useMemoized(DateHeaderScrollActivity.new, [timelineId]);
|
|
useEffect(() => activity.dispose, [activity]);
|
|
return activity;
|
|
}
|