From d96a528ac08b1bc77be30dfff7f0395f8b5d3701 Mon Sep 17 00:00:00 2001 From: Sunny Hirai Date: Tue, 9 Jan 2018 13:07:40 -0800 Subject: [PATCH 1/3] Fixed scroll-to-selection jumping to top on iOS --- packages/slate-react/src/utils/scroll-to-selection.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/slate-react/src/utils/scroll-to-selection.js b/packages/slate-react/src/utils/scroll-to-selection.js index 6e621d889..a35db0307 100644 --- a/packages/slate-react/src/utils/scroll-to-selection.js +++ b/packages/slate-react/src/utils/scroll-to-selection.js @@ -1,7 +1,7 @@ import getWindow from 'get-window' import isBackward from 'selection-is-backward' -import { IS_SAFARI } from '../constants/environment' +import { IS_SAFARI, IS_IOS } from '../constants/environment' /** * CSS overflow values that would cause scrolling. @@ -58,6 +58,7 @@ function findScrollContainer(el, window) { */ function scrollToSelection(selection) { + if (IS_IOS) return if (!selection.anchorNode) return const window = getWindow(selection.anchorNode) From 7dee55d06699df88db907ca580e34ae8c22f1d2b Mon Sep 17 00:00:00 2001 From: Sunny Hirai Date: Wed, 10 Jan 2018 16:57:39 -0800 Subject: [PATCH 2/3] Updated scroll-to-selection to abort only if on iOS 11 --- .../src/utils/scroll-to-selection.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/slate-react/src/utils/scroll-to-selection.js b/packages/slate-react/src/utils/scroll-to-selection.js index a35db0307..f5fc16382 100644 --- a/packages/slate-react/src/utils/scroll-to-selection.js +++ b/packages/slate-react/src/utils/scroll-to-selection.js @@ -51,6 +51,19 @@ function findScrollContainer(el, window) { return scroller } +/** + * Get the current iOS version. Assumes that an IOS check was conducted + * prior to calling. + */ + +const IOS_VERSION_REGEX = /OS (\d+)_/ + +function getMajorIOSVersion() { + const { userAgent } = window.navigator + const matches = userAgent.match(IOS_VERSION_REGEX) + return matches ? parseInt(matches[1]) : null +} + /** * Scroll the current selection's focus point into view if needed. * @@ -58,7 +71,11 @@ function findScrollContainer(el, window) { */ function scrollToSelection(selection) { - if (IS_IOS) return + if (IS_IOS) { + const majorIOSVersion = getMajorIOSVersion() + if (majorIOSVersion && majorIOSVersion == 11) return + } + if (!selection.anchorNode) return const window = getWindow(selection.anchorNode) From 3d86533b5bb9a4b3d39a641bacf83dd829e42f7d Mon Sep 17 00:00:00 2001 From: Sunny Hirai Date: Thu, 11 Jan 2018 10:06:41 -0800 Subject: [PATCH 3/3] Updated scroll-to-selection so it skips the scroll only on version 11 of iOS. --- .../src/utils/scroll-to-selection.js | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/packages/slate-react/src/utils/scroll-to-selection.js b/packages/slate-react/src/utils/scroll-to-selection.js index f5fc16382..0825862e3 100644 --- a/packages/slate-react/src/utils/scroll-to-selection.js +++ b/packages/slate-react/src/utils/scroll-to-selection.js @@ -15,6 +15,12 @@ const OVERFLOWS = [ 'scroll', ] +/** + * Detect whether we are running IOS version 11 + */ + +const IS_IOS_11 = IS_IOS && !!window.navigator.userAgent.match(/os 11_/i) + /** * Find the nearest parent with scrolling, or window. * @@ -51,19 +57,6 @@ function findScrollContainer(el, window) { return scroller } -/** - * Get the current iOS version. Assumes that an IOS check was conducted - * prior to calling. - */ - -const IOS_VERSION_REGEX = /OS (\d+)_/ - -function getMajorIOSVersion() { - const { userAgent } = window.navigator - const matches = userAgent.match(IOS_VERSION_REGEX) - return matches ? parseInt(matches[1]) : null -} - /** * Scroll the current selection's focus point into view if needed. * @@ -71,11 +64,7 @@ function getMajorIOSVersion() { */ function scrollToSelection(selection) { - if (IS_IOS) { - const majorIOSVersion = getMajorIOSVersion() - if (majorIOSVersion && majorIOSVersion == 11) return - } - + if (IS_IOS_11) return if (!selection.anchorNode) return const window = getWindow(selection.anchorNode)