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

Adjust Platform constants import #1211

Merged
merged 5 commits into from
Feb 13, 2021
Merged

Adjust Platform constants import #1211

merged 5 commits into from
Feb 13, 2021

Conversation

drewandre
Copy link
Contributor

@drewandre drewandre commented Oct 13, 2020

Description

Fixes #1210 by importing platform constants from react-native's Platform API instead of NativeModules.PlatformConstants. ForceTouchGestureHandler is the only handler that requires this file, so this change only affects this handler. It is also backwards-compatible.

I'm a bit confused why PlatformConstants would ever be used over Platform. They have a slightly different data structure, but as far as I can tell the constants are the same.

Test plan

I tested this on the gesture-handler example app which is running RN v0.61.2, as well as the reanimated v2 playground repo which runs RN v0.63.1. I did not test on web, but PlatformConstants is not a file required by any web-specific files. There is a PlatformConstants.web.js file, but the getter defined in this file is the same data structure as exporting Platform.constants in PlatformConstants.js for mobile.

@drewandre drewandre changed the title correct platform constants import Correct platform constants import (fixes ForceTouchGestureHandler) Oct 13, 2020
Copy link
Contributor

@jkadamczyk jkadamczyk left a comment

Choose a reason for hiding this comment

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

Hey @drewandre
I added a suggestion on how it can be implemented in case someone is using an older version and PlatformConstants is still available.
@jakub-gonet Please let me know if I'm wrong with the solution in any way 😄

PlatformConstants.js Outdated Show resolved Hide resolved
PlatformConstants.js Outdated Show resolved Hide resolved
This looks great, I didn't think that PlatformConstants may be used in older versions of this library. Thanks for the suggestion!

Co-authored-by: Jakub Adamczyk <[email protected]>
@jkadamczyk
Copy link
Contributor

@drewandre Thanks for the fixes, I'll try to look into this today and get it merged. Have a good day!

@jkadamczyk
Copy link
Contributor

E2E tests are kind of not working I have to investigate why 🤷

@jkadamczyk jkadamczyk self-requested a review October 21, 2020 10:43
@jkadamczyk jkadamczyk self-assigned this Oct 21, 2020
@jakub-gonet
Copy link
Member

Updated branch with master. Sorry for introducing a bunch of unrelated lint changes.

@jakub-gonet
Copy link
Member

CI is failing due to missing Platform.constants types.
I submitted DefinitelyTyped/DefinitelyTyped#51146 so we should update RN types after it's merged and merge this one.

Copy link
Member

@jakub-gonet jakub-gonet left a comment

Choose a reason for hiding this comment

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

Thanks!

@jakub-gonet jakub-gonet changed the title Correct platform constants import (fixes ForceTouchGestureHandler) Adjust Platform constants import Feb 13, 2021
@jakub-gonet jakub-gonet merged commit 28b5b98 into software-mansion:master Feb 13, 2021
braincore pushed a commit to braincore/react-native-gesture-handler that referenced this pull request Mar 4, 2021
## Description

Fixes software-mansion#1210 by importing platform constants from react-native's `Platform` API instead of `NativeModules.PlatformConstants`. ForceTouchGestureHandler is the only handler that requires this file, so this change only affects this handler. It is also backward-compatible.

I'm a bit confused why PlatformConstants would ever be used over Platform. They have a slightly different data structure, but as far as I can tell the constants are the same.

## Test plan

I tested this on the [gesture-handler example app](https://github.com/software-mansion/react-native-gesture-handler/tree/master/Example) which is running RN v0.61.2, as well as the [reanimated v2 playground repo](https://github.com/software-mansion-labs/reanimated-2-playground) which runs RN v0.63.1. I did not test on the web, but PlatformConstants is not a file required by any web-specific files. There is a PlatformConstants.web.js file, but the getter defined in this file is the same data structure as exporting `Platform.constants` in PlatformConstants.js for mobile.


Co-authored-by: Jakub Adamczyk <[email protected]>
Co-authored-by: Jakub Gonet <[email protected]>
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.

PlatformConstants no longer a member of NativeModules (breaks ForceTouchGestureHandler)
3 participants