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

Fix created view is flickered when marking as unread #30815

Merged
merged 8 commits into from
Dec 6, 2023
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
2 changes: 1 addition & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2803,7 +2803,7 @@ const CONST = {
HORIZONTAL_SPACER: {
DEFAULT_BORDER_BOTTOM_WIDTH: 1,
DEFAULT_MARGIN_VERTICAL: 8,
HIDDEN_MARGIN_VERTICAL: 0,
HIDDEN_MARGIN_VERTICAL: 4,
HIDDEN_BORDER_BOTTOM_WIDTH: 0,
},

Expand Down
25 changes: 17 additions & 8 deletions src/components/SpacerView.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import Animated, {useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
import usePrevious from '@hooks/usePrevious';
import stylePropTypes from '@styles/stylePropTypes';
import * as StyleUtils from '@styles/StyleUtils';
import CONST from '@src/CONST';
Expand All @@ -23,22 +24,30 @@ const defaultProps = {
};

function SpacerView({shouldShow = true, style = []}) {
const marginVertical = useSharedValue(CONST.HORIZONTAL_SPACER.DEFAULT_MARGIN_VERTICAL);
const borderBottomWidth = useSharedValue(CONST.HORIZONTAL_SPACER.DEFAULT_BORDER_BOTTOM_WIDTH);
const marginVertical = useSharedValue(shouldShow ? CONST.HORIZONTAL_SPACER.DEFAULT_MARGIN_VERTICAL : CONST.HORIZONTAL_SPACER.HIDDEN_MARGIN_VERTICAL);
const borderBottomWidth = useSharedValue(shouldShow ? CONST.HORIZONTAL_SPACER.DEFAULT_BORDER_BOTTOM_WIDTH : CONST.HORIZONTAL_SPACER.HIDDEN_BORDER_BOTTOM_WIDTH);
const prevShouldShow = usePrevious(shouldShow);

const duration = CONST.ANIMATED_TRANSITION;
const animatedStyles = useAnimatedStyle(() => ({
marginVertical: marginVertical.value,
borderBottomWidth: borderBottomWidth.value,
borderBottomWidth: withTiming(borderBottomWidth.value, {duration}),
marginTop: withTiming(marginVertical.value, {duration}),
marginBottom: withTiming(marginVertical.value, {duration}),
}));

React.useEffect(() => {
const duration = CONST.ANIMATED_TRANSITION;
if (shouldShow === prevShouldShow) {
return;
}
const values = {
marginVertical: shouldShow ? CONST.HORIZONTAL_SPACER.DEFAULT_MARGIN_VERTICAL : CONST.HORIZONTAL_SPACER.HIDDEN_MARGIN_VERTICAL,
borderBottomWidth: shouldShow ? CONST.HORIZONTAL_SPACER.DEFAULT_BORDER_BOTTOM_WIDTH : CONST.HORIZONTAL_SPACER.HIDDEN_BORDER_BOTTOM_WIDTH,
};
marginVertical.value = withTiming(values.marginVertical, {duration});
borderBottomWidth.value = withTiming(values.borderBottomWidth, {duration});
}, [shouldShow, borderBottomWidth, marginVertical]);
marginVertical.value = values.marginVertical;
borderBottomWidth.value = values.borderBottomWidth;

// eslint-disable-next-line react-hooks/exhaustive-deps -- we only need to trigger when shouldShow prop is changed
}, [shouldShow, prevShouldShow]);

return <Animated.View style={[animatedStyles, ...StyleUtils.parseStyleAsArray(style)]} />;
}
Expand Down
47 changes: 20 additions & 27 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,9 @@ function ReportActionItem(props) {
};

if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) {
let content = (
<ReportActionItemCreated
reportID={props.report.reportID}
policyID={props.report.policyID}
/>
);
const parentReportAction = ReportActionsUtils.getParentReportAction(props.report);
if (ReportActionsUtils.isTransactionThread(parentReportAction)) {
content = (
return (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understand correctly the reason for returning everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the past, we didn't return to add the margin-bottom to wrap view of created action. Now we bring the margin to SpacingView so we can earlier return here.

<ShowContextMenuContext.Provider value={contextValue}>
<MoneyRequestView
report={props.report}
Expand All @@ -587,7 +581,7 @@ function ReportActionItem(props) {
}
if (ReportUtils.isTaskReport(props.report)) {
if (ReportUtils.isCanceledTaskReport(props.report, parentReportAction)) {
content = (
return (
<>
<AnimatedEmptyStateBackground />
<View style={[StyleUtils.getReportWelcomeTopMarginStyle(props.isSmallScreenWidth)]}>
Expand All @@ -602,22 +596,21 @@ function ReportActionItem(props) {
</View>
</>
);
} else {
content = (
<>
<AnimatedEmptyStateBackground />
<View style={[StyleUtils.getReportWelcomeTopMarginStyle(props.isSmallScreenWidth)]}>
<TaskView
report={props.report}
shouldShowHorizontalRule={!props.shouldHideThreadDividerLine}
/>
</View>
</>
);
}
return (
<>
<AnimatedEmptyStateBackground />
<View style={[StyleUtils.getReportWelcomeTopMarginStyle(props.isSmallScreenWidth)]}>
<TaskView
report={props.report}
shouldShowHorizontalRule={!props.shouldHideThreadDividerLine}
/>
</View>
</>
);
}
if (ReportUtils.isExpenseReport(props.report) || ReportUtils.isIOUReport(props.report)) {
content = (
return (
<OfflineWithFeedback pendingAction={props.action.pendingAction}>
<MoneyReportView
report={props.report}
Expand All @@ -627,12 +620,12 @@ function ReportActionItem(props) {
);
}

const isNormalCreatedAction =
!ReportActionsUtils.isTransactionThread(parentReportAction) &&
!ReportUtils.isTaskReport(props.report) &&
!ReportUtils.isExpenseReport(props.report) &&
!ReportUtils.isIOUReport(props.report);
return <View style={[props.shouldHideThreadDividerLine && !isNormalCreatedAction && styles.mb2]}>{content}</View>;
return (
<ReportActionItemCreated
reportID={props.report.reportID}
policyID={props.report.policyID}
/>
);
}
if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.RENAMED) {
return <RenameAction action={props.action} />;
Expand Down
Loading