Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retention of scroll offset in emoji #1269

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/widgets/autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class AutocompleteField<QueryT extends AutocompleteQuery, ResultT exten

class _AutocompleteFieldState<QueryT extends AutocompleteQuery, ResultT extends AutocompleteResult> extends State<AutocompleteField<QueryT, ResultT>> with PerAccountStoreAwareStateMixin<AutocompleteField<QueryT, ResultT>> {
AutocompleteView<QueryT, ResultT>? _viewModel;
final ScrollController _scrollController = ScrollController();

void _initViewModel(QueryT query) {
_viewModel = widget.initViewModel(context, query)
Expand All @@ -57,7 +58,13 @@ class _AutocompleteFieldState<QueryT extends AutocompleteQuery, ResultT extends
_initViewModel(newQuery);
} else {
assert(_viewModel!.acceptsQuery(newQuery));
final oldQuery = _viewModel!.query;
_viewModel!.query = newQuery;
// Reset scroll when query content changes
if (oldQuery.toString() != newQuery.toString() &&
_scrollController.hasClients) {
_scrollController.jumpTo(0);
}
}
}
}
Expand Down Expand Up @@ -91,6 +98,7 @@ class _AutocompleteFieldState<QueryT extends AutocompleteQuery, ResultT extends
void dispose() {
widget.controller.removeListener(_handleControllerChange);
_viewModel?.dispose(); // removes our listener
_scrollController.dispose();
super.dispose();
}

Expand Down Expand Up @@ -133,6 +141,7 @@ class _AutocompleteFieldState<QueryT extends AutocompleteQuery, ResultT extends
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 300), // TODO not hard-coded
child: ListView.builder(
controller: _scrollController,
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: _resultsToDisplay.length,
Expand Down