first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
# 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.
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)
include(${REACT_COMMON_DIR}/cmake-utils/internal/react-native-platform-selector.cmake)
include(${REACT_COMMON_DIR}/cmake-utils/react-native-flags.cmake)
react_native_android_selector(platform_SRC
platform/android/*.cpp
platform/cxx/*.cpp)
file(GLOB rrc_modal_SRC CONFIGURE_DEPENDS
*.cpp
${platform_SRC})
add_library(rrc_modal STATIC ${rrc_modal_SRC})
target_include_directories(rrc_modal PUBLIC ${REACT_COMMON_DIR})
target_link_libraries(rrc_modal
glog
folly_runtime
glog_init
react_codegen_rncore
react_renderer_componentregistry
react_renderer_core
react_renderer_debug
react_renderer_graphics
react_renderer_imagemanager
react_renderer_uimanager
rrc_image
rrc_view
yoga
)
target_compile_reactnative_options(rrc_modal PRIVATE)
target_compile_options(rrc_modal PRIVATE -Wpedantic)

View File

@@ -0,0 +1,48 @@
/*
* 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 "ModalHostViewComponentDescriptor.h"
namespace facebook::react {
#ifdef ANDROID
State::Shared ModalHostViewComponentDescriptor::createInitialState(
const Props::Shared& props,
const ShadowNodeFamily::Shared& family) const {
// For Android, we need to get the size of the screen without the vertical
// insets to correctly position the modal on the first rendering.
// For this reason we provide the `createInitialState` implementation
// that will query FabricUIManager for the size of the screen without
// vertical insets.
int surfaceId = family->getSurfaceId();
const jni::global_ref<jobject>& fabricUIManager =
contextContainer_->at<jni::global_ref<jobject>>("FabricUIManager");
static auto getEncodedScreenSizeWithoutVerticalInsets =
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<jlong(jint)>("getEncodedScreenSizeWithoutVerticalInsets");
auto result =
getEncodedScreenSizeWithoutVerticalInsets(fabricUIManager, surfaceId);
// Inspired from yogaMeasureToSize from conversions.h
int32_t wBits = 0xFFFFFFFF & (result >> 32);
int32_t hBits = 0xFFFFFFFF & result;
auto* measuredWidth = reinterpret_cast<float*>(&wBits);
auto* measuredHeight = reinterpret_cast<float*>(&hBits);
return std::make_shared<ModalHostViewShadowNode::ConcreteState>(
std::make_shared<const ModalHostViewState>(ModalHostViewState(
Size{.width = *measuredWidth, .height = *measuredHeight})),
family);
}
#endif // ANDROID
} // namespace facebook::react

View File

@@ -0,0 +1,43 @@
/*
* 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 <glog/logging.h>
#include <react/renderer/components/modal/ModalHostViewShadowNode.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h>
namespace facebook::react {
/*
* Descriptor for <ModalHostView> component.
*/
class ModalHostViewComponentDescriptor final : public ConcreteComponentDescriptor<ModalHostViewShadowNode> {
public:
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
void adopt(ShadowNode &shadowNode) const override
{
auto &layoutableShadowNode = static_cast<YogaLayoutableShadowNode &>(shadowNode);
auto &stateData = static_cast<const ModalHostViewShadowNode::ConcreteState &>(*shadowNode.getState()).getData();
layoutableShadowNode.setSize(Size{.width = stateData.screenSize.width, .height = stateData.screenSize.height});
layoutableShadowNode.setPositionType(YGPositionTypeAbsolute);
ConcreteComponentDescriptor::adopt(shadowNode);
}
#ifdef ANDROID
State::Shared createInitialState(const Props::Shared &props, const ShadowNodeFamily::Shared &family) const override;
#endif // ANDROID
private:
constexpr static auto UIManagerJavaDescriptor = "com/facebook/react/fabric/FabricUIManager";
};
} // namespace facebook::react

View File

