Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Details
This PR is a follow up of the TS migration. It's aim was to figure out way of handling refs in the project as in many places the types were defined as union of React Native's components and HTML elements.
Bug caused by usage of refs was found and fixed. The
AutocompleteSuggestions
component was handling long press events by overridingonpointerdown
handler. But the reference to dom element wasn't ready duringuseEffect
hook and result was that the autocomplete was closing on mobile browsers when suggestion was pressed for longer time. It was fixed by usingonPointerDown
provided by react-native-web.Fixed Issues
$
PROPOSAL:
In general we should avoid using DOM elements as ref types. That's React Native Web handles references on web so there's no need to explicitly use types like
HTMLDivElement
. Exception of this rule is when we explicitly need to use functions available only in DOM and not in React Native, e.g.getBoundingClientRect
. It's heavily used in Tooltips and Popovers which are only used on web.When adding handlers for Pointers and Mouse events the interaction API provided by React Native Web is preferred option. It's generally satisfied across the app.
In general if there is no need to use DOM specific methods then one should use
View
as ref type. This PR updates types in several places to follow this pattern. Union types likeView | HTMLDivElement
should be used only in places where DOM api is necessary. Technically components on web have type equal toView & HTMLDivElement
because they have methods available on both platforms. But it's not true in case of native components and this is why union should be used. It enforces developer to explicitly check if metod on property exist on the reference object. While it may be a bit cumbersome it prevents runtime bugs.Unfortunately, union types forces us to use type casting. This is because
HTMLDivElement
can't be passed toView
. It should be done as soon as possible to prevent such types to be propagated. There are utility functions likeviewRef
defined to achieve that.Tests
:app
Offline tests
N/A
QA Steps
Same as in Tests
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.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 and/or tagged@Expensify/design
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
Before:
android_web_before.mov
After:
android_web_after.mov
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop