Files
buzz/mobile/lib/features/channels/ime_metrics_settle_observer.dart
klopez4212 69107dc3bf Polish mobile message threads and composer (#5645)
## Summary

- refine mobile message metadata, search spacing, and Activity filter
semantics
- add channel-parity Latest navigation and stable tail following to
threads
- synchronize Android composer/keyboard geometry and keep Latest spacing
stable across IME transitions

## Validation

- `bin/just mobile-check`
- `bin/just mobile-test` (1,276 tests)
- Pixel 10 install/launch and channel/thread keyboard, Latest, tail, and
back-navigation review
- signed iPhone install/launch workflow

## Snapshots

See the review snapshots below.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Signed-off-by: Kenny Lopez <klopez4212@gmail.com>
Signed-off-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
Co-authored-by: Fast Fizz <2df81cb51f05a9d5387ef24d7b9ecb8fcdfcd1c70ffabc67061c9596e1b5b1c4@buzz.block.builderlab.xyz>
Co-authored-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
2026-08-15 09:14:14 +01:00

45 lines
1.5 KiB
Dart

import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
/// How long Android viewport metrics must stay quiet before layout correction.
const androidImeMetricsSettleDelay = Duration(milliseconds: 120);
/// Coalesces Android's frame-by-frame IME metrics into one settled callback.
///
/// iOS continues to receive callbacks immediately. Android sends viewport
/// metrics throughout the keyboard animation; doing list realignment for each
/// delivery competes with the IME transition and can drop frames.
class ImeMetricsSettleObserver with WidgetsBindingObserver {
/// Runs after Android metrics remain quiet for [androidSettleDelay], or
/// immediately for each metrics change on other platforms.
final VoidCallback onMetricsSettled;
/// The quiet period used to coalesce Android IME animation metrics.
final Duration androidSettleDelay;
Timer? _androidTimer;
/// Creates an observer that coalesces Android IME metric updates.
ImeMetricsSettleObserver({
required this.onMetricsSettled,
this.androidSettleDelay = androidImeMetricsSettleDelay,
});
@override
void didChangeMetrics() {
if (defaultTargetPlatform != TargetPlatform.android) {
onMetricsSettled();
return;
}
_androidTimer?.cancel();
_androidTimer = Timer(androidSettleDelay, onMetricsSettled);
}
/// Cancels any pending Android metrics-settlement callback.
void dispose() {
_androidTimer?.cancel();
_androidTimer = null;
}
}