Skip to content

Commit

Permalink
Merge pull request #39297 from dragnoir/30360-fix-02
Browse files Browse the repository at this point in the history
Fix: grey line SpacerView same padding as green line UnreadActionIndicator
  • Loading branch information
Beamanator authored May 1, 2024
2 parents c4a1c59 + ca6e3c4 commit a7db226
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 54 deletions.
10 changes: 1 addition & 9 deletions src/components/ReportActionItem/MoneyReportView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import SpacerView from '@components/SpacerView';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
Expand All @@ -29,12 +28,9 @@ type MoneyReportViewProps = {

/** Policy that the report belongs to */
policy: OnyxEntry<Policy>;

/** Whether we should display the horizontal rule below the component */
shouldShowHorizontalRule: boolean;
};

function MoneyReportView({report, policy, shouldShowHorizontalRule}: MoneyReportViewProps) {
function MoneyReportView({report, policy}: MoneyReportViewProps) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down Expand Up @@ -168,10 +164,6 @@ function MoneyReportView({report, policy, shouldShowHorizontalRule}: MoneyReport
</View>
</>
)}
<SpacerView
shouldShow={shouldShowHorizontalRule}
style={[shouldShowHorizontalRule && styles.reportHorizontalRule]}
/>
</>
)}
</View>
Expand Down
9 changes: 0 additions & 9 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {useSession} from '@components/OnyxProvider';
import {ReceiptAuditHeader, ReceiptAuditMessages} from '@components/ReceiptAudit';
import ReceiptEmptyState from '@components/ReceiptEmptyState';
import SpacerView from '@components/SpacerView';
import Switch from '@components/Switch';
import Text from '@components/Text';
import ViolationMessages from '@components/ViolationMessages';
Expand Down Expand Up @@ -77,9 +76,6 @@ type MoneyRequestViewPropsWithoutTransaction = MoneyRequestViewOnyxPropsWithoutT
/** The report currently being looked at */
report: OnyxTypes.Report;

/** Whether we should display the horizontal rule below the component */
shouldShowHorizontalRule: boolean;

/** Whether we should display the animated banner above the component */
shouldShowAnimatedBackground: boolean;
};
Expand All @@ -91,7 +87,6 @@ function MoneyRequestView({
parentReport,
parentReportActions,
policyCategories,
shouldShowHorizontalRule,
transaction,
policyTagList,
policy,
Expand Down Expand Up @@ -566,10 +561,6 @@ function MoneyRequestView({
</View>
)}
</View>
<SpacerView
shouldShow={shouldShowHorizontalRule}
style={[shouldShowHorizontalRule ? styles.reportHorizontalRule : {}]}
/>
</View>
);
}
Expand Down
10 changes: 1 addition & 9 deletions src/components/ReportActionItem/TaskView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {usePersonalDetails} from '@components/OnyxProvider';
import PressableWithSecondaryInteraction from '@components/PressableWithSecondaryInteraction';
import SpacerView from '@components/SpacerView';
import Text from '@components/Text';
import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails';
import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails';
Expand Down Expand Up @@ -40,12 +39,9 @@ type TaskViewProps = TaskViewOnyxProps &
WithCurrentUserPersonalDetailsProps & {
/** The report currently being looked at */
report: Report;

/** Whether we should display the horizontal rule below the component */
shouldShowHorizontalRule: boolean;
};

function TaskView({report, shouldShowHorizontalRule, ...props}: TaskViewProps) {
function TaskView({report, ...props}: TaskViewProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
useEffect(() => {
Expand Down Expand Up @@ -185,10 +181,6 @@ function TaskView({report, shouldShowHorizontalRule, ...props}: TaskViewProps) {
)}
</OfflineWithFeedback>
</OfflineWithFeedback>
<SpacerView
shouldShow={shouldShowHorizontalRule}
style={shouldShowHorizontalRule && styles.reportHorizontalRule}
/>
</View>
);
}
Expand Down
10 changes: 8 additions & 2 deletions src/components/UnreadActionIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@ import CONST from '@src/CONST';
import Text from './Text';

type UnreadActionIndicatorProps = {
/** The ID of the report action */
reportActionID: string;

/** Whether we should hide thread divider line */
shouldHideThreadDividerLine?: boolean;
};

function UnreadActionIndicator({reportActionID}: UnreadActionIndicatorProps) {
function UnreadActionIndicator({reportActionID, shouldHideThreadDividerLine}: UnreadActionIndicatorProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();

const containerStyle = shouldHideThreadDividerLine ? styles.topUnreadIndicatorContainer : styles.unreadIndicatorContainer;

return (
<View
accessibilityLabel={translate('accessibilityHints.newMessageLineIndicator')}
data-action-id={reportActionID}
style={[styles.unreadIndicatorContainer, styles.userSelectNone, styles.pointerEventsNone]}
style={[containerStyle, styles.userSelectNone, styles.pointerEventsNone]}
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
>
<View style={styles.unreadIndicatorLine} />
Expand Down
81 changes: 56 additions & 25 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import TaskAction from '@components/ReportActionItem/TaskAction';
import TaskPreview from '@components/ReportActionItem/TaskPreview';
import TaskView from '@components/ReportActionItem/TaskView';
import {ShowContextMenuContext} from '@components/ShowContextMenuContext';
import SpacerView from '@components/SpacerView';
import Text from '@components/Text';
import UnreadActionIndicator from '@components/UnreadActionIndicator';
import useLocalize from '@hooks/useLocalize';
Expand Down Expand Up @@ -151,6 +152,12 @@ type ReportActionItemProps = {

/** Callback to be called on onPress */
onPress?: () => void;

/** If this is the first visible report action */
isFirstVisibleReportAction: boolean;

/** IF the thread divider line will be used */
shouldUseThreadDividerLine?: boolean;
} & ReportActionItemOnyxProps;

const isIOUReport = (actionObj: OnyxEntry<OnyxTypes.ReportAction>): actionObj is OnyxTypes.ReportActionBase & OnyxTypes.OriginalMessageIOU =>
Expand All @@ -175,6 +182,8 @@ function ReportActionItem({
policy,
transaction,
onPress = undefined,
isFirstVisibleReportAction = false,
shouldUseThreadDividerLine = false,
}: ReportActionItemProps) {
const {translate} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
Expand Down Expand Up @@ -460,6 +469,22 @@ function ReportActionItem({
];
}, [action, report.reportID]);

const renderThreadDivider = useMemo(
() =>
shouldHideThreadDividerLine ? (
<UnreadActionIndicator
reportActionID={report.reportID}
shouldHideThreadDividerLine={shouldHideThreadDividerLine}
/>
) : (
<SpacerView
shouldShow={!shouldHideThreadDividerLine}
style={[!shouldHideThreadDividerLine ? styles.reportHorizontalRule : {}]}
/>
),
[shouldHideThreadDividerLine, styles.reportHorizontalRule, report.reportID],
);

/**
* Get the content of ReportActionItem
* @param hovered whether the ReportActionItem is hovered
Expand Down Expand Up @@ -765,11 +790,13 @@ function ReportActionItem({
}
return (
<ShowContextMenuContext.Provider value={contextValue}>
<MoneyRequestView
report={report}
shouldShowHorizontalRule={!shouldHideThreadDividerLine}
shouldShowAnimatedBackground
/>
<View>
<MoneyRequestView
report={report}
shouldShowAnimatedBackground
/>
{renderThreadDivider}
</View>
</ShowContextMenuContext.Provider>
);
}
Expand Down Expand Up @@ -797,10 +824,8 @@ function ReportActionItem({
<View>
<AnimatedEmptyStateBackground />
<View style={[StyleUtils.getReportWelcomeTopMarginStyle(isSmallScreenWidth)]}>
<TaskView
report={report}
shouldShowHorizontalRule={!shouldHideThreadDividerLine}
/>
<TaskView report={report} />
{renderThreadDivider}
</View>
</View>
);
Expand All @@ -811,26 +836,32 @@ function ReportActionItem({
{transactionThreadReport && !isEmptyObject(transactionThreadReport) ? (
<>
{transactionCurrency !== report.currency && (
<MoneyReportView
report={report}
policy={policy}
shouldShowHorizontalRule={!shouldHideThreadDividerLine}
/>
<>
<MoneyReportView
report={report}
policy={policy}
/>
{renderThreadDivider}
</>
)}
<ShowContextMenuContext.Provider value={contextValue}>
<MoneyRequestView
report={transactionThreadReport}
shouldShowHorizontalRule={!shouldHideThreadDividerLine}
shouldShowAnimatedBackground={transactionCurrency === report.currency}
/>
<View>
<MoneyRequestView
report={transactionThreadReport}
shouldShowAnimatedBackground={transactionCurrency === report.currency}
/>
{renderThreadDivider}
</View>
</ShowContextMenuContext.Provider>
</>
) : (
<MoneyReportView
report={report}
policy={policy}
shouldShowHorizontalRule={!shouldHideThreadDividerLine}
/>
<>
<MoneyReportView
report={report}
policy={policy}
/>
{renderThreadDivider}
</>
)}
</OfflineWithFeedback>
);
Expand Down Expand Up @@ -907,7 +938,7 @@ function ReportActionItem({
>
{(hovered) => (
<View style={highlightedBackgroundColorIfNeeded}>
{shouldDisplayNewMarker && <UnreadActionIndicator reportActionID={action.reportActionID} />}
{shouldDisplayNewMarker && (!shouldUseThreadDividerLine || !isFirstVisibleReportAction) && <UnreadActionIndicator reportActionID={action.reportActionID} />}
<MiniReportActionContextMenu
reportID={report.reportID}
reportActionID={action.reportActionID}
Expand Down
10 changes: 10 additions & 0 deletions src/pages/home/report/ReportActionItemParentAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ type ReportActionItemParentActionProps = {

/** Whether we should display "Replies" divider */
shouldDisplayReplyDivider: boolean;

/** If this is the first visible report action */
isFirstVisibleReportAction: boolean;

/** If the thread divider line will be used */
shouldUseThreadDividerLine?: boolean;
};

function ReportActionItemParentAction({
Expand All @@ -54,6 +60,8 @@ function ReportActionItemParentAction({
index = 0,
shouldHideThreadDividerLine = false,
shouldDisplayReplyDivider,
isFirstVisibleReportAction = false,
shouldUseThreadDividerLine = false,
}: ReportActionItemParentActionProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down Expand Up @@ -124,6 +132,8 @@ function ReportActionItemParentAction({
isMostRecentIOUReportAction={false}
shouldDisplayNewMarker={ancestor.shouldDisplayNewMarker}
index={index}
isFirstVisibleReportAction={isFirstVisibleReportAction}
shouldUseThreadDividerLine={shouldUseThreadDividerLine}
/>
</OfflineWithFeedback>
))}
Expand Down
24 changes: 24 additions & 0 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ function ReportActionsList({
[sortedReportActions, isOffline, currentUnreadMarker],
);

const firstVisibleReportActionID = useMemo(() => ReportActionsUtils.getFirstVisibleReportActionID(sortedReportActions, isOffline), [sortedReportActions, isOffline]);

/**
* Evaluate new unread marker visibility for each of the report actions.
*/
Expand Down Expand Up @@ -451,6 +453,24 @@ function ReportActionsList({
[currentUnreadMarker, sortedVisibleReportActions, report.reportID, messageManuallyMarkedUnread],
);

const shouldUseThreadDividerLine = useMemo(() => {
const topReport = sortedVisibleReportActions[sortedVisibleReportActions.length - 1];

if (topReport.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED) {
return false;
}

if (ReportActionsUtils.isTransactionThread(parentReportAction)) {
return !ReportActionsUtils.isDeletedParentAction(parentReportAction) && !ReportActionsUtils.isReversedTransaction(parentReportAction);
}

if (ReportUtils.isTaskReport(report)) {
return !ReportUtils.isCanceledTaskReport(report, parentReportAction);
}

return ReportUtils.isExpenseReport(report) || ReportUtils.isIOUReport(report);
}, [parentReportAction, report, sortedVisibleReportActions]);

const calculateUnreadMarker = useCallback(() => {
// Iterate through the report actions and set appropriate unread marker.
// This is to avoid a warning of:
Expand Down Expand Up @@ -536,6 +556,8 @@ function ReportActionsList({
shouldHideThreadDividerLine={shouldHideThreadDividerLine}
shouldDisplayNewMarker={shouldDisplayNewMarker(reportAction, index)}
shouldDisplayReplyDivider={sortedReportActions.length > 1}
isFirstVisibleReportAction={firstVisibleReportActionID === reportAction.reportActionID}
shouldUseThreadDividerLine={shouldUseThreadDividerLine}
/>
),
[
Expand All @@ -550,6 +572,8 @@ function ReportActionsList({
reportActions,
transactionThreadReport,
parentReportActionForTransactionThread,
shouldUseThreadDividerLine,
firstVisibleReportActionID,
],
);

Expand Down
12 changes: 12 additions & 0 deletions src/pages/home/report/ReportActionsListItemRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ type ReportActionsListItemRendererProps = {

/** Whether we should display "Replies" divider */
shouldDisplayReplyDivider: boolean;

/** If this is the first visible report action */
isFirstVisibleReportAction: boolean;

/** If the thread divider line will be used */
shouldUseThreadDividerLine?: boolean;
};

function ReportActionsListItemRenderer({
Expand All @@ -61,6 +67,8 @@ function ReportActionsListItemRenderer({
shouldDisplayNewMarker,
linkedReportActionID = '',
shouldDisplayReplyDivider,
isFirstVisibleReportAction = false,
shouldUseThreadDividerLine = false,
parentReportActionForTransactionThread,
}: ReportActionsListItemRendererProps) {
const shouldDisplayParentAction =
Expand Down Expand Up @@ -144,6 +152,8 @@ function ReportActionsListItemRenderer({
reportActions={reportActions}
transactionThreadReport={transactionThreadReport}
index={index}
isFirstVisibleReportAction={isFirstVisibleReportAction}
shouldUseThreadDividerLine={shouldUseThreadDividerLine}
/>
) : (
<ReportActionItem
Expand All @@ -165,6 +175,8 @@ function ReportActionsListItemRenderer({
}
isMostRecentIOUReportAction={reportAction.reportActionID === mostRecentIOUReportActionID}
index={index}
isFirstVisibleReportAction={isFirstVisibleReportAction}
shouldUseThreadDividerLine={shouldUseThreadDividerLine}
/>
);
}
Expand Down
Loading

0 comments on commit a7db226

Please sign in to comment.