From 2d165e1ecd3b32581a0b31f6eba9c42425f738df Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Wed, 26 Oct 2016 21:13:06 -0500 Subject: [PATCH] fix(scroll): fix scroll to top on iOS --- src/util/events.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/util/events.ts b/src/util/events.ts index 72f5f06bf9..5c01fa1fec 100644 --- a/src/util/events.ts +++ b/src/util/events.ts @@ -1,4 +1,4 @@ -import { nativeTimeout } from '../util/dom'; +import { nativeTimeout, nativeRaf } from '../util/dom'; import { Platform } from '../platform/platform'; import { ScrollView } from '../util/scroll-view'; @@ -135,7 +135,29 @@ export function setupEvents(platform: Platform): Events { let content = el.closest('.scroll-content'); if (content) { var scroll = new ScrollView(content); - scroll.scrollTo(0, 0, 300); + // We need to stop scrolling if it's happening and scroll up + + content.style['WebkitBackfaceVisibility'] = 'hidden'; + content.style['WebkitTransform'] = 'translate3d(0,0,0)'; + + nativeRaf(function() { + content.style.overflow = 'hidden'; + + function finish() { + content.style.overflow = ''; + content.style['WebkitBackfaceVisibility'] = ''; + content.style['WebkitTransform'] = ''; + } + + let didScrollTimeout = setTimeout(() => { + finish(); + }, 400); + + scroll.scrollTo(0, 0, 300).then(() => { + clearTimeout(didScrollTimeout); + finish(); + }); + }); } });