DEV: Drop non-visualViewport Safari hacks (#15007)
Those were required pre-iOS 13.
This commit is contained in:
parent
b1844c45c3
commit
cabacb5c48
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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/29064810
|
||||
function 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;
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue