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 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
cc2332a
Merge branch 'main' into fix/46611-re-create
nkdengineer Jan 9, 2025
1c55762
fix lint error
nkdengineer Jan 9, 2025
2e8c45d
remove height prop
nkdengineer Jan 13, 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
5 changes: 5 additions & 0 deletions assets/images/global-create.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,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;
12 changes: 9 additions & 3 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import HeaderWithBackButton from './HeaderWithBackButton';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import LoadingBar from './LoadingBar';
import MoneyReportHeaderStatusBar from './MoneyReportHeaderStatusBar';
import type {MoneyRequestHeaderStatusBarProps} from './MoneyRequestHeaderStatusBar';
import MoneyRequestHeaderStatusBar from './MoneyRequestHeaderStatusBar';
Expand Down Expand Up @@ -67,8 +68,8 @@
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {shouldUseNarrowLayout, isSmallScreenWidth} = useResponsiveLayout();
const route = useRoute();
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID ?? '-1'}`);

Check failure on line 71 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID ?? '-1'}`);

Check failure on line 72 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`);
const [session] = useOnyx(ONYXKEYS.SESSION);
const requestParentReportAction = useMemo(() => {
Expand All @@ -83,7 +84,7 @@
const transaction =
transactions?.[
`${ONYXKEYS.COLLECTION.TRANSACTION}${
ReportActionsUtils.isMoneyRequestAction(requestParentReportAction) ? ReportActionsUtils.getOriginalMessage(requestParentReportAction)?.IOUTransactionID ?? -1 : -1

Check failure on line 87 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

}`
] ?? undefined;

Expand All @@ -96,7 +97,7 @@
const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(moneyRequestReport);
const isOnHold = TransactionUtils.isOnHold(transaction);
const isDeletedParentAction = !!requestParentReportAction && ReportActionsUtils.isDeletedAction(requestParentReportAction);
const isDuplicate = TransactionUtils.isDuplicate(transaction?.transactionID ?? '');

Check failure on line 100 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check


// Only the requestor can delete the request, admins can only edit it.
const isActionOwner =
Expand All @@ -115,12 +116,12 @@
const hasScanningReceipt = ReportUtils.getTransactionsWithReceipts(moneyRequestReport?.reportID).some((t) => TransactionUtils.isReceiptBeingScanned(t));
const hasOnlyPendingTransactions = allTransactions.length > 0 && allTransactions.every((t) => TransactionUtils.isExpensifyCardTransaction(t) && TransactionUtils.isPending(t));
const transactionIDs = allTransactions.map((t) => t.transactionID);
const hasAllPendingRTERViolations = TransactionUtils.allHavePendingRTERViolation([transaction?.transactionID ?? '-1']);

Check failure on line 119 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const shouldShowBrokenConnectionViolation = TransactionUtils.shouldShowBrokenConnectionViolation(transaction?.transactionID ?? '-1', moneyRequestReport, policy);

Check failure on line 120 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const hasOnlyHeldExpenses = ReportUtils.hasOnlyHeldExpenses(moneyRequestReport?.reportID ?? '');

Check failure on line 121 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const isPayAtEndExpense = TransactionUtils.isPayAtEndExpense(transaction);
const isArchivedReport = ReportUtils.isArchivedRoomWithID(moneyRequestReport?.reportID);
const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport?.reportID ?? '-1'}`, {selector: ReportUtils.getArchiveReason});

Check failure on line 124 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check


const getCanIOUBePaid = useCallback(
(onlyShowPayElsewhere = false) => IOU.canIOUBePaid(moneyRequestReport, chatReport, policy, transaction ? [transaction] : undefined, onlyShowPayElsewhere),
Expand All @@ -132,7 +133,7 @@

const shouldShowMarkAsCashButton =
hasAllPendingRTERViolations ||
(shouldShowBrokenConnectionViolation && (!PolicyUtils.isPolicyAdmin(policy) || ReportUtils.isCurrentUserSubmitter(moneyRequestReport?.reportID ?? '')));

Check failure on line 136 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check


const shouldShowPayButton = canIOUBePaid || onlyShowPayElsewhere;

Expand Down Expand Up @@ -177,6 +178,7 @@
const isMoreContentShown = shouldShowNextStep || shouldShowStatusBar || (shouldShowAnyButton && shouldUseNarrowLayout);
const {isDelegateAccessRestricted} = useDelegateUserDetails();
const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false);
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA);

const isReportInRHP = route.name === SCREENS.SEARCH.REPORT_RHP;
const shouldDisplaySearchRouter = !isReportInRHP || isSmallScreenWidth;
Expand Down Expand Up @@ -215,7 +217,7 @@
const deleteTransaction = useCallback(() => {
if (requestParentReportAction) {
const iouTransactionID = ReportActionsUtils.isMoneyRequestAction(requestParentReportAction)
? ReportActionsUtils.getOriginalMessage(requestParentReportAction)?.IOUTransactionID ?? '-1'

Check failure on line 220 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

: '-1';
if (ReportActionsUtils.isTrackExpenseAction(requestParentReportAction)) {
navigateBackToAfterDelete.current = IOU.deleteTrackExpense(moneyRequestReport?.reportID ?? '-1', iouTransactionID, requestParentReportAction, true);
Expand Down Expand Up @@ -334,7 +336,7 @@
}, [canDeleteRequest]);

return (
<View style={[styles.pt0]}>
<View style={[styles.pt0, styles.borderBottom]}>
<HeaderWithBackButton
shouldShowReportAvatarWithDisplay
shouldEnableDetailPageNavigation
Expand All @@ -345,7 +347,7 @@
shouldDisplaySearchRouter={shouldDisplaySearchRouter}
onBackButtonPress={onBackButtonPress}
// Shows border if no buttons or banners are showing below the header
shouldShowBorderBottom={!isMoreContentShown}
shouldShowBorderBottom={false}
>
{isDuplicate && !shouldUseNarrowLayout && (
<View style={[shouldDuplicateButtonBeSuccess ? styles.ml2 : styles.mh2]}>
Expand Down Expand Up @@ -414,7 +416,7 @@
)}
</HeaderWithBackButton>
{!!isMoreContentShown && (
<View style={[styles.dFlex, styles.flexColumn, shouldAddGapToContents && styles.gap3, styles.pb3, styles.ph5, styles.borderBottom]}>
<View style={[styles.dFlex, styles.flexColumn, shouldAddGapToContents && styles.gap3, styles.pb3, styles.ph5]}>
<View style={[styles.dFlex, styles.w100, styles.flexRow, styles.gap3]}>
{isDuplicate && shouldUseNarrowLayout && (
<Button
Expand Down Expand Up @@ -481,6 +483,10 @@
)}
</View>
)}
<LoadingBar
shouldShow={(isLoadingReportData && shouldUseNarrowLayout) ?? false}
height={1}

Check failure on line 488 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Type '{ shouldShow: boolean; height: number; }' is not assignable to type 'IntrinsicAttributes & LoadingBarProps'.
/>
{isHoldMenuVisible && requestType !== undefined && (
<ProcessMoneyReportHoldMenu
nonHeldAmount={!hasOnlyHeldExpenses && hasValidNonHeldAmount ? nonHeldAmount : undefined}
Expand Down
9 changes: 6 additions & 3 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Button from './Button';
import HeaderWithBackButton from './HeaderWithBackButton';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import LoadingBar from './LoadingBar';
import type {MoneyRequestHeaderStatusBarProps} from './MoneyRequestHeaderStatusBar';
import MoneyRequestHeaderStatusBar from './MoneyRequestHeaderStatusBar';
import ProcessMoneyRequestHoldMenu from './ProcessMoneyRequestHoldMenu';
Expand Down Expand Up @@ -58,6 +59,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
);
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {initialValue: true});
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA);
const isLoadingHoldUseExplained = isLoadingOnyxValue(dismissedHoldUseExplanationResult);
const styles = useThemeStyles();
const theme = useTheme();
Expand Down Expand Up @@ -149,9 +151,9 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre

return (
<>
<View style={[styles.pl0]}>
<View style={[styles.pl0, styles.borderBottom]}>
<HeaderWithBackButton
shouldShowBorderBottom={!statusBarProps && !isOnHold}
shouldShowBorderBottom={false}
shouldShowReportAvatarWithDisplay
shouldEnableDetailPageNavigation
shouldShowPinButton={false}
Expand Down Expand Up @@ -207,13 +209,14 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
</View>
)}
{!!statusBarProps && (
<View style={[styles.ph5, styles.pb3, styles.borderBottom]}>
<View style={[styles.ph5, styles.pb3]}>
<MoneyRequestHeaderStatusBar
icon={statusBarProps.icon}
description={statusBarProps.description}
/>
</View>
)}
<LoadingBar shouldShow={(isLoadingReportData && shouldUseNarrowLayout) ?? false} />
</View>
{isSmallScreenWidth && shouldShowHoldMenu && (
<ProcessMoneyRequestHoldMenu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Breadcrumbs from '@components/Breadcrumbs';
import LoadingBar from '@components/LoadingBar';
import {PressableWithoutFeedback} from '@components/Pressable';
import SearchButton from '@components/Search/SearchRouter/SearchButton';
import Text from '@components/Text';
Expand Down Expand Up @@ -29,6 +30,7 @@ function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true,
const {translate} = useLocalize();
const policy = usePolicy(activeWorkspaceID);
const [session] = useOnyx(ONYXKEYS.SESSION, {selector: (sessionValue) => sessionValue && {authTokenType: sessionValue.authTokenType}});
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA);
const isAnonymousUser = Session.isAnonymousUser(session);

const headerBreadcrumb = policy?.name
Expand Down Expand Up @@ -74,6 +76,7 @@ function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true,
)}
{displaySearch && <SearchButton />}
</View>
<LoadingBar shouldShow={isLoadingReportData ?? false} />
</View>
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/pages/home/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import DisplayNames from '@components/DisplayNames';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import {FallbackAvatar} from '@components/Icon/Expensicons';
import LoadingBar from '@components/LoadingBar';
import MultipleAvatars from '@components/MultipleAvatars';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import ParentNavigationSubtitle from '@components/ParentNavigationSubtitle';
Expand Down Expand Up @@ -77,6 +78,7 @@ function HeaderView({report, parentReportAction, reportID, onNavigationMenuButto
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID || report?.reportID || CONST.DEFAULT_NUMBER_ID}`);
const policy = usePolicy(report?.policyID);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA);

const {translate} = useLocalize();
const theme = useTheme();
Expand Down Expand Up @@ -323,6 +325,7 @@ function HeaderView({report, parentReportAction, reportID, onNavigationMenuButto
</View>
</View>
)}
<LoadingBar shouldShow={(isLoadingReportData && shouldUseNarrowLayout) ?? false} />
</View>
);
}
Expand Down
1 change: 0 additions & 1 deletion src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
const finishedLoadingApp = wasLoadingApp && !isLoadingApp;
const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(parentReportAction);
const prevIsDeletedParentAction = usePrevious(isDeletedParentAction);

const isLoadingReportOnyx = isLoadingOnyxValue(reportResult);
const permissions = useDeepCompareRef(reportOnyx?.permissions);

Expand Down
14 changes: 14 additions & 0 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5339,6 +5339,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