Skip to content

Commit 7759a31

Browse files
mountinyOSBotify
authored andcommitted
Merge pull request #61840 from software-mansion-labs/Guccio163/wideViewFollowups
(cherry picked from commit d919997) (cherry-picked to staging by mountiny)
1 parent 745e79b commit 7759a31

File tree

7 files changed

+38
-17
lines changed

7 files changed

+38
-17
lines changed

src/CONST.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,7 @@ const CONST = {
15041504
},
15051505
RESERVED_ROOM_NAMES: ['#admins', '#announce'],
15061506
MAX_PREVIEW_AVATARS: 4,
1507+
TRANSACTION_PREVIEW_WIDTH_WIDE: 303,
15071508
MAX_ROOM_NAME_LENGTH: 99,
15081509
LAST_MESSAGE_TEXT_MAX_LENGTH: 200,
15091510
MIN_LENGTH_LAST_MESSAGE_WITH_ELLIPSIS: 20,

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ function MoneyRequestReportPreviewContent({
105105
lastTransactionViolations,
106106
isDelegateAccessRestricted,
107107
renderTransactionItem,
108-
onLayout,
108+
onCarouselLayout,
109+
onWrapperLayout,
109110
currentWidth,
110111
reportPreviewStyles,
111112
shouldDisplayContextMenu = true,
@@ -410,7 +411,10 @@ function MoneyRequestReportPreviewContent({
410411
};
411412

412413
// The button should expand up to transaction width
413-
const buttonMaxWidth = !shouldUseNarrowLayout && reportPreviewStyles.transactionPreviewStyle.width >= 303 ? {maxWidth: reportPreviewStyles.transactionPreviewStyle.width} : {};
414+
const buttonMaxWidth =
415+
!shouldUseNarrowLayout && reportPreviewStyles.transactionPreviewStyle.width >= CONST.REPORT.TRANSACTION_PREVIEW_WIDTH_WIDE
416+
? {maxWidth: reportPreviewStyles.transactionPreviewStyle.width}
417+
: {};
414418

415419
const approvedOrSettledIcon = (iouSettled || isApproved) && (
416420
<ImageSVG
@@ -581,14 +585,17 @@ function MoneyRequestReportPreviewContent({
581585
};
582586

583587
return (
584-
<View onLayout={onLayout}>
588+
<View onLayout={onWrapperLayout}>
585589
<OfflineWithFeedback
586590
pendingAction={iouReport?.pendingFields?.preview}
587591
shouldDisableOpacity={!!(action.pendingAction ?? action.isOptimisticAction)}
588592
needsOffscreenAlphaCompositing
589593
style={styles.mt1}
590594
>
591-
<View style={[styles.chatItemMessage, isReportDeleted && [styles.cursorDisabled, styles.pointerEventsAuto], containerStyles]}>
595+
<View
596+
style={[styles.chatItemMessage, isReportDeleted && [styles.cursorDisabled, styles.pointerEventsAuto], containerStyles]}
597+
onLayout={onCarouselLayout}
598+
>
592599
<PressableWithoutFeedback
593600
onPress={onPress}
594601
onPressIn={() => canUseTouchScreen() && ControlSelection.block()}

src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ function MoneyRequestReportPreview({
5959
const isTrackExpenseAction = isTrackExpenseActionReportActionsUtils(action);
6060
const isSplitBillAction = isSplitBillActionReportActionsUtils(action);
6161
const [currentWidth, setCurrentWidth] = useState(256);
62+
const [currentWrapperWidth, setCurrentWrapperWidth] = useState(256);
6263
const reportPreviewStyles = useMemo(
63-
() => StyleUtils.getMoneyRequestReportPreviewStyle(shouldUseNarrowLayout, currentWidth, transactions.length === 1),
64-
[StyleUtils, currentWidth, shouldUseNarrowLayout, transactions.length],
64+
() => StyleUtils.getMoneyRequestReportPreviewStyle(shouldUseNarrowLayout, currentWidth, currentWrapperWidth, transactions.length === 1),
65+
[StyleUtils, currentWidth, currentWrapperWidth, shouldUseNarrowLayout, transactions.length],
6566
);
6667

6768
const shouldShowIOUData = useMemo(() => {
@@ -127,9 +128,12 @@ function MoneyRequestReportPreview({
127128
lastTransactionViolations={lastTransactionViolations}
128129
isDelegateAccessRestricted={isDelegateAccessRestricted}
129130
renderTransactionItem={renderItem}
130-
onLayout={(e: LayoutChangeEvent) => {
131+
onCarouselLayout={(e: LayoutChangeEvent) => {
131132
setCurrentWidth(e.nativeEvent.layout.width ?? 255);
132133
}}
134+
onWrapperLayout={(e: LayoutChangeEvent) => {
135+
setCurrentWrapperWidth(e.nativeEvent.layout.width ?? 255);
136+
}}
133137
currentWidth={currentWidth}
134138
reportPreviewStyles={reportPreviewStyles}
135139
shouldDisplayContextMenu={shouldDisplayContextMenu}

src/components/ReportActionItem/MoneyRequestReportPreview/types.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ type MoneyRequestReportPreviewContentProps = MoneyRequestReportPreviewContentOny
8181
/** MoneyRequestReportPreview's current width */
8282
currentWidth: number;
8383

84-
/** Callback passed to onLayout */
85-
onLayout: (e: LayoutChangeEvent) => void;
84+
/** Callback passed to Carousel's onLayout */
85+
onCarouselLayout: (e: LayoutChangeEvent) => void;
86+
87+
/** Callback passed to Component wrapper view's onLayout */
88+
onWrapperLayout: (e: LayoutChangeEvent) => void;
8689

8790
/** Callback to render a transaction preview item */
8891
renderTransactionItem: ListRenderItem<Transaction>;

src/pages/home/report/PureReportActionItem.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ function PureReportActionItem({
433433
[StyleUtils, isReportActionLinked, theme.messageHighlightBG],
434434
);
435435

436-
const reportPreviewStyles = StyleUtils.getMoneyRequestReportPreviewStyle(shouldUseNarrowLayout, undefined, true);
436+
const reportPreviewStyles = StyleUtils.getMoneyRequestReportPreviewStyle(shouldUseNarrowLayout, undefined, undefined, true);
437437

438438
const isDeletedParentAction = isDeletedParentActionUtils(action);
439439

src/stories/MoneyRequestReportPreview.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const mockTransactionsBig = Array.from({length: 12}).map((item, index) => {
3434
return {...transactionR14932, transactionID: `${transactionR14932.transactionID}${index}`};
3535
});
3636

37-
const reportPreviewStyle = getMoneyRequestReportPreviewStyle(false, 400, false);
37+
const reportPreviewStyle = getMoneyRequestReportPreviewStyle(false, 400, 400, false);
3838

3939
const mockRenderItem: ListRenderItem<Transaction> = ({item}) => (
4040
<TransactionPreviewContent

src/styles/utils/getMoneyRequestReportPreviewStyle/index.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {MoneyRequestReportPreviewStyleType} from '@components/ReportActionI
33
import sizing from '@styles/utils/sizing';
44
// eslint-disable-next-line no-restricted-imports
55
import spacing from '@styles/utils/spacing';
6+
import CONST from '@src/CONST';
67

78
const componentsSpacing = {
89
flatListStyle: [spacing.mhn4],
@@ -11,7 +12,7 @@ const componentsSpacing = {
1112
};
1213

1314
const NEXT_TRANSACTION_PEEK = 32;
14-
const TRANSACTION_WIDTH_WIDE = 303;
15+
const TRANSACTION_WIDTH_WIDE = CONST.REPORT.TRANSACTION_PREVIEW_WIDTH_WIDE;
1516

1617
const mobileStyle = (currentWidth: number, isSingleTransaction?: boolean) => {
1718
const peek = isSingleTransaction ? spacing.p4.padding : NEXT_TRANSACTION_PEEK;
@@ -23,20 +24,25 @@ const mobileStyle = (currentWidth: number, isSingleTransaction?: boolean) => {
2324
};
2425
};
2526

26-
const desktopStyle = (currentWidth: number, isSingleTransaction?: boolean) => {
27+
const desktopStyle = (currentWrapperWidth: number, isSingleTransaction?: boolean) => {
2728
const peek = isSingleTransaction ? spacing.p4.padding : NEXT_TRANSACTION_PEEK;
28-
const transactionPreviewWidth = currentWidth - spacing.p4.padding - peek;
29+
const transactionPreviewWidth = currentWrapperWidth - spacing.p4.padding - peek;
2930
const minimalWrapperWidth = TRANSACTION_WIDTH_WIDE + spacing.p4.padding + peek;
3031
return {
31-
transactionPreviewStyle: {width: currentWidth > minimalWrapperWidth ? TRANSACTION_WIDTH_WIDE : transactionPreviewWidth},
32+
transactionPreviewStyle: {width: currentWrapperWidth > minimalWrapperWidth ? TRANSACTION_WIDTH_WIDE : transactionPreviewWidth},
3233
componentStyle: [{maxWidth: 'min(680px, 100%)'}, {width: 'min-content'}],
3334
expenseCountVisible: transactionPreviewWidth >= TRANSACTION_WIDTH_WIDE,
3435
};
3536
};
3637

37-
const getMoneyRequestReportPreviewStyle = (shouldUseNarrowLayout: boolean, currentWidth?: number, isSingleTransaction?: boolean): MoneyRequestReportPreviewStyleType => ({
38+
const getMoneyRequestReportPreviewStyle = (
39+
shouldUseNarrowLayout: boolean,
40+
currentWidth?: number,
41+
currentWrapperWidth?: number,
42+
isSingleTransaction?: boolean,
43+
): MoneyRequestReportPreviewStyleType => ({
3844
...componentsSpacing,
39-
...(shouldUseNarrowLayout ? mobileStyle(currentWidth ?? 256, isSingleTransaction) : desktopStyle(currentWidth ?? 1000, isSingleTransaction)),
45+
...(shouldUseNarrowLayout ? mobileStyle(currentWidth ?? 256, isSingleTransaction) : desktopStyle(currentWrapperWidth ?? 1000, isSingleTransaction)),
4046
});
4147

4248
export default getMoneyRequestReportPreviewStyle;

0 commit comments

Comments
 (0)