-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow out-of-tree platforms to extend Touch fields (#38681)
Summary: Pull Request resolved: #38681 Desktop platforms send additional information with onTouch(Start|Move|End|Cancel) events, including modifier keys and mouse button information. This information has not historically been available for mobile platforms, so rather than blindly adding the fields, this change adds a hook for out-of-tree platforms to extend the data in nativeEvent payload for Fabric Touch events. ## Changelog: [General] [Added] - Support customization of underlying Touch event representation in out-of-tree platforms Reviewed By: christophpurrer Differential Revision: D47896016 fbshipit-source-id: 02e3fce854302412381b0bd9254474c6bb5c63ac
- Loading branch information
1 parent
2b688f6
commit 4884322
Showing
6 changed files
with
139 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
packages/react-native/ReactCommon/react/renderer/components/view/BaseTouch.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <jsi/jsi.h> | ||
#include <react/renderer/core/ReactPrimitives.h> | ||
#include <react/renderer/debug/DebugStringConvertible.h> | ||
#include <react/renderer/graphics/Point.h> | ||
|
||
namespace facebook::react { | ||
|
||
/* | ||
* Describes an individual touch point for a touch event. | ||
* See https://www.w3.org/TR/touch-events/ for more details. | ||
*/ | ||
struct BaseTouch { | ||
/* | ||
* The coordinate of point relative to the root component in points. | ||
*/ | ||
Point pagePoint; | ||
|
||
/* | ||
* The coordinate of point relative to the target component in points. | ||
*/ | ||
Point offsetPoint; | ||
|
||
/* | ||
* The coordinate of point relative to the screen component in points. | ||
*/ | ||
Point screenPoint; | ||
|
||
/* | ||
* An identification number for each touch point. | ||
*/ | ||
int identifier; | ||
|
||
/* | ||
* The tag of a component on which the touch point started when it was first | ||
* placed on the surface, even if the touch point has since moved outside the | ||
* interactive area of that element. | ||
*/ | ||
Tag target; | ||
|
||
/* | ||
* The force of the touch. | ||
*/ | ||
Float force; | ||
|
||
/* | ||
* The time in seconds when the touch occurred or when it was last mutated. | ||
*/ | ||
Float timestamp; | ||
|
||
/* | ||
* The particular implementation of `Hasher` and (especially) `Comparator` | ||
* make sense only when `Touch` object is used as a *key* in indexed | ||
* collections. Because of that they are expressed as separate classes. | ||
*/ | ||
struct Hasher { | ||
size_t operator()(BaseTouch const &touch) const { | ||
return std::hash<decltype(touch.identifier)>()(touch.identifier); | ||
} | ||
}; | ||
|
||
struct Comparator { | ||
bool operator()(BaseTouch const &lhs, BaseTouch const &rhs) const { | ||
return lhs.identifier == rhs.identifier; | ||
} | ||
}; | ||
}; | ||
|
||
void setTouchPayloadOnObject( | ||
jsi::Object &object, | ||
jsi::Runtime &runtime, | ||
BaseTouch const &touch); | ||
|
||
#if RN_DEBUG_STRING_CONVERTIBLE | ||
|
||
std::string getDebugName(BaseTouch const &touch); | ||
std::vector<DebugStringConvertibleObject> getDebugProps( | ||
BaseTouch const &touch, | ||
DebugStringConvertibleOptions options); | ||
|
||
#endif | ||
|
||
} // namespace facebook::react |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...derer/components/view/platform/android/react/renderer/components/view/HostPlatformTouch.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <react/renderer/components/view/BaseTouch.h> | ||
|
||
namespace facebook::react { | ||
using HostPlatformTouch = BaseTouch; | ||
} // namespace facebook::react |
14 changes: 14 additions & 0 deletions
14
.../renderer/components/view/platform/cxx/react/renderer/components/view/HostPlatformTouch.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <react/renderer/components/view/BaseTouch.h> | ||
|
||
namespace facebook::react { | ||
using HostPlatformTouch = BaseTouch; | ||
} // namespace facebook::react |