Skip to content

Retention of scroll offset in emoji #1269

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions lib/widgets/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ class ZulipApp extends StatefulWidget {

final localizations = ZulipLocalizations.of(navigatorKey.currentContext!);
final newSnackBar = scaffoldMessenger!.showSnackBar(
snackBarAnimationStyle: AnimationStyle(
duration: const Duration(milliseconds: 200),
reverseDuration: const Duration(milliseconds: 50)),
snackBarAnimationStyle: const AnimationStyle(
duration: Duration(milliseconds: 200),
reverseDuration: Duration(milliseconds: 50)),
SnackBar(
content: Text(message),
action: (details == null) ? null : SnackBarAction(
Expand Down
7 changes: 7 additions & 0 deletions lib/widgets/autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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 @@ -63,6 +64,10 @@ class _AutocompleteFieldState<QueryT extends AutocompleteQuery, ResultT extends
} else {
assert(_viewModel!.acceptsQuery(newQuery));
_viewModel!.query = newQuery;
// Reset scroll when query content changes
if (_scrollController.hasClients) {
_scrollController.jumpTo(0);
}
}
}
}
Expand Down Expand Up @@ -96,6 +101,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 @@ -138,6 +144,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