Move rncxx coremodules

Summary: Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D72875329

fbshipit-source-id: 86578362f99210dbe8aa990991829760fa61daf8
This commit is contained in:
Andrew Datsenko
2025-04-16 09:53:18 -07:00
committed by Facebook GitHub Bot
parent 706b6e878d
commit 929099f064
6 changed files with 250 additions and 0 deletions
@@ -0,0 +1,28 @@
/*
* 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 "AppStateModule.h"
namespace facebook::react {
AppStateConstants AppStateModule::getConstants(jsi::Runtime& /*rt*/) {
// TODO: T160890586 Wire up AppState implementation to use real data
return AppStateConstants{.initialAppState = ""};
}
void AppStateModule::getCurrentAppState(
jsi::Runtime& /*rt*/,
const AsyncCallback<AppState>& /*success*/,
jsi::Function /*error*/) {}
void AppStateModule::addListener(
jsi::Runtime& /*rt*/,
const std::string& /*eventName*/) {}
void AppStateModule::removeListeners(jsi::Runtime& /*rt*/, double /*count*/) {}
} // namespace facebook::react
@@ -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 <FBReactNativeSpec/FBReactNativeSpecJSI.h>
#include <memory>
#include <string>
namespace facebook::react {
using AppStateConstants = NativeAppStateAppStateConstants<std::string>;
template <>
struct Bridging<AppStateConstants>
: NativeAppStateAppStateConstantsBridging<AppStateConstants> {};
using AppState = NativeAppStateAppState<std::string>;
template <>
struct Bridging<AppState> : NativeAppStateAppStateBridging<AppState> {};
class AppStateModule : public NativeAppStateCxxSpec<AppStateModule> {
public:
explicit AppStateModule(std::shared_ptr<CallInvoker> jsInvoker)
: NativeAppStateCxxSpec(jsInvoker) {}
AppStateConstants getConstants(jsi::Runtime& rt);
void getCurrentAppState(
jsi::Runtime& rt,
const AsyncCallback<AppState>& success,
jsi::Function error);
void addListener(jsi::Runtime& rt, const std::string& eventName);
void removeListeners(jsi::Runtime& rt, double count);
};
} // namespace facebook::react
@@ -0,0 +1,25 @@
/*
* 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 "DeviceInfoModule.h"
namespace facebook::react {
DeviceInfoConstants DeviceInfoModule::getConstants(jsi::Runtime& /*rt*/) {
// TODO: Wire this to come from the actual app
// size (T161837708)
return DeviceInfoConstants{
.Dimensions =
{.window =
DisplayMetrics{
1280,
720,
}},
};
}
} // namespace facebook::react
@@ -0,0 +1,58 @@
/*
* 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 <FBReactNativeSpec/FBReactNativeSpecJSI.h>
#include <optional>
namespace facebook::react {
using DisplayMetrics =
NativeDeviceInfoDisplayMetrics<double, double, double, double>;
using DisplayMetricsAndroid = NativeDeviceInfoDisplayMetricsAndroid<
double,
double,
double,
double,
double>;
using DimensionsPayload = NativeDeviceInfoDimensionsPayload<
std::optional<DisplayMetrics>,
std::optional<DisplayMetrics>,
std::optional<DisplayMetricsAndroid>,
std::optional<DisplayMetricsAndroid>>;
using DeviceInfoConstants =
NativeDeviceInfoDeviceInfoConstants<DimensionsPayload, std::optional<bool>>;
template <>
struct Bridging<DisplayMetrics>
: NativeDeviceInfoDisplayMetricsBridging<DisplayMetrics> {};
template <>
struct Bridging<DisplayMetricsAndroid>
: NativeDeviceInfoDisplayMetricsAndroidBridging<DisplayMetricsAndroid> {};
template <>
struct Bridging<DimensionsPayload>
: NativeDeviceInfoDimensionsPayloadBridging<DimensionsPayload> {};
template <>
struct Bridging<DeviceInfoConstants>
: NativeDeviceInfoDeviceInfoConstantsBridging<DeviceInfoConstants> {};
class DeviceInfoModule : public NativeDeviceInfoCxxSpec<DeviceInfoModule> {
public:
explicit DeviceInfoModule(std::shared_ptr<CallInvoker> jsInvoker)
: NativeDeviceInfoCxxSpec(jsInvoker) {}
DeviceInfoConstants getConstants(jsi::Runtime& rt);
};
} // namespace facebook::react
@@ -0,0 +1,35 @@
/*
* 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 "PlatformConstantsModule.h"
namespace facebook::react {
PlatformConstantsAndroid PlatformConstantsModule::getConstants(
jsi::Runtime& /*rt*/) {
return PlatformConstantsAndroid{
.isTesting = false,
.isDisableAnimations = false,
.reactNativeVersion =
{
.major = 1000,
.minor = 0,
.patch = 0,
.prerelease = std::nullopt,
},
.Version = 33, // Android 13 (API level 33)
.Release = "",
.Fingerprint = "",
.Model = "",
.ServerHost = "",
.uiMode = "",
.Brand = "",
.Manufacturer = "",
};
}
} // namespace facebook::react
@@ -0,0 +1,61 @@
/*
* 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 <FBReactNativeSpec/FBReactNativeSpecJSI.h>
#include <optional>
namespace facebook::react {
using ReactNativeVersionAndroid =
NativePlatformConstantsAndroidReactNativeVersionAndroid<
int,
int,
int,
std::optional<int>>;
template <>
struct Bridging<ReactNativeVersionAndroid>
: NativePlatformConstantsAndroidReactNativeVersionAndroidBridging<
ReactNativeVersionAndroid> {};
using PlatformConstantsAndroid =
NativePlatformConstantsAndroidPlatformConstantsAndroid<
bool,
std::optional<bool>,
ReactNativeVersionAndroid,
int,
std::string,
std::string,
std::string,
std::string,
std::optional<std::string>,
std::string,
std::string,
std::string>;
template <>
struct Bridging<PlatformConstantsAndroid>
: NativePlatformConstantsAndroidPlatformConstantsAndroidBridging<
PlatformConstantsAndroid> {};
// T159303412: [RN] Metro: Need support for new target platform
class PlatformConstantsModule
: public NativePlatformConstantsAndroidCxxSpec<PlatformConstantsModule> {
public:
explicit PlatformConstantsModule(std::shared_ptr<CallInvoker> jsInvoker)
: NativePlatformConstantsAndroidCxxSpec(jsInvoker) {}
std::string getAndroidID(jsi::Runtime& /*rt*/) {
return "";
}
PlatformConstantsAndroid getConstants(jsi::Runtime& rt);
};
} // namespace facebook::react