Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
resize_handler: Fix scroll jumps on iOS.
Aman Agrawal885957c5297e
diff --git a/web/src/resize_handler.ts b/web/src/resize_handler.tsindex c5d4b089e10..67a24e98a7a 100644--- a/web/src/resize_handler.ts+++ b/web/src/resize_handler.ts@@ -13,6 +13,7 @@ export let _old_width = $(window).width();export function handler(): void {const new_width = $(window).width();+ let width_changed = false;const mobile = util.is_mobile();if (!mobile || new_width !== _old_width) {@@ -21,6 +22,7 @@ export function handler(): void {if (new_width !== _old_width) {_old_width = new_width;+ width_changed = true;}resize.resize_page_components();compose_ui.autosize_textarea($("textarea#compose-textarea"));@@ -30,10 +32,19 @@ export function handler(): void {// Re-compute and display/remove 'Show more' buttons to messagescondense.condense_and_collapse(message_lists.all_current_message_rows());+ // Height can change on mobile OS like i0S if scrolling causes URL bar to change height.+ // We don't want to cause scroll jump in that case and just let our logic for keeping the+ // selected message in the view handle it. Width can change due change in device orientation+ // in which case we want to scroll to the selected message.+ const only_height_changed_on_mobile = mobile && !width_changed;// This function might run onReady (if we're in a narrow window),// but before we've loaded in the messages; in that case, don't// try to scroll to one.- if (message_lists.current !== undefined && message_lists.current.selected_id() !== -1) {+ if (+ !only_height_changed_on_mobile &&+ message_lists.current !== undefined &&+ message_lists.current.selected_id() !== -1+ ) {message_viewport.scroll_to_selected();}}