-
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.
Refactor event pipeline to accept typed event payloads (#38276)
Summary: Pull Request resolved: #38276 Changelog: [Internal] Refactor Fabric event pipeline to accept typed event payloads As a first step towards my project of managing the Pointer Capture API by intercepting events in UIManagerBinding I need infrastructure to be able to safely & efficently read the properties of the event payload which is what this diff lays the ground work of addressing. Currently the events are passed from the EventEmitter all the way to UIManagerBinding with only a ValueFactory (std::function lambda) which is called to produce the jsi::Value. My diff introduces a new virtual base class, EventPayload, which provides the same functionality but in a member function, asJSIValue. To ease the transition to this new paradigm I also introduce the first concrete subclass of EventPayload: ValueFactoryEventPayload — which simply stores and calls a ValueFactory so that we can incrementally migrate to typed events (or frankly, continue to be used for events that we don't *need* to be typed, as the only real use-case in the beginning will be for Pointer Events). This diff notably does not change any behavior and should behave the exact same way it did before — it is in later diffs where I will begin applying this to the pointer events. Differential Revision: D47299631 fbshipit-source-id: a97e5c2c3397cda83cf151d98324c8c1534ffc5b
- Loading branch information
1 parent
28dfdb2
commit 8cb965b
Showing
13 changed files
with
102 additions
and
22 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
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
29 changes: 29 additions & 0 deletions
29
packages/react-native/ReactCommon/react/renderer/core/EventPayload.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,29 @@ | ||
/* | ||
* 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> | ||
|
||
namespace facebook::react { | ||
|
||
/** | ||
* Abstract base class for all event payload types. | ||
*/ | ||
struct EventPayload { | ||
virtual ~EventPayload() = default; | ||
|
||
EventPayload() = default; | ||
EventPayload(const EventPayload &) = default; | ||
EventPayload &operator=(const EventPayload &) = default; | ||
EventPayload(EventPayload &&) = default; | ||
EventPayload &operator=(EventPayload &&) = default; | ||
|
||
virtual jsi::Value asJSIValue(jsi::Runtime &runtime) const = 0; | ||
}; | ||
|
||
} // 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
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
19 changes: 19 additions & 0 deletions
19
packages/react-native/ReactCommon/react/renderer/core/ValueFactoryEventPayload.cpp
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,19 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "ValueFactoryEventPayload.h" | ||
|
||
namespace facebook::react { | ||
|
||
ValueFactoryEventPayload::ValueFactoryEventPayload(ValueFactory factory) | ||
: valueFactory_(std::move(factory)) {} | ||
|
||
jsi::Value ValueFactoryEventPayload::asJSIValue(jsi::Runtime &runtime) const { | ||
return valueFactory_(runtime); | ||
} | ||
|
||
} // namespace facebook::react |
24 changes: 24 additions & 0 deletions
24
packages/react-native/ReactCommon/react/renderer/core/ValueFactoryEventPayload.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,24 @@ | ||
/* | ||
* 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/core/EventPayload.h> | ||
#include <react/renderer/core/ValueFactory.h> | ||
|
||
namespace facebook::react { | ||
|
||
class ValueFactoryEventPayload : public EventPayload { | ||
public: | ||
explicit ValueFactoryEventPayload(ValueFactory factory); | ||
jsi::Value asJSIValue(jsi::Runtime &runtime) const override; | ||
|
||
private: | ||
ValueFactory valueFactory_; | ||
}; | ||
|
||
} // 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
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