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

More consistent platform for out-of-tree platform extensions #38703

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ header_search_paths = [
"$(PODS_ROOT)/Headers/Public/hermes-engine"
] : []).concat(use_frameworks ? [
"$(PODS_CONFIGURATION_BUILD_DIR)/React-Fabric/React_Fabric.framework/Headers/",
"$(PODS_CONFIGURATION_BUILD_DIR)/React-Fabric/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx/",
"$(PODS_CONFIGURATION_BUILD_DIR)/React-graphics/React_graphics.framework/Headers/",
"$(PODS_CONFIGURATION_BUILD_DIR)/React-graphics/React_graphics.framework/Headers/react/renderer/graphics/platform/ios",
"$(PODS_CONFIGURATION_BUILD_DIR)/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core",
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/React/React-RCTFabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ if ENV['USE_FRAMEWORKS']
header_search_paths << "\"${PODS_CONFIGURATION_BUILD_DIR}/React-FabricImage/React_FabricImage.framework/Headers\""
header_search_paths << "\"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/textlayoutmanager/platform/ios\""
header_search_paths << "\"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/components/textinput/iostextinput\""
header_search_paths << "\"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx\""
header_search_paths << "\"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/imagemanager/platform/ios\""
header_search_paths << "\"${PODS_CONFIGURATION_BUILD_DIR}/React-nativeconfig/React_nativeconfig.framework/Headers\""
header_search_paths << "\"${PODS_CONFIGURATION_BUILD_DIR}/React-graphics/React_graphics.framework/Headers\""
Expand Down
5 changes: 4 additions & 1 deletion packages/react-native/ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa
),
new PrefabPreprocessingEntry(
"rrc_view",
new Pair("../ReactCommon/react/renderer/components/view/", "react/renderer/components/view/")
[
new Pair("../ReactCommon/react/renderer/components/view/", "react/renderer/components/view/"),
new Pair("../ReactCommon/react/renderer/components/view/platform/android/", ""),
]
),
new PrefabPreprocessingEntry(
"rrc_legacyviewmanagerinterop",
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native/ReactCommon/React-Fabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Pod::Spec.new do |s|
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-rendererdebug/React_rendererdebug.framework/Headers/\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/textlayoutmanager/platform/ios\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/textinput/iostextinput\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/view/platform/cxx\"",
]
end

Expand Down Expand Up @@ -224,7 +225,7 @@ Pod::Spec.new do |s|
sss.dependency "Yoga"
sss.compiler_flags = folly_compiler_flags
sss.source_files = "react/renderer/components/view/**/*.{m,mm,cpp,h}"
sss.exclude_files = "react/renderer/components/view/tests"
sss.exclude_files = "react/renderer/components/view/tests", "react/renderer/components/view/platform/android"
sss.header_dir = "react/renderer/components/view"
sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Headers/Private/Yoga\"" }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if ENV['USE_FRAMEWORKS']
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-Codegen/React_Codegen.framework/Headers\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-graphics/React_graphics.framework/Headers/react/renderer/graphics/platform/ios\"",
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/imagemanager/platform/ios\"",
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/textlayoutmanager/platform/ios\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/textinput/iostextinput\"",
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,30 @@

namespace facebook::react {

void setTouchPayloadOnObject(
jsi::Object &object,
jsi::Runtime &runtime,
BaseTouch const &touch) {
object.setProperty(runtime, "locationX", touch.offsetPoint.x);
object.setProperty(runtime, "locationY", touch.offsetPoint.y);
object.setProperty(runtime, "pageX", touch.pagePoint.x);
object.setProperty(runtime, "pageY", touch.pagePoint.y);
object.setProperty(runtime, "screenX", touch.screenPoint.x);
object.setProperty(runtime, "screenY", touch.screenPoint.y);
object.setProperty(runtime, "identifier", touch.identifier);
object.setProperty(runtime, "target", touch.target);
object.setProperty(runtime, "timestamp", touch.timestamp * 1000);
object.setProperty(runtime, "force", touch.force);
}

#if RN_DEBUG_STRING_CONVERTIBLE

std::string getDebugName(Touch const & /*touch*/) {
std::string getDebugName(BaseTouch const & /*touch*/) {
return "Touch";
}

std::vector<DebugStringConvertibleObject> getDebugProps(
Touch const &touch,
BaseTouch const &touch,
DebugStringConvertibleOptions options) {
return {
{"pagePoint", getDebugDescription(touch.pagePoint, options)},
Expand Down
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
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
@@ -0,0 +1,67 @@
/*
* 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 <memory>
#include <mutex>

#include <react/renderer/core/LayoutMetrics.h>
#include <react/renderer/core/ReactPrimitives.h>

#include "TouchEventEmitter.h"

namespace facebook::react {

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

#pragma mark - Accessibility

void onAccessibilityAction(std::string const &name) const;
void onAccessibilityTap() const;
void onAccessibilityMagicTap() const;
void onAccessibilityEscape() const;

#pragma mark - Layout

void onLayout(const LayoutMetrics &layoutMetrics) const;

private:
/*
* Contains the most recent `frame` and a `mutex` protecting access to it.
*/
struct LayoutEventState {
/*
* Protects an access to other fields of the struct.
*/
std::mutex mutex;

/*
* Last dispatched `frame` value or value that's being dispatched right now.
*/
Rect frame{};

/*
* Indicates that the `frame` value was already dispatched (and dispatching
* of the *same* value is not needed).
*/
bool wasDispatched{false};

/*
* Indicates that some lambda is already being dispatching (and dispatching
* another one is not needed).
*/
bool isDispatching{false};
};

mutable std::shared_ptr<LayoutEventState> layoutEventState_{
std::make_shared<LayoutEventState>()};
};

} // namespace facebook::react
Loading