Skip to content

Commit eaae6ec

Browse files
committed
wip msglist page take anchor; TODO test
TODO test: on jump and then new store, preserve jumped anchor
1 parent 39d2f10 commit eaae6ec

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

lib/widgets/message_list.dart

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,17 @@ abstract class MessageListPageState {
147147
}
148148

149149
class MessageListPage extends StatefulWidget {
150-
const MessageListPage({super.key, required this.initNarrow});
150+
const MessageListPage({
151+
super.key,
152+
required this.initNarrow,
153+
this.initAnchorMessageId,
154+
});
151155

152156
static AccountRoute<void> buildRoute({int? accountId, BuildContext? context,
153-
required Narrow narrow}) {
157+
required Narrow narrow, int? initAnchorMessageId}) {
154158
return MaterialAccountWidgetRoute(accountId: accountId, context: context,
155-
page: MessageListPage(initNarrow: narrow));
159+
page: MessageListPage(
160+
initNarrow: narrow, initAnchorMessageId: initAnchorMessageId));
156161
}
157162

158163
/// The [MessageListPageState] above this context in the tree.
@@ -168,6 +173,7 @@ class MessageListPage extends StatefulWidget {
168173
}
169174

170175
final Narrow initNarrow;
176+
final int? initAnchorMessageId;
171177

172178
@override
173179
State<MessageListPage> createState() => _MessageListPageState();
@@ -237,6 +243,10 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
237243
narrow: ChannelNarrow(streamId)))));
238244
}
239245

246+
// TODO(#80): default to anchor firstUnread, instead of newest
247+
final initAnchor = widget.initAnchorMessageId == null
248+
? AnchorCode.newest : NumericAnchor(widget.initAnchorMessageId!);
249+
240250
// Insert a PageRoot here, to provide a context that can be used for
241251
// MessageListPage.ancestorOf.
242252
return PageRoot(child: Scaffold(
@@ -256,7 +266,8 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
256266
// we matched to the Figma in 21dbae120. See another frame, which uses that:
257267
// https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=147%3A9088&mode=dev
258268
body: Builder(
259-
builder: (BuildContext context) => Column(
269+
builder: (BuildContext context) {
270+
return Column(
260271
// Children are expected to take the full horizontal space
261272
// and handle the horizontal device insets.
262273
// The bottom inset should be handled by the last child only.
@@ -276,11 +287,13 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
276287
child: MessageList(
277288
key: _messageListKey,
278289
narrow: narrow,
290+
initAnchor: initAnchor,
279291
onNarrowChanged: _narrowChanged,
280292
))),
281293
if (ComposeBox.hasComposeBox(narrow))
282294
ComposeBox(key: _composeBoxKey, narrow: narrow)
283-
]))));
295+
]);
296+
})));
284297
}
285298
}
286299

@@ -438,9 +451,15 @@ const kFetchMessagesBufferPixels = (kMessageListFetchBatchSize / 2) * _kShortMes
438451
/// When there is no [ComposeBox], also takes responsibility
439452
/// for dealing with the bottom inset.
440453
class MessageList extends StatefulWidget {
441-
const MessageList({super.key, required this.narrow, required this.onNarrowChanged});
454+
const MessageList({
455+
super.key,
456+
required this.narrow,
457+
required this.initAnchor,
458+
required this.onNarrowChanged,
459+
});
442460

443461
final Narrow narrow;
462+
final Anchor initAnchor;
444463
final void Function(Narrow newNarrow) onNarrowChanged;
445464

446465
@override
@@ -463,8 +482,9 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
463482

464483
@override
465484
void onNewStore() { // TODO(#464) try to keep using old model until new one gets messages
485+
final anchor = _model == null ? widget.initAnchor : _model!.anchor;
466486
_model?.dispose();
467-
_initModel(PerAccountStoreWidget.of(context));
487+
_initModel(PerAccountStoreWidget.of(context), anchor);
468488
}
469489

470490
@override
@@ -475,10 +495,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
475495
super.dispose();
476496
}
477497

478-
void _initModel(PerAccountStore store) {
479-
// TODO(#82): get anchor as page/route argument, instead of using newest
480-
// TODO(#80): default to anchor firstUnread, instead of newest
481-
final anchor = AnchorCode.newest;
498+
void _initModel(PerAccountStore store, Anchor anchor) {
482499
_model = MessageListView.init(store: store,
483500
narrow: widget.narrow, anchor: anchor);
484501
model.addListener(_modelChanged);

0 commit comments

Comments
 (0)