Open long chats bottom-anchored so only the rows that show are laid out
This commit is contained in:
@@ -103,27 +103,39 @@ void main() {
|
||||
expect(chatRestoreOffset(savedOffset: 0, maxScrollExtent: 640), 0);
|
||||
expect(chatRestoreOffset(savedOffset: 900, maxScrollExtent: 640), 640);
|
||||
});
|
||||
|
||||
test('a bottom-anchored position above the centre stays negative', () {
|
||||
double restore(double saved) => chatRestoreOffset(
|
||||
savedOffset: saved,
|
||||
minScrollExtent: -2000,
|
||||
maxScrollExtent: 300,
|
||||
);
|
||||
expect(restore(-750), -750);
|
||||
expect(restore(-5000), -2000);
|
||||
expect(restore(900), 300);
|
||||
});
|
||||
});
|
||||
|
||||
group('store', () {
|
||||
test('remembers one conversation without touching another', () {
|
||||
final store = MemoryChatScrollStore();
|
||||
store.write('a', 120);
|
||||
store.write('b', 30);
|
||||
expect(store.read('a'), 120);
|
||||
expect(store.read('b'), 30);
|
||||
store.write('a', (offset: 120, anchor: null));
|
||||
store.write('b', (offset: -30, anchor: 'm4'));
|
||||
expect(store.read('a'), (offset: 120.0, anchor: null));
|
||||
expect(store.read('b'), (offset: -30.0, anchor: 'm4'));
|
||||
expect(store.read('c'), isNull);
|
||||
|
||||
store.clear('a');
|
||||
expect(store.read('a'), isNull);
|
||||
expect(store.entries, {'b': 30.0});
|
||||
expect(store.entries, {'b': (offset: -30.0, anchor: 'm4')});
|
||||
});
|
||||
|
||||
test('ignores an unusable offset instead of inventing a position', () {
|
||||
final store = MemoryChatScrollStore();
|
||||
store.write('a', double.nan);
|
||||
store.write('a', double.infinity);
|
||||
store.write('a', -5);
|
||||
store.write('a', (offset: double.nan, anchor: 'm1'));
|
||||
store.write('a', (offset: double.infinity, anchor: null));
|
||||
// Only a bottom-anchored offset counts from a centre and can be negative.
|
||||
store.write('a', (offset: -5, anchor: null));
|
||||
expect(store.read('a'), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user