Skip to content

Commit

Permalink
Create option for out-of-tree platforms to customize ViewEventEmitter (
Browse files Browse the repository at this point in the history
…facebook#38582)

Summary:
Pull Request resolved: facebook#38582

Some out of tree platforms may have extra events (e.g., events for different input modalities) that don't exist on other platforms.

For example, react-native-windows and react-native-macos have `onKeyUp` and `onKeyDown` that can be emitted from any native component.

This change provides a hook for out of platforms to customize which events can be emitted from all native components.

## Changelog:
[General] [Added] - Support additional View events in out of tree platform Fabric implementations

Reviewed By: christophpurrer

Differential Revision: D47721603

fbshipit-source-id: 8ac5b4c26d738bf47c57cce6e1a437454de4253d
  • Loading branch information
rozele authored and facebook-github-bot committed Jul 26, 2023
1 parent dfd1be5 commit 9d7c7d7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,36 @@
* LICENSE file in the root directory of this source tree.
*/

#include "ViewEventEmitter.h"
#include "BaseViewEventEmitter.h"

namespace facebook::react {

#pragma mark - Accessibility

void ViewEventEmitter::onAccessibilityAction(std::string const &name) const {
void BaseViewEventEmitter::onAccessibilityAction(
std::string const &name) const {
dispatchEvent("accessibilityAction", [name](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "actionName", name);
return payload;
});
}

void ViewEventEmitter::onAccessibilityTap() const {
void BaseViewEventEmitter::onAccessibilityTap() const {
dispatchEvent("accessibilityTap");
}

void ViewEventEmitter::onAccessibilityMagicTap() const {
void BaseViewEventEmitter::onAccessibilityMagicTap() const {
dispatchEvent("magicTap");
}

void ViewEventEmitter::onAccessibilityEscape() const {
void BaseViewEventEmitter::onAccessibilityEscape() const {
dispatchEvent("accessibilityEscape");
}

#pragma mark - Layout

void ViewEventEmitter::onLayout(const LayoutMetrics &layoutMetrics) const {
void BaseViewEventEmitter::onLayout(const LayoutMetrics &layoutMetrics) const {
// A copy of a shared pointer (`layoutEventState_`) establishes shared
// ownership that will be captured by lambda.
auto layoutEventState = layoutEventState_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@

namespace facebook::react {

class ViewEventEmitter;

using SharedViewEventEmitter = std::shared_ptr<const ViewEventEmitter>;

class ViewEventEmitter : public TouchEventEmitter {
class BaseViewEventEmitter : public TouchEventEmitter {
public:
using TouchEventEmitter::TouchEventEmitter;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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/BaseViewEventEmitter.h>

namespace facebook::react {
using ViewEventEmitter = BaseViewEventEmitter;
using SharedViewEventEmitter = std::shared_ptr<const ViewEventEmitter>;
} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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/BaseViewEventEmitter.h>

namespace facebook::react {
using ViewEventEmitter = BaseViewEventEmitter;
using SharedViewEventEmitter = std::shared_ptr<const ViewEventEmitter>;
} // namespace facebook::react

0 comments on commit 9d7c7d7

Please sign in to comment.