-
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
[HOLD for payment 2024-10-30] [$1000] Create a useResponsiveLayout hook #30528
Comments
Job added to Upwork: https://www.upwork.com/jobs/~01f36dcb081cdf74b2 |
Triggered auto assignment to @maddylewis ( |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @getusha ( |
I can work on this if no one is assigned yet, or should I write proposal Since it is a new feature main idea is explained well in description, and I think anything else could be discussed in the PR |
ProposalPlease re-state the problem that we are trying to solve in this issue.The problem we aim to address is the lack of a consistent and reliable method to determine the appropriate layout for mobile devices and wide screens within our application. Currently, we rely on the What is the root cause of that problem?The root cause of this problem lies in the absence of a dedicated mechanism to determine the layout based on specific conditions, such as whether a screen is within the RHP or on a small screen. What changes do you think we should make in order to solve the problem?
App/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx Lines 60 to 64 in 7b836cf
Include an isInRHP option with a default value (true). <ModalStackNavigator.Screen
key={name}
name={name}
getComponent={(screens as Required<Screens>)[name as Screen]}
initialParams={{isInRHP: true} as TStackParams[string]} //here
/>
export default function useResponsiveLayout(): ResponsiveLayoutResult {
const {isSmallScreenWidth} = useWindowDimensions();
try {
const {params} = useRoute<RouteProp<RouteParams, 'params'>>();
return {shouldUseNarrowLayout: isSmallScreenWidth || (params?.isInRHP ?? false)};
} catch (error) {
return {
shouldUseNarrowLayout: isSmallScreenWidth,
};
}
}
Before: const { isSmallScreenWidth } = useWindowDimensions(); After: const { shouldUseNarrowLayout } = useResponsiveLayout();
const _ = require('underscore');
const message = require('./CONST').MESSAGE.PREFER_USE_RESPONSIVE_FOR_LAYOUT;
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Prohibit the direct use of isSmallScreenWidth from useWindowDimensions',
},
},
create(context) {
return {
VariableDeclarator(node) {
if (!node.init || !node.init.callee || node.init.callee.name !== 'useWindowDimensions') {
return;
}
// Check for 'const {isSmallScreenWidth, ...} = useWindowDimensions();' pattern
if (node.id.type === 'ObjectPattern') {
node.id.properties.forEach((property) => {
if (!property.key || property.key.name !== 'isSmallScreenWidth') {
return;
}
context.report({
node: property,
message,
});
});
}
// Check for 'const var = useWindowDimensions();' and use of this var
const variableName = node.id.name;
const variableUsages = _.filter(context.getScope().references, reference => reference.identifier.name === variableName);
variableUsages.forEach((usage) => {
const parent = usage.identifier.parent;
// Check for 'const isSmallScreen = var.isSmallScreenWidth;' pattern
if (parent.type === 'MemberExpression' && parent.property.name === 'isSmallScreenWidth') {
context.report({
node: parent.property,
message,
});
}
// Check for 'const {isSmallScreenWidth} = var;' pattern
if (parent.type === 'VariableDeclarator' && parent.id.type === 'ObjectPattern') {
parent.id.properties.forEach((property) => {
if (!property.key || property.key.name !== 'isSmallScreenWidth') {
return;
}
context.report({
node: property,
message,
});
});
}
});
},
MemberExpression(node) {
// Check for 'const isSmallScreen = useWindowDimensions().isSmallScreenWidth;' pattern
if (node.object.type !== 'CallExpression' || node.object.callee.name !== 'useWindowDimensions' || node.property.name !== 'isSmallScreenWidth') {
return;
}
context.report({
node,
message,
});
},
};
},
}; we should also add a test for this rule. What alternative solutions did you explore? (Optional)N/A |
Problem: Solution: Route Prop for RHP Detection: In the navigation stack, it is suggested to add an isInRHP route prop to all screens within the RHP. This addition allows for easy identification of screens within the RHP. Custom Hook - useResponsiveLayout: Create a custom hook called useResponsiveLayout to determine the appropriate layout based on the screen width and the isInRHP route prop.
Replace useWindowDimensions with useResponsiveLayout: To ensure a consistent approach to layout handling, replace most of the current uses of useWindowDimensions with useResponsiveLayout as shown below:
// After |
📣 @WebflowGuru! 📣
|
Thanks for all the proposals everyone. At this time I've decided to move forward with the one that feels the clearest and most high-quality, which in my opinion is from @rayane-djouah here. |
Thank you, I will raise a PR asap |
PR ready for review: #50935 |
This comment was marked as outdated.
This comment was marked as outdated.
Waiting for this one to move to production |
|
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.52-5 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue: If no regressions arise, payment will be issued on 2024-10-30. 🎊 For reference, here are some details about the assignees on this issue:
|
BugZero Checklist: The PR adding this new feature has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:
|
No regression tests required this is a tool for developers The payment summary is $1000 to @rayane-djouah and to @getusha |
Payment Summary
BugZero Checklist (@alexpensify)
|
Payouts due: 2024-10-30
Upwork job is here. I had to create a new job in Upwork. Please accept and I can complete the payment process. Thanks! |
@alexpensify The payment amount for this issue is $1000 - #30528 (comment) |
@alexpensify Offer accepted, thanks! |
🤦🏼 good catch - Upwork was right. I've updated the summary here and paid @rayane-djouah via Upwork. I'm waiting for @getusha to accept. |
Status: Waiting for @getusha to accept in Upwork |
@alexpensify I think that @getusha is being paid in NewDot, we can close this issue |
Thanks for flagging! This GH is from 2023. I think it needs to be paid via Chat, but let me double-check. |
I confirmed that this one is from 2023. It will need to be paid via Upwork. I will move this to weekly since I'm OOO until Tuesday. @getusha, keep me posted when you accept it in Upwork. I'll complete the process when I'm back online. |
@alexpensify accepted, thanks! |
All set, everyone has been paid via Upwork: #30528 (comment) |
Slack context: https://expensify.slack.com/archives/C01GTK53T8Q/p1698364514493649
Problem
There are some times when we want to use the same layout on mobile devices or in the RHP on wide screens. In these cases, we can't rely on
isSmallScreenWidth
fromuseWindowDimensions
to determine which layout to use, so we have hard-coded and/or different solutions we use to address the same problem.Solution
In the navigation stack, add an
isInRHP
route prop to all screens in the RHP.Write a custom hook called
useResponsiveLayout
that does something like this:Replace most layout-motivated uses of useWindowDimensions with useResponsiveLayout like so:
Introduce a new lint rule that prohibits using
isSmallScreenWidth
fromuseWindowDimensions
, advising developers to useshouldUseNarrowLayout
instead.Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @alexpensifyThe text was updated successfully, but these errors were encountered: