@@ -147,12 +147,17 @@ abstract class MessageListPageState {
147
147
}
148
148
149
149
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
+ });
151
155
152
156
static AccountRoute <void > buildRoute ({int ? accountId, BuildContext ? context,
153
- required Narrow narrow}) {
157
+ required Narrow narrow, int ? initAnchorMessageId }) {
154
158
return MaterialAccountWidgetRoute (accountId: accountId, context: context,
155
- page: MessageListPage (initNarrow: narrow));
159
+ page: MessageListPage (
160
+ initNarrow: narrow, initAnchorMessageId: initAnchorMessageId));
156
161
}
157
162
158
163
/// The [MessageListPageState] above this context in the tree.
@@ -168,6 +173,7 @@ class MessageListPage extends StatefulWidget {
168
173
}
169
174
170
175
final Narrow initNarrow;
176
+ final int ? initAnchorMessageId;
171
177
172
178
@override
173
179
State <MessageListPage > createState () => _MessageListPageState ();
@@ -237,6 +243,10 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
237
243
narrow: ChannelNarrow (streamId)))));
238
244
}
239
245
246
+ // TODO(#80): default to anchor firstUnread, instead of newest
247
+ final initAnchor = widget.initAnchorMessageId == null
248
+ ? AnchorCode .newest : NumericAnchor (widget.initAnchorMessageId! );
249
+
240
250
// Insert a PageRoot here, to provide a context that can be used for
241
251
// MessageListPage.ancestorOf.
242
252
return PageRoot (child: Scaffold (
@@ -256,7 +266,8 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
256
266
// we matched to the Figma in 21dbae120. See another frame, which uses that:
257
267
// https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=147%3A9088&mode=dev
258
268
body: Builder (
259
- builder: (BuildContext context) => Column (
269
+ builder: (BuildContext context) {
270
+ return Column (
260
271
// Children are expected to take the full horizontal space
261
272
// and handle the horizontal device insets.
262
273
// The bottom inset should be handled by the last child only.
@@ -276,11 +287,13 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
276
287
child: MessageList (
277
288
key: _messageListKey,
278
289
narrow: narrow,
290
+ initAnchor: initAnchor,
279
291
onNarrowChanged: _narrowChanged,
280
292
))),
281
293
if (ComposeBox .hasComposeBox (narrow))
282
294
ComposeBox (key: _composeBoxKey, narrow: narrow)
283
- ]))));
295
+ ]);
296
+ })));
284
297
}
285
298
}
286
299
@@ -438,9 +451,15 @@ const kFetchMessagesBufferPixels = (kMessageListFetchBatchSize / 2) * _kShortMes
438
451
/// When there is no [ComposeBox] , also takes responsibility
439
452
/// for dealing with the bottom inset.
440
453
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
+ });
442
460
443
461
final Narrow narrow;
462
+ final Anchor initAnchor;
444
463
final void Function (Narrow newNarrow) onNarrowChanged;
445
464
446
465
@override
@@ -463,8 +482,9 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
463
482
464
483
@override
465
484
void onNewStore () { // TODO(#464) try to keep using old model until new one gets messages
485
+ final anchor = _model == null ? widget.initAnchor : _model! .anchor;
466
486
_model? .dispose ();
467
- _initModel (PerAccountStoreWidget .of (context));
487
+ _initModel (PerAccountStoreWidget .of (context), anchor );
468
488
}
469
489
470
490
@override
@@ -475,10 +495,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
475
495
super .dispose ();
476
496
}
477
497
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) {
482
499
_model = MessageListView .init (store: store,
483
500
narrow: widget.narrow, anchor: anchor);
484
501
model.addListener (_modelChanged);
0 commit comments