Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/pages/settings/InitialSettingsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useRoute} from '@react-navigation/native';
import React, {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import React, {useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react';
// eslint-disable-next-line no-restricted-imports
import type {GestureResponderEvent, ScrollView as RNScrollView, ScrollViewProps, StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
Expand Down Expand Up @@ -461,19 +461,14 @@ function InitialSettingsPage({session, userWallet, bankAccountList, fundList, wa
[route, saveScrollOffset],
);

const [isAfterOnLayout, setIsAfterOnLayout] = useState(false);

const onLayout = useCallback(() => {
useLayoutEffect(() => {
const scrollOffset = getScrollOffset(route);
setIsAfterOnLayout(true);
if (!scrollOffset || !scrollViewRef.current) {
return;
}
scrollViewRef.current.scrollTo({y: scrollOffset, animated: false});
}, [getScrollOffset, route]);

const scrollOffset = getScrollOffset(route);

return (
<ScreenWrapper
style={[styles.w100, styles.pb0]}
Expand All @@ -483,11 +478,8 @@ function InitialSettingsPage({session, userWallet, bankAccountList, fundList, wa
>
<ScrollView
ref={scrollViewRef}
onLayout={onLayout}
onScroll={onScroll}
scrollEventThrottle={16}
// We use marginTop to prevent glitching on the initial frame that renders before scrollTo.
contentContainerStyle={[!isAfterOnLayout && !!scrollOffset && {marginTop: -scrollOffset}]}
style={[styles.w100, styles.pt4]}
>
{headerContent}
Expand Down