Skip to content

Commit 2d165e1

Browse files
committed
fix(scroll): fix scroll to top on iOS
1 parent c1ba120 commit 2d165e1

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/util/events.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { nativeTimeout } from '../util/dom';
1+
import { nativeTimeout, nativeRaf } from '../util/dom';
22
import { Platform } from '../platform/platform';
33
import { ScrollView } from '../util/scroll-view';
44

@@ -135,7 +135,29 @@ export function setupEvents(platform: Platform): Events {
135135
let content = <HTMLElement>el.closest('.scroll-content');
136136
if (content) {
137137
var scroll = new ScrollView(content);
138-
scroll.scrollTo(0, 0, 300);
138+
// We need to stop scrolling if it's happening and scroll up
139+
140+
content.style['WebkitBackfaceVisibility'] = 'hidden';
141+
content.style['WebkitTransform'] = 'translate3d(0,0,0)';
142+
143+
nativeRaf(function() {
144+
content.style.overflow = 'hidden';
145+
146+
function finish() {
147+
content.style.overflow = '';
148+
content.style['WebkitBackfaceVisibility'] = '';
149+
content.style['WebkitTransform'] = '';
150+
}
151+
152+
let didScrollTimeout = setTimeout(() => {
153+
finish();
154+
}, 400);
155+
156+
scroll.scrollTo(0, 0, 300).then(() => {
157+
clearTimeout(didScrollTimeout);
158+
finish();
159+
});
160+
});
139161
}
140162
});
141163

0 commit comments

Comments
 (0)