-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[No QA] use a better approach for useResponsiveLayout hook #34743
[No QA] use a better approach for useResponsiveLayout hook #34743
Conversation
@getusha @roryabraham After encountering regressions caused by #33426, I am modifying the logic for the useResponsiveLayout hook. Instead of passing a parameter to screens in the modal stack navigator and checking for it in the hook, I am now obtaining the navigator name directly from the navigationRef in the hook without altering the navigation logic. What are your thoughts on this approach? |
@getusha bump |
@rayane-djouah Just tested this on
|
@rayane-djouah this is the changes i made to the component, please let me know if i did something wrong. Diff
diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js
index bd8d535e54..abf4c9c858 100755
--- a/src/components/AttachmentModal.js
+++ b/src/components/AttachmentModal.js
@@ -39,6 +39,7 @@ import SafeAreaConsumer from './SafeAreaConsumer';
import transactionPropTypes from './transactionPropTypes';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions';
+import useResponsiveLayout from "@hooks/useResponsiveLayout";
/**
* Modal render prop component that exposes modal launching triggers that can be used
@@ -136,6 +137,8 @@ function AttachmentModal(props) {
const [isDownloadButtonReadyToBeShown, setIsDownloadButtonReadyToBeShown] = React.useState(true);
const {windowWidth} = useWindowDimensions();
+ const {shouldUseNarrowLayout} = useResponsiveLayout();
+
const isOverlayModalVisible = (props.isReceiptAttachment && isDeleteReceiptConfirmModalVisible) || (!props.isReceiptAttachment && isAttachmentInvalid);
const [file, setFile] = useState(
@@ -445,14 +448,14 @@ function AttachmentModal(props) {
propagateSwipe
>
<GestureHandlerRootView style={styles.flex1}>
- {props.isSmallScreenWidth && <HeaderGap />}
+ {shouldUseNarrowLayout && <HeaderGap />}
<HeaderWithBackButton
title={headerTitle}
shouldShowBorderBottom
shouldShowDownloadButton={shouldShowDownloadButton}
onDownloadButtonPress={() => downloadAttachment(source)}
- shouldShowCloseButton={!props.isSmallScreenWidth}
- shouldShowBackButton={props.isSmallScreenWidth}
+ shouldShowCloseButton={!shouldUseNarrowLayout}
+ shouldShowBackButton={shouldUseNarrowLayout}
onBackButtonPress={closeModal}
onCloseButtonPress={closeModal}
shouldShowThreeDotsButton={shouldShowThreeDotsButton}
@@ -494,7 +497,7 @@ function AttachmentModal(props) {
<Animated.View style={[StyleUtils.fade(confirmButtonFadeAnimation), safeAreaPaddingBottomStyle]}>
<Button
success
- style={[styles.buttonConfirm, props.isSmallScreenWidth ? {} : styles.attachmentButtonBigScreen]}
+ style={[styles.buttonConfirm, shouldUseNarrowLayout ? {} : styles.attachmentButtonBigScreen]}
textStyles={[styles.buttonConfirmText]}
text={translate('common.send')}
onPress={submitAndClose} |
Good catch! @getusha Consequently, I propose that the optimal solution involves returning both here is the diff for debugging @getusha : Diffdiff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js
index bd8d535e54..67fba81181 100755
--- a/src/components/AttachmentModal.js
+++ b/src/components/AttachmentModal.js
@@ -9,6 +9,7 @@ import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
+import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
@@ -136,6 +137,8 @@ function AttachmentModal(props) {
const [isDownloadButtonReadyToBeShown, setIsDownloadButtonReadyToBeShown] = React.useState(true);
const {windowWidth} = useWindowDimensions();
+ const {isSmallScreenWidth, isInModal} = useResponsiveLayout();
+
const isOverlayModalVisible = (props.isReceiptAttachment && isDeleteReceiptConfirmModalVisible) || (!props.isReceiptAttachment && isAttachmentInvalid);
const [file, setFile] = useState(
@@ -149,6 +152,8 @@ function AttachmentModal(props) {
const {isOffline} = useNetwork();
useEffect(() => {
+ console.log('isInModal: ', isInModal);
+ console.log('isSmallScreenWidth: ', isSmallScreenWidth);
setFile(props.originalFileName ? {name: props.originalFileName} : undefined);
}, [props.originalFileName]);
@@ -445,14 +450,14 @@ function AttachmentModal(props) {
propagateSwipe
>
<GestureHandlerRootView style={styles.flex1}>
- {props.isSmallScreenWidth && <HeaderGap />}
+ {isSmallScreenWidth && <HeaderGap />}
<HeaderWithBackButton
title={headerTitle}
shouldShowBorderBottom
shouldShowDownloadButton={shouldShowDownloadButton}
onDownloadButtonPress={() => downloadAttachment(source)}
- shouldShowCloseButton={!props.isSmallScreenWidth}
- shouldShowBackButton={props.isSmallScreenWidth}
+ shouldShowCloseButton={!isSmallScreenWidth}
+ shouldShowBackButton={isSmallScreenWidth}
onBackButtonPress={closeModal}
onCloseButtonPress={closeModal}
shouldShowThreeDotsButton={shouldShowThreeDotsButton}
@@ -494,7 +499,7 @@ function AttachmentModal(props) {
<Animated.View style={[StyleUtils.fade(confirmButtonFadeAnimation), safeAreaPaddingBottomStyle]}>
<Button
success
- style={[styles.buttonConfirm, props.isSmallScreenWidth ? {} : styles.attachmentButtonBigScreen]}
+ style={[styles.buttonConfirm, isSmallScreenWidth ? {} : styles.attachmentButtonBigScreen]}
textStyles={[styles.buttonConfirmText]}
text={translate('common.send')}
onPress={submitAndClose} What do you think @getusha @roryabraham ? |
@rayane-djouah that seems like the new solution differs from what we're trying to achieve. |
Reviewer Checklist
Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeiOS: NativeiOS: mWeb SafariMacOS: Chrome / SafariMacOS: Desktop |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/roryabraham in version: 1.4.33-0 🚀
|
🚀 Deployed to production by https://github.com/francoisl in version: 1.4.33-5 🚀
|
Details
#30528 (comment)
Fixed Issues
$ #30528
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop