Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll to top when tapping on the active tab. #247

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion src/navigation/card/components/CardDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {useFocusEffect, useNavigation} from '@react-navigation/native';
import {
useFocusEffect,
useNavigation,
useScrollToTop,
} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
import React, {useCallback, useLayoutEffect, useMemo} from 'react';
import {useRef, useState} from 'react';
Expand Down Expand Up @@ -360,6 +364,9 @@ const CardDashboard: React.FC<CardDashboardProps> = props => {
});
}

const flatListRef = useRef<FlatList>(null);
useScrollToTop(flatListRef);

return (
<>
<FlatList
Expand Down Expand Up @@ -419,6 +426,7 @@ const CardDashboard: React.FC<CardDashboardProps> = props => {
}
ListFooterComponent={listFooterComponent}
ListEmptyComponent={listEmptyComponent}
ref={flatListRef}
/>
<FloatingActionButtonContainer>
<FloatingActionButton
Expand Down
7 changes: 6 additions & 1 deletion src/navigation/card/components/CardIntro.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {StackNavigationProp} from '@react-navigation/stack';
import React, {useLayoutEffect} from 'react';
import React, {useLayoutEffect, useRef} from 'react';
import {useTranslation} from 'react-i18next';
import {ScrollView, View} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
Expand Down Expand Up @@ -28,6 +28,7 @@ import {CardStackParamList} from '../CardStack';
import CardFeatureTabs from './CardIntroFeatureTabs';
import CardIntroHeroImg from './CardIntroHeroImage';
import CardHighlights from './CardIntroHighlights';
import {useScrollToTop} from '@react-navigation/native';

interface CardIntroProps {
navigation: StackNavigationProp<CardStackParamList, 'CardHome'>;
Expand Down Expand Up @@ -94,9 +95,13 @@ const CardIntro: React.FC<CardIntroProps> = props => {
});
}, [navigation]);

const scrollViewRef = useRef<ScrollView>(null);
useScrollToTop(scrollViewRef);

return (
<>
<ScrollView
ref={scrollViewRef}
style={{
marginTop: insets.top,
}}>
Expand Down
12 changes: 10 additions & 2 deletions src/navigation/tabs/home/HomeRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import {useNavigation, useTheme} from '@react-navigation/native';
import React, {useEffect, useMemo, useState} from 'react';
import {
useNavigation,
useScrollToTop,
useTheme,
} from '@react-navigation/native';
import React, {useEffect, useMemo, useRef, useState} from 'react';
import {RefreshControl, ScrollView} from 'react-native';
import {STATIC_CONTENT_CARDS_ENABLED} from '../../../constants/config';
import {SupportedCurrencyOptions} from '../../../constants/SupportedCurrencyOptions';
Expand Down Expand Up @@ -183,10 +187,14 @@ const HomeRoot = () => {
}
}, [dispatch, keyMigrationFailure, keyMigrationFailureModalHasBeenShown]);

const scrollViewRef = useRef<ScrollView>(null);
useScrollToTop(scrollViewRef);

return (
<HomeContainer>
{appIsLoading ? null : (
<ScrollView
ref={scrollViewRef}
refreshControl={
<RefreshControl
tintColor={theme.dark ? White : SlateDark}
Expand Down
10 changes: 7 additions & 3 deletions src/navigation/tabs/settings/SettingsRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {StackScreenProps} from '@react-navigation/stack';
import React, {ReactElement, useMemo} from 'react';
import React, {ReactElement, useMemo, useRef} from 'react';
import {useTranslation} from 'react-i18next';
import {View, LayoutAnimation} from 'react-native';
import {View, LayoutAnimation, ScrollView} from 'react-native';
import styled from 'styled-components/native';
import AngleRight from '../../../../assets/img/angle-right.svg';
import Avatar from '../../../components/avatar/BitPayIdAvatar';
Expand Down Expand Up @@ -33,6 +33,7 @@ import {useSelector} from 'react-redux';
import Crypto from './components/Crypto';
import WalletsAndKeys from './components/WalletsAndKeys';
import {SettingsStackParamList} from './SettingsStack';
import {useScrollToTop} from '@react-navigation/native';

interface HomeSetting {
id: SettingsListType;
Expand Down Expand Up @@ -218,9 +219,12 @@ const SettingsHomeScreen: React.VFC<SettingsHomeProps> = ({route}) => {
);
}, [dispatch, memoizedSettingsConfigs, hideList]);

const scrollViewRef = useRef<ScrollView>(null);
useScrollToTop(scrollViewRef);

return (
<SettingsContainer>
<SettingsHome>
<SettingsHome ref={scrollViewRef}>
<BitPayIdSettingsLink
style={{paddingHorizontal: 15}}
onPress={() => {
Expand Down
4 changes: 3 additions & 1 deletion src/navigation/tabs/shop/ShopHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {useAppSelector} from '../../../utils/hooks';
import {StackScreenProps} from '@react-navigation/stack';
import {ShopScreens, ShopStackParamList} from './ShopStack';
import {useTranslation} from 'react-i18next';
import {useFocusEffect} from '@react-navigation/native';
import {useFocusEffect, useScrollToTop} from '@react-navigation/native';
import {logSegmentEvent} from '../../../store/app/app.effects';

export enum ShopTabs {
Expand Down Expand Up @@ -107,7 +107,9 @@ const ShopHome: React.FC<
[purchasedGiftCards],
);
const categoriesAndCurations = useAppSelector(selectCategoriesAndCurations);

const scrollViewRef = useRef<ScrollView>(null);
useScrollToTop(scrollViewRef);

const availableGiftCards = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useCallback, useEffect} from 'react';
import {useNavigation} from '@react-navigation/native';
import React, {useCallback, useEffect, useRef} from 'react';
import {useNavigation, useScrollToTop} from '@react-navigation/native';
import {StackScreenProps} from '@react-navigation/stack';
import {SectionContainer} from '../../components/styled/ShopTabComponents';
import {GiftCardScreens} from '../GiftCardStack';
Expand Down Expand Up @@ -57,12 +57,17 @@ const ArchivedGiftCards = ({
},
[navigator, supportedGiftCardMap],
);

const flatListRef = useRef<FlatList>(null);
useScrollToTop(flatListRef);

return (
<SectionContainer>
<FlatList
data={giftCards}
renderItem={renderItem}
keyExtractor={item => item.invoiceId}
ref={flatListRef}
/>
</SectionContainer>
);
Expand Down