Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Oct 17, 2023
1 parent bf5c8e2 commit be107b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export const isRTLDocument = /*#__PURE__*/ once((): boolean => {

// Currently, all browsers on iOS/iPadOS are WebKit, including WebView.
export const isIOSWebKit = /*#__PURE__*/ once((): boolean => {
return isBrowser ? /iP(hone|od|ad)/.test(navigator.userAgent) : false;
return /iP(hone|od|ad)/.test(navigator.userAgent);
});
8 changes: 3 additions & 5 deletions src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ export const createVirtualStore = (
let _maybeJumped = false;
let _prevRange: ItemsRange = [0, initialItemCount];

// In iOS WebKit browsers, updating scroll position will stop scrolling so it have to be deferred during scrolling.
const shouldDeferJump = isIOSWebKit();

const subscribers = new Set<[number, Subscriber]>();
const getScrollSize = (): number =>
computeTotalSize(cache as Writeable<Cache>);
Expand All @@ -121,7 +118,8 @@ export const createVirtualStore = (
return clamp(value, 0, getScrollOffsetMax());
};
const applyJump = (j: ScrollJump) => {
if (shouldDeferJump && _scrollDirection !== SCROLL_IDLE) {
// In iOS WebKit browsers, updating scroll position will stop scrolling so it have to be deferred during scrolling.
if (isIOSWebKit() && _scrollDirection !== SCROLL_IDLE) {
pendingJump += j;
} else {
jump += j;
Expand Down Expand Up @@ -283,7 +281,7 @@ export const createVirtualStore = (
);
const diff = isRemove ? -min(shift, distanceToEnd) : shift;
applyJump(diff);
if (!shouldDeferJump) {
if (!isIOSWebKit()) {
scrollOffset = clampScrollOffset(scrollOffset + diff);
}

Expand Down

0 comments on commit be107b5

Please sign in to comment.