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

Mobile: fix side-menu width on tablet devices #6662

Merged
merged 62 commits into from
Aug 25, 2022

Conversation

Tolu-Mals
Copy link
Contributor

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

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.
@laurent22
Copy link
Owner

Thanks Tolu. You have some conflicts that need to be resolved

@Tolu-Mals
Copy link
Contributor Author

It looks like a dependency is missing! Try running yarn install again and committing changes to yarn.lock.

Error: ➤YN0000: │ root@workspace:.STDERR➤YN0000: [@joplin/app-mobile]: tools/buildInjectedJs.ts(6,45): error TS7016: Could not find a declaration file for module 'fs-extra'. 'D:/a/joplin/joplin/packages/app-mobile/node_modules/fs-extra/lib/index.js' implicitly has an 'any' type.

(A dependency on @types/fs-extra was added in a recently-merged PR)

Thanks. I'll try that.

@Tolu-Mals
Copy link
Contributor Author

It looks like a dependency is missing! Try running yarn install again and committing changes to yarn.lock.

Error: ➤YN0000: │ root@workspace:.STDERR➤YN0000: [@joplin/app-mobile]: tools/buildInjectedJs.ts(6,45): error TS7016: Could not find a declaration file for module 'fs-extra'. 'D:/a/joplin/joplin/packages/app-mobile/node_modules/fs-extra/lib/index.js' implicitly has an 'any' type.

(A dependency on @types/fs-extra was added in a recently-merged PR)

After running yarn install there were no changes in yarn.lock

@Tolu-Mals
Copy link
Contributor Author

Tolu-Mals commented Jul 24, 2022

A test is now failing due to a linter error in getResponsiveValue.ts:

  41:10  error  Expected '!==' and instead saw '!='  eqeqeq
  45:9   error  Expected '!==' and instead saw '!='  eqeqeq
  49:9   error  Expected '!==' and instead saw '!='  eqeqeq
  57:9   error  Expected '!==' and instead saw '!='  eqeqeq
  65:25  error  Expected '!==' and instead saw '!='  eqeqeq
  69:26  error  Expected '!==' and instead saw '!='  eqeqeq
  73:27  error  Expected '!==' and instead saw '!='  eqeqeq

eslint expects only strict equality to be used. I'll see if there's a way to rewrite the logic without the '!='

@Tolu-Mals
Copy link
Contributor Author

I think this is ready to be merged.

Tolu-Mals and others added 2 commits July 25, 2022 10:55

const config = {
preset: 'ts-jest',
testMatch: ['**/*.test.js'],
Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Owner

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?

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Owner

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.

Copy link
Contributor Author

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.

Comment on lines +2143 to +2145
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
Copy link
Owner

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted.

Copy link
Contributor Author

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

Comment on lines 6 to 13
type Event = {
nativeEvent: {
layout: {
width: number;
height: number;
};
};
};
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted.

Comment on lines 9 to 14

// Files that don't need transpilation
"gulpfile.ts",
"tools/*.ts",
"**/*.test.ts",
"**/*.test.tsx",
Copy link
Owner

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?

Copy link
Contributor Author

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.
@laurent22
Copy link
Owner

I think it's good now but please resolve the yarn.lock conflict

@laurent22
Copy link
Owner

Some tests need this to work.
@Tolu-Mals
Copy link
Contributor Author

Tests are failing: https://github.com/laurent22/joplin/runs/7729267796?check_suite_focus=true#step:10:4324

Thank you. I just made a fix, I think they should pass now.

@Tolu-Mals
Copy link
Contributor Author

@laurent22 It's good now.

@laurent22
Copy link
Owner

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.
@laurent22 laurent22 merged commit 8b06cbf into laurent22:dev Aug 25, 2022
@laurent22
Copy link
Owner

Ok I've tested it on simulator and it looks good, thanks Tolu!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants