-
-
Notifications
You must be signed in to change notification settings - Fork 4.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
Mobile: fix side-menu width on tablet devices #6662
Conversation
I decided to include the test setup inside the test to make the tests easier to read and understand. Also, future tests might not require the same set up, so it's best to include the setup only the test that requires it.
I added sideMenuWidth state to the root component, then set up an event listener to update the sideMenuWidth state everything the screen width changes. I also set the sideMenuWidth state as a key to the side menu component to make it rerender when the sideMenuWidth state changes.
The former method is deprecated
…tResponsiveValue.ts and getResponsiveValue.test.ts
Array syntax implementation is removed to make the code more self documenting. The first test is modified to check that an exception is thrown when an empty valueMap object is passed to getResponsiveValue, since there's no reason for that.
To reduce boiler plate code and make tests easier to maintain.
Change screenWidthChangeEvent to unsubscribeScreenWidthChangeHandler_ to follow naming convention.
I replaced Dimensions.get('screen') with Dimensions.get('window') because that gives a more concise value that excludes the status bar or navigation bar on an android device.
react-native-side-menu had an issue where it wasn't calculating the side menu's width properly, when a device's width changes , as a result the side menu wasn't rendering consistently with the openMenuOffset values being passed. To fix this, I overrided a method, with a slightly different version. The sidemenu now renders consistently when a device's width cahnges.
The logic for getting the side menu width was being repeated in two parts of the code, so I created a function for that. Also, I made the side menu width increase with each successive breakpoint to take advantage of the screen width to display longer note titles without truncating it.
The sidemenu component rerenders when sideMenuWidth changes without the key.
Thanks Tolu. You have some conflicts that need to be resolved |
Thanks. I'll try that. |
After running |
A test is now failing due to a linter error in
eslint expects only strict equality to be used. I'll see if there's a way to rewrite the logic without the '!=' |
I think this is ready to be merged. |
Co-authored-by: Henry Heino <[email protected]>
Co-authored-by: Henry Heino <[email protected]>
packages/app-mobile/jest.config.js
Outdated
|
||
const config = { | ||
preset: 'ts-jest', | ||
testMatch: ['**/*.test.js'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was ts-test removed? I thought we were keeping this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, actually @personalizedrefrigerator set it up with ts-jest, is that right? In that case, yes please use this for this particular package.
I saw this a bit late. I'll fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm currently setting up app-mobile to use ts-jest for testing and I've realized that the preset doesn't need to be 'ts-jest' for ts-jest to be used. The preset needs to 'react-native'. Just leaving this here to avoid any confusion. I followed this guide: Using Typescript With React Native.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know about this, but I think that's going to conflict with what @personalizedrefrigerator is doing? @personalizedrefrigerator will your tests still work with this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, tsconfig.json
is configured to not create .js files from .test.ts
files. As such, unless tsconfig.json
is modified, it shouldn't work with my test files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed tsconfig
in my recent commit. Your tests are running fine now as well as mine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like some consistency in the tests. Either it's all .js or it's all .ts but not mix and match. I liked the approach of running the .test.ts files directly because it means we don't need source maps.
Is it not possible to get that working with your tests @Tolu-Mals? If there's an issue please explain clearly what it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible. I'll do that.
packages/app-mobile/components/get-responsive-value.test.js | ||
packages/app-mobile/components/get-responsive-value.test.js | ||
packages/app-mobile/components/get-responsive-value.test.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that should be here - run yarn run updateIgnored from the root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why but running updateIgnored
from root doesn't remove it from the .gitignore
type Event = { | ||
nativeEvent: { | ||
layout: { | ||
width: number; | ||
height: number; | ||
}; | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove. We can't have each file define types for third-party libraries. That should maybe be in a separate file shared by all other files. But for now just remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted.
packages/app-mobile/tsconfig.json
Outdated
|
||
// Files that don't need transpilation | ||
"gulpfile.ts", | ||
"tools/*.ts", | ||
"**/*.test.ts", | ||
"**/*.test.tsx", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, why was that changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix that.
This commit removes support for js test files from jest. This is because only typescript is to be used for testing in app-mobile.
I think it's good now but please resolve the yarn.lock conflict |
Some tests need this to work.
Thank you. I just made a fix, I think they should pass now. |
@laurent22 It's good now. |
Unfortunately still a yarn.lock conflict. A new one this time. |
Removed jsdom as the default test environment, it's better for specific files that need it to define it inside the file. Also defined types in the tsconfig.
Ok I've tested it on simulator and it looks good, thanks Tolu! |
Summary
This pull request fixes the issue of the side-menu becoming too wide on devices with wider screens like tablet devices. It's a part of the Tablet Layout Project