Skip to content

Commit ec7b14c

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

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
@@ -141,12 +141,17 @@ abstract class MessageListPageState {
141141
}
142142

143143
class MessageListPage extends StatefulWidget {
144-
const MessageListPage({super.key, required this.initNarrow});
144+
const MessageListPage({
145+
super.key,
146+
required this.initNarrow,
147+
this.initAnchorMessageId,
148+
});
145149

146150
static AccountRoute<void> buildRoute({int? accountId, BuildContext? context,
147-
required Narrow narrow}) {
151+
required Narrow narrow, int? initAnchorMessageId}) {
148152
return MaterialAccountWidgetRoute(accountId: accountId, context: context,
149-
page: MessageListPage(initNarrow: narrow));
153+
page: MessageListPage(
154+
initNarrow: narrow, initAnchorMessageId: initAnchorMessageId));
150155
}
151156

152157
/// The [MessageListPageState] above this context in the tree.
@@ -162,6 +167,7 @@ class MessageListPage extends StatefulWidget {
162167
}
163168

164169
final Narrow initNarrow;
170+
final int? initAnchorMessageId;
165171

166172
@override
167173
State<MessageListPage> createState() => _MessageListPageState();
@@ -240,6 +246,10 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
240246
actions.add(_TopicListButton(streamId: streamId));
241247
}
242248

249+
// TODO(#80): default to anchor firstUnread, instead of newest
250+
final initAnchor = widget.initAnchorMessageId == null
251+
? AnchorCode.newest : NumericAnchor(widget.initAnchorMessageId!);
252+
243253
// Insert a PageRoot here, to provide a context that can be used for
244254
// MessageListPage.ancestorOf.
245255
return PageRoot(child: Scaffold(
@@ -259,7 +269,8 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
259269
// we matched to the Figma in 21dbae120. See another frame, which uses that:
260270
// https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=147%3A9088&mode=dev
261271
body: Builder(
262-
builder: (BuildContext context) => Column(
272+
builder: (BuildContext context) {
273+
return Column(
263274
// Children are expected to take the full horizontal space
264275
// and handle the horizontal device insets.
265276
// The bottom inset should be handled by the last child only.
@@ -279,11 +290,13 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
279290
child: MessageList(
280291
key: _messageListKey,
281292
narrow: narrow,
293+
initAnchor: initAnchor,
282294
onNarrowChanged: _narrowChanged,
283295
))),
284296
if (ComposeBox.hasComposeBox(narrow))
285297
ComposeBox(key: _composeBoxKey, narrow: narrow)
286-
]))));
298+
]);
299+
})));
287300
}
288301
}
289302

@@ -470,9 +483,15 @@ const kFetchMessagesBufferPixels = (kMessageListFetchBatchSize / 2) * _kShortMes
470483
/// When there is no [ComposeBox], also takes responsibility
471484
/// for dealing with the bottom inset.
472485
class MessageList extends StatefulWidget {
473-
const MessageList({super.key, required this.narrow, required this.onNarrowChanged});
486+
const MessageList({
487+
super.key,
488+
required this.narrow,
489+
required this.initAnchor,
490+
required this.onNarrowChanged,
491+
});
474492

475493
final Narrow narrow;
494+
final Anchor initAnchor;
476495
final void Function(Narrow newNarrow) onNarrowChanged;
477496

478497
@override
@@ -495,8 +514,9 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
495514

496515
@override
497516
void onNewStore() { // TODO(#464) try to keep using old model until new one gets messages
517+
final anchor = _model == null ? widget.initAnchor : _model!.anchor;
498518
_model?.dispose();
499-
_initModel(PerAccountStoreWidget.of(context));
519+
_initModel(PerAccountStoreWidget.of(context), anchor);
500520
}
501521

502522
@override
@@ -507,10 +527,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
507527
super.dispose();
508528
}
509529

510-
void _initModel(PerAccountStore store) {
511-
// TODO(#82): get anchor as page/route argument, instead of using newest
512-
// TODO(#80): default to anchor firstUnread, instead of newest
513-
final anchor = AnchorCode.newest;
530+
void _initModel(PerAccountStore store, Anchor anchor) {
514531
_model = MessageListView.init(store: store,
515532
narrow: widget.narrow, anchor: anchor);
516533
model.addListener(_modelChanged);

0 commit comments

Comments
 (0)