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

feature: Add loading indicator when ReconnectApp is running #52272

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1c3c035
feature: Add loading indicator when ReconnectApp is running
nkdengineer Nov 8, 2024
c8f048a
fix lint
nkdengineer Nov 8, 2024
c69bf57
Merge branch 'main' into fix/46611-re-create
nkdengineer Nov 12, 2024
a3dcad3
remove isVisible shared value
nkdengineer Nov 12, 2024
7bc1067
Merge branch 'main' into fix/46611-re-create
nkdengineer Nov 12, 2024
b88bc5d
Merge branch 'main' into fix/46611-re-create
nkdengineer Nov 27, 2024
0309518
resolve conflict
nkdengineer Nov 28, 2024
cd37b51
fix lint
nkdengineer Nov 28, 2024
7e16699
fix border radius
nkdengineer Nov 28, 2024
2d79dbc
merge main
nkdengineer Nov 29, 2024
4015f65
fix loading bar animation doesn't work
nkdengineer Nov 29, 2024
683e2c3
Update src/pages/home/ReportScreen.tsx
nkdengineer Dec 5, 2024
3b0e568
Merge branch 'main' into fix/46611-re-create
nkdengineer Dec 10, 2024
bf4660c
remove initial value
nkdengineer Dec 10, 2024
88e2618
Merge branch 'main' into fix/46611-re-create
nkdengineer Dec 13, 2024
117d8c0
Merge branch 'main' into fix/46611-re-create
nkdengineer Dec 17, 2024
8168260
Merge branch 'main' into fix/46611-re-create
nkdengineer Dec 18, 2024
bb2b538
move the loading bar to TopBar and HeaderView
nkdengineer Dec 18, 2024
2e423e7
Merge branch 'main' into fix/46611-re-create
nkdengineer Dec 18, 2024
6da8491
fix bug
nkdengineer Dec 18, 2024
6b0babc
merge main
nkdengineer Dec 20, 2024
fce28c5
update loading bar height to 1px
nkdengineer Dec 20, 2024
975d001
merge main
nkdengineer Dec 25, 2024
b413d4b
merge main
nkdengineer Dec 30, 2024
af12eae
Merge branch 'main' into fix/46611-re-create
nkdengineer Jan 6, 2025
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
3 changes: 3 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ const CONST = {
ANIMATED_HIGHLIGHT_END_DURATION: 2000,
ANIMATED_TRANSITION: 300,
ANIMATED_TRANSITION_FROM_VALUE: 100,
ANIMATED_PROGRESS_BAR_DELAY: 300,
ANIMATED_PROGRESS_BAR_OPACITY_DURATION: 300,
ANIMATED_PROGRESS_BAR_DURATION: 750,
ANIMATION_IN_TIMING: 100,
ANIMATION_DIRECTION: {
IN: 'in',
Expand Down
83 changes: 83 additions & 0 deletions src/components/LoadingBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React, {useEffect} from 'react';
import Animated, {cancelAnimation, Easing, useAnimatedStyle, useSharedValue, withDelay, withRepeat, withSequence, withTiming} from 'react-native-reanimated';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';

type LoadingBarProps = {
// Whether or not to show the loading bar
shouldShow: boolean;
};

function LoadingBar({shouldShow}: LoadingBarProps) {
const left = useSharedValue(0);
const width = useSharedValue(0);
const opacity = useSharedValue(0);
const styles = useThemeStyles();

useEffect(() => {
if (shouldShow) {
// eslint-disable-next-line react-compiler/react-compiler
left.set(0);
width.set(0);
opacity.set(withTiming(1, {duration: CONST.ANIMATED_PROGRESS_BAR_OPACITY_DURATION}));

left.set(
withDelay(
CONST.ANIMATED_PROGRESS_BAR_DELAY,
withRepeat(
withSequence(
withTiming(0, {duration: 0}),
withTiming(0, {duration: CONST.ANIMATED_PROGRESS_BAR_DURATION, easing: Easing.bezier(0.65, 0, 0.35, 1)}),
withTiming(100, {duration: CONST.ANIMATED_PROGRESS_BAR_DURATION, easing: Easing.bezier(0.65, 0, 0.35, 1)}),
),
-1,
false,
),
),
);

width.set(
withDelay(
CONST.ANIMATED_PROGRESS_BAR_DELAY,
withRepeat(
withSequence(
withTiming(0, {duration: 0}),
withTiming(100, {duration: CONST.ANIMATED_PROGRESS_BAR_DURATION, easing: Easing.bezier(0.65, 0, 0.35, 1)}),
withTiming(0, {duration: CONST.ANIMATED_PROGRESS_BAR_DURATION, easing: Easing.bezier(0.65, 0, 0.35, 1)}),
),
-1,
false,
),
),
);
} else {
opacity.set(
withTiming(0, {duration: CONST.ANIMATED_PROGRESS_BAR_OPACITY_DURATION}, () => {
cancelAnimation(left);
cancelAnimation(width);
}),
);
}
// we want to update only when shouldShow changes
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [shouldShow]);

const animatedIndicatorStyle = useAnimatedStyle(() => ({
left: `${left.get()}%`,
width: `${width.get()}%`,
}));

const animatedContainerStyle = useAnimatedStyle(() => ({
opacity: opacity.get(),
}));

return (
<Animated.View style={[styles.progressBarWrapper, animatedContainerStyle]}>
<Animated.View style={[styles.progressBar, animatedIndicatorStyle]} />
</Animated.View>
);
}

LoadingBar.displayName = 'ProgressBar';

export default LoadingBar;
4 changes: 3 additions & 1 deletion src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Banner from '@components/Banner';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import DragAndDropProvider from '@components/DragAndDrop/Provider';
import * as Expensicons from '@components/Icon/Expensicons';
import LoadingBar from '@components/LoadingBar';
import MoneyReportHeader from '@components/MoneyReportHeader';
import MoneyRequestHeader from '@components/MoneyRequestHeader';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
Expand Down Expand Up @@ -135,7 +136,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
const finishedLoadingApp = wasLoadingApp && !isLoadingApp;
const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(parentReportAction);
const prevIsDeletedParentAction = usePrevious(isDeletedParentAction);

const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {initialValue: true});
const isLoadingReportOnyx = isLoadingOnyxValue(reportResult);
const permissions = useDeepCompareRef(reportOnyx?.permissions);

Expand Down Expand Up @@ -768,6 +769,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
needsOffscreenAlphaCompositing
>
{headerView}
{shouldUseNarrowLayout && !!isLoadingReportData && <LoadingBar shouldShow={!!isLoadingReportData} />}
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
{!!report && ReportUtils.isTaskReport(report) && shouldUseNarrowLayout && ReportUtils.isOpenTaskReport(report, parentReportAction) && (
<View style={[styles.borderBottom]}>
<View style={[styles.appBG, styles.pl0]}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useEffect} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import LoadingBar from '@components/LoadingBar';
import ScreenWrapper from '@components/ScreenWrapper';
import useActiveWorkspaceFromNavigationState from '@hooks/useActiveWorkspaceFromNavigationState';
import useLocalize from '@hooks/useLocalize';
Expand All @@ -22,7 +23,7 @@ function BaseSidebarScreen() {
const {translate} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const [activeWorkspace] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`);

const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {initialValue: true});
useEffect(() => {
Performance.markStart(CONST.TIMING.SIDEBAR_LOADED);
Timing.start(CONST.TIMING.SIDEBAR_LOADED);
Expand Down Expand Up @@ -54,6 +55,7 @@ function BaseSidebarScreen() {
activeWorkspaceID={activeWorkspaceID}
shouldDisplaySearch={shouldDisplaySearch}
/>
<LoadingBar shouldShow={isLoadingReportData ?? false} />
<View style={[styles.flex1]}>
<SidebarLinksData insets={insets} />
</View>
Expand Down
14 changes: 14 additions & 0 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5321,6 +5321,20 @@ const styles = (theme: ThemeColors) =>
width: variables.sideBarWidth - 19,
},

progressBarWrapper: {
height: 2,
width: '100%',
backgroundColor: theme.border,
borderRadius: 2,
overflow: 'hidden',
},

progressBar: {
height: '100%',
backgroundColor: theme.success,
width: '100%',
},

accountSwitcherAnchorPosition: {
top: 80,
left: 12,
Expand Down
Loading