@@ -0,0 +1,17 @@
/*
* 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 "ModalHostViewShadowNode.h"
#include <react/renderer/components/modal/ModalHostViewShadowNode.h>
#include <react/renderer/core/LayoutContext.h>
namespace facebook::react {
extern const char ModalHostViewComponentName[] = "ModalHostView";
} // namespace facebook::react

View File

@@ -0,0 +1,41 @@
/*
* 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/FBReactNativeSpec/EventEmitters.h>
#include <react/renderer/components/FBReactNativeSpec/Props.h>
#include <react/renderer/components/modal/ModalHostViewState.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
namespace facebook::react {
extern const char ModalHostViewComponentName[];
/*
* `ShadowNode` for <ModalHostView> component.
*/
class ModalHostViewShadowNode final : public ConcreteViewShadowNode<
ModalHostViewComponentName,
ModalHostViewProps,
ModalHostViewEventEmitter,
ModalHostViewState> {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;
static ShadowNodeTraits BaseTraits()
{
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(ShadowNodeTraits::Trait::RootNodeKind);
// <Modal> has a side effect of showing the modal overlay and
// must not be culled. Otherwise, the modal overlay will not be shown.
traits.set(ShadowNodeTraits::Trait::Unstable_uncullableView);
return traits;
}
};
} // namespace facebook::react

View File

@@ -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 "ModalHostViewState.h"
namespace facebook::react {
#ifdef RN_SERIALIZABLE_STATE
folly::dynamic ModalHostViewState::getDynamic() const {
return folly::dynamic::object("screenWidth", screenSize.width)(
"screenHeight", screenSize.height);
}
#endif
} // namespace facebook::react

View File

@@ -0,0 +1,46 @@
/*
* 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/graphicsConversions.h>
#include <react/renderer/graphics/Float.h>
#include "ModalHostViewUtils.h"
#ifdef RN_SERIALIZABLE_STATE
#include <folly/dynamic.h>
#endif
namespace facebook::react {
/*
* State for <ModalHostView> component.
*/
class ModalHostViewState final {
public:
using Shared = std::shared_ptr<const ModalHostViewState>;
ModalHostViewState() : screenSize(ModalHostViewScreenSize()) {}
ModalHostViewState(Size screenSize_) : screenSize(screenSize_) {};
#ifdef RN_SERIALIZABLE_STATE
ModalHostViewState(const ModalHostViewState &previousState, folly::dynamic data)
: screenSize(
Size{.width = (Float)data["screenWidth"].getDouble(), .height = (Float)data["screenHeight"].getDouble()}) {
};
#endif
const Size screenSize{};
#ifdef RN_SERIALIZABLE_STATE
folly::dynamic getDynamic() const;
#endif
#pragma mark - Getters
};
} // namespace facebook::react

View File

@@ -0,0 +1,16 @@
/*
* 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/graphics/Size.h>
namespace facebook::react {
Size ModalHostViewScreenSize(void);
} // namespace facebook::react

View File

@@ -0,0 +1,20 @@
/*
* 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.
*/
#import "ModalHostViewUtils.h"
#import <Foundation/Foundation.h>
#import <React/RCTUtils.h>
namespace facebook::react {
Size ModalHostViewScreenSize(void)
{
CGSize screenSize = RCTScreenSize();
return {.width = screenSize.width, .height = screenSize.height};
}
} // namespace facebook::react

View File

@@ -0,0 +1,17 @@
/*
* 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 <react/renderer/components/modal/ModalHostViewUtils.h>
#include <react/renderer/graphics/Size.h>
namespace facebook::react {
Size ModalHostViewScreenSize() {
return Size{.width = 0, .height = 0};
}
} // namespace facebook::react

View File

@@ -0,0 +1,17 @@
/*
* 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 <react/renderer/components/modal/ModalHostViewUtils.h>
#include <react/renderer/graphics/Size.h>
namespace facebook::react {
Size ModalHostViewScreenSize() {
return Size{0, 0};
}
} // namespace facebook::react