A platform for community discussion. Free, open, simple.
DEV: Drop non-visualViewport Safari hacks (#15007)
Jarek Radoszcabacb5c4809
diff --git a/app/assets/javascripts/discourse/app/components/emoji-picker.js b/app/assets/javascripts/discourse/app/components/emoji-picker.jsindex 20189196442..3d04b226bb7 100644--- a/app/assets/javascripts/discourse/app/components/emoji-picker.js+++ b/app/assets/javascripts/discourse/app/components/emoji-picker.js@@ -6,7 +6,7 @@ import {isSkinTonableEmoji,} from "pretty-text/emoji";import { emojiUnescape, emojiUrlFor } from "discourse/lib/text";-import { escapeExpression, safariHacksDisabled } from "discourse/lib/utilities";+import { escapeExpression } from "discourse/lib/utilities";import { later, schedule } from "@ember/runloop";import Component from "@ember/component";import { createPopper } from "@popperjs/core";@@ -115,10 +115,7 @@ export default Component.extend({this.set("isLoading", false);schedule("afterRender", () => {- if (- (!this.site.isMobileDevice || this.isEditorFocused) &&- !safariHacksDisabled()- ) {+ if (!this.site.isMobileDevice || this.isEditorFocused) {const filter = emojiPicker.querySelector("input.filter");filter && filter.focus();diff --git a/app/assets/javascripts/discourse/app/controllers/preferences/interface.js b/app/assets/javascripts/discourse/app/controllers/preferences/interface.jsindex 8a769cee584..d91dde1b52d 100644--- a/app/assets/javascripts/discourse/app/controllers/preferences/interface.js+++ b/app/assets/javascripts/discourse/app/controllers/preferences/interface.js@@ -1,11 +1,6 @@import Controller, { inject as controller } from "@ember/controller";import Session from "discourse/models/session";-import {- iOSWithVisualViewport,- isiPad,- safariHacksDisabled,- setDefaultHomepage,-} from "discourse/lib/utilities";+import { setDefaultHomepage } from "discourse/lib/utilities";import {listColorSchemes,loadColorSchemeStylesheet,@@ -72,18 +67,6 @@ export default Controller.extend({return attrs;},- @discourseComputed()- isiPad() {- // TODO: remove this preference checkbox when iOS adoption > 90%- // (currently only applies to iOS 12 and below)- return isiPad() && !iOSWithVisualViewport();- },-- @discourseComputed()- disableSafariHacks() {- return safariHacksDisabled();- },-@discourseComputed()availableLocales() {return JSON.parse(this.siteSettings.available_locales);@@ -342,16 +325,6 @@ export default Controller.extend({this.homeChanged();- if (this.isiPad) {- if (safariHacksDisabled() !== this.disableSafariHacks) {- this.session.requiresRefresh = true;- }- localStorage.setItem(- "safari-hacks-disabled",- this.disableSafariHacks.toString()- );- }-if (this.themeId !== this.currentThemeId) {reload();}diff --git a/app/assets/javascripts/discourse/app/lib/safari-hacks.js b/app/assets/javascripts/discourse/app/lib/safari-hacks.jsindex 3f6c17fe155..5d9f8f0e5b7 100644--- a/app/assets/javascripts/discourse/app/lib/safari-hacks.js+++ b/app/assets/javascripts/discourse/app/lib/safari-hacks.js@@ -1,76 +1,8 @@-import {- iOSWithVisualViewport,- safariHacksDisabled,-} from "discourse/lib/utilities";import { INPUT_DELAY } from "discourse-common/config/environment";import discourseDebounce from "discourse-common/lib/debounce";import { helperContext } from "discourse-common/lib/helpers";import { later } from "@ember/runloop";-// TODO: remove calcHeight once iOS 13 adoption > 90%-// In iOS 13 and up we use visualViewport API to calculate height--// we can't tell what the actual visible window height is-// because we cannot account for the height of the mobile keyboard-// and any other mobile autocomplete UI that may appear-// so let's be conservative here rather than trying to max out every-// available pixel of height for the editor-function calcHeight() {- // estimate 270 px for keyboard- let withoutKeyboard = window.innerHeight - 270;- const min = 270;-- // iPhone shrinks header and removes footer controls ( back / forward nav )- // at 39px we are at the largest viewport- const portrait = window.innerHeight > window.innerWidth;- const smallViewport =- (portrait ? window.screen.height : window.screen.width) -- window.innerHeight >- 40;-- if (portrait) {- // iPhone SE, it is super small so just- // have a bit of crop- if (window.screen.height === 568) {- withoutKeyboard = 270;- }-- // iPhone 6/7/8- if (window.screen.height === 667) {- withoutKeyboard = smallViewport ? 295 : 325;- }-- // iPhone 6/7/8 plus- if (window.screen.height === 736) {- withoutKeyboard = smallViewport ? 353 : 383;- }-- // iPhone X- if (window.screen.height === 812) {- withoutKeyboard = smallViewport ? 340 : 370;- }-- // iPhone Xs Max and iPhone Xʀ- if (window.screen.height === 896) {- withoutKeyboard = smallViewport ? 410 : 440;- }-- // iPad can use innerHeight cause it renders nothing in the footer- if (window.innerHeight > 920) {- withoutKeyboard -= 45;- }- } else {- // landscape- // iPad, we have a bigger keyboard- if (window.innerHeight > 665) {- withoutKeyboard -= 128;- }- }-- // iPad portrait also has a bigger keyboard- return Math.max(withoutKeyboard, min);-}-let workaroundActive = false;export function isWorkaroundActive() {@@ -80,7 +12,7 @@ export function isWorkaroundActive() {// per http://stackoverflow.com/questions/29001977/safari-in-ios8-is-scrolling-screen-when-fixed-elements-get-focus/29064810function positioningWorkaround($fixedElement) {let caps = helperContext().capabilities;- if (!caps.isIOS || safariHacksDisabled()) {+ if (!caps.isIOS) {return;}@@ -91,8 +23,6 @@ function positioningWorkaround($fixedElement) {});const fixedElement = $fixedElement[0];- const oldHeight = fixedElement.style.height;-let originalScrollTop = 0;let lastTouchedElement = null;@@ -106,11 +36,6 @@ function positioningWorkaround($fixedElement) {}workaroundActive = false;-- if (!iOSWithVisualViewport()) {- fixedElement.style.height = oldHeight;- later(() => $(fixedElement).removeClass("no-transition"), 500);- }}};@@ -172,8 +97,8 @@ function positioningWorkaround($fixedElement) {let delay = caps.isIpadOS ? 350 : 150;- later(function () {- if (caps.isIpadOS && iOSWithVisualViewport()) {+ later(() => {+ if (caps.isIpadOS) {// disable hacks when using a hardware keyboard// by default, a hardware keyboard will show the keyboard accessory bar// whose height is currently 55px (using 75 for a bit of a buffer)@@ -191,12 +116,6 @@ function positioningWorkaround($fixedElement) {document.body.classList.add("ios-safari-composer-hacks");window.scrollTo(0, 0);- if (!iOSWithVisualViewport()) {- const height = calcHeight();- fixedElement.style.height = height + "px";- $(fixedElement).addClass("no-transition");- }-evt.preventDefault();_this.focus();workaroundActive = true;diff --git a/app/assets/javascripts/discourse/app/lib/utilities.js b/app/assets/javascripts/discourse/app/lib/utilities.jsindex acdc69825e0..c6a5ca1446d 100644--- a/app/assets/javascripts/discourse/app/lib/utilities.js+++ b/app/assets/javascripts/discourse/app/lib/utilities.js@@ -5,6 +5,7 @@ import { deepMerge } from "discourse-common/lib/object";import { escape } from "pretty-text/sanitizer";import { helperContext } from "discourse-common/lib/helpers";import toMarkdown from "discourse/lib/to-markdown";+import deprecated from "discourse-common/lib/deprecated";let _defaultHomepage;@@ -306,10 +307,6 @@ export function isAppleDevice() {let iPadDetected = undefined;-export function iOSWithVisualViewport() {- return isAppleDevice() && window.visualViewport !== undefined;-}-export function isiPad() {if (iPadDetected === undefined) {iPadDetected =@@ -320,16 +317,15 @@ export function isiPad() {}export function safariHacksDisabled() {- if (iOSWithVisualViewport()) {- return false;- }+ deprecated(+ "`safariHacksDisabled()` is deprecated, it now always returns `false`",+ {+ since: "2.8.0.beta8",+ dropFrom: "2.9.0.beta1",+ }+ );- let pref = localStorage.getItem("safari-hacks-disabled");- let result = false;- if (pref !== null) {- result = pref === "true";- }- return result;+ return false;}const toArray = (items) => {diff --git a/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js b/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.jsindex aab066c61b9..6dd67f74ad9 100644--- a/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js+++ b/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js@@ -8,7 +8,6 @@ import { isTesting } from "discourse-common/config/environment";import {clipboardHelpers,determinePostReplaceSelection,- safariHacksDisabled,} from "discourse/lib/utilities";import { next, schedule } from "@ember/runloop";@@ -96,7 +95,7 @@ export default Mixin.create({this._$textarea.trigger("change");if (opts.scroll) {const oldScrollPos = this._$textarea.scrollTop();- if (!this.capabilities.isIOS || safariHacksDisabled()) {+ if (!this.capabilities.isIOS) {this._$textarea.focus();}this._$textarea.scrollTop(oldScrollPos);diff --git a/app/assets/javascripts/discourse/app/templates/preferences/interface.hbs b/app/assets/javascripts/discourse/app/templates/preferences/interface.hbsindex 4c07cafbdbf..ebe30a1ec57 100644--- a/app/assets/javascripts/discourse/app/templates/preferences/interface.hbs+++ b/app/assets/javascripts/discourse/app/templates/preferences/interface.hbs@@ -142,9 +142,6 @@{{#if siteSettings.allow_users_to_hide_profile}}{{preference-checkbox labelKey="user.hide_profile_and_presence" checked=model.user_option.hide_profile_and_presence class="pref-hide-profile"}}{{/if}}- {{#if isiPad}}- {{preference-checkbox labelKey="user.enable_physical_keyboard" checked=disableSafariHacks class="pref-safari-hacks"}}- {{/if}}{{preference-checkbox labelKey="user.dynamic_favicon" checked=model.user_option.dynamic_favicon class="pref-dynamic-favicon"}}<div class="controls controls-dropdown pref-page-title"><label for="user-title-count-mode">{{i18n "user.title_count_mode.title"}}</label>