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,29 @@
#include "RNSScreenRemovalListener.h"
#include <react/renderer/mounting/ShadowViewMutation.h>
using namespace facebook::react;
std::optional<MountingTransaction> RNSScreenRemovalListener::pullTransaction(
SurfaceId surfaceId,
MountingTransaction::Number transactionNumber,
const TransactionTelemetry &telemetry,
ShadowViewMutationList mutations) const {
for (const ShadowViewMutation &mutation : mutations) {
// When using RNSModalScreen on Android it should be added here.
if (mutation.type == ShadowViewMutation::Type::Remove &&
mutation.oldChildShadowView.componentName != nullptr &&
std::strcmp(mutation.oldChildShadowView.componentName, "RNSScreen") ==
0) {
// We call the listener function even if this screen has not been owned
// by RNSScreenStack as since RN 0.78 we do not have enough information
// here. This final filter is applied later in NativeProxy.
listenerFunction_(mutation.oldChildShadowView.tag);
}
}
return MountingTransaction{
surfaceId, transactionNumber, std::move(mutations), telemetry};
}
bool RNSScreenRemovalListener::shouldOverridePullTransaction() const {
return true;
}

View File

@@ -0,0 +1,20 @@
#pragma once
#include <react/renderer/componentregistry/ComponentDescriptorFactory.h>
#include <react/renderer/mounting/MountingOverrideDelegate.h>
#include <react/renderer/mounting/ShadowView.h>
using namespace facebook::react;
struct RNSScreenRemovalListener : public MountingOverrideDelegate {
std::function<void(int)> listenerFunction_;
RNSScreenRemovalListener(std::function<void(int)> &&listenerFunction_)
: listenerFunction_(std::move(listenerFunction_)) {}
bool shouldOverridePullTransaction() const override;
std::optional<MountingTransaction> pullTransaction(
SurfaceId surfaceId,
MountingTransaction::Number number,
const TransactionTelemetry &telemetry,
ShadowViewMutationList mutations) const override;
};

View File

@@ -0,0 +1,115 @@
#include "RNScreensTurboModule.h"
using namespace facebook;
namespace RNScreens {
const char RNScreensTurboModule::MODULE_NAME[] = "RNScreensTurboModule";
std::function<std::array<int, 2>(int)> RNScreensTurboModule::startTransition_;
std::function<void(int, double)> RNScreensTurboModule::updateTransition_;
std::function<void(int, bool)> RNScreensTurboModule::finishTransition_;
std::function<void(int)> RNScreensTurboModule::disableSwipeBackForTopScreen_;
RNScreensTurboModule::RNScreensTurboModule(
std::function<std::array<int, 2>(int)> startTransition,
std::function<void(int, double)> updateTransition,
std::function<void(int, bool)> finishTransition,
std::function<void(int)> disableSwipeBackForTopScreen) {
startTransition_ = startTransition;
updateTransition_ = updateTransition;
finishTransition_ = finishTransition;
disableSwipeBackForTopScreen_ = disableSwipeBackForTopScreen;
}
RNScreensTurboModule::~RNScreensTurboModule() {};
jsi::Value RNScreensTurboModule::get(
jsi::Runtime &rt,
const jsi::PropNameID &name) {
if (name.utf8(rt) == "startTransition") {
return jsi::Function::createFromHostFunction(rt, name, 1, startTransition);
} else if (name.utf8(rt) == "updateTransition") {
return jsi::Function::createFromHostFunction(rt, name, 2, updateTransition);
} else if (name.utf8(rt) == "finishTransition") {
return jsi::Function::createFromHostFunction(rt, name, 2, finishTransition);
} else if (name.utf8(rt) == "disableSwipeBackForTopScreen") {
return jsi::Function::createFromHostFunction(
rt, name, 1, disableSwipeBackForTopScreen);
}
return jsi::Value::undefined();
}
void RNScreensTurboModule::set(
jsi::Runtime &,
const jsi::PropNameID &,
const jsi::Value &) {};
std::vector<jsi::PropNameID> RNScreensTurboModule::getPropertyNames(
jsi::Runtime &rt) {
std::vector<jsi::PropNameID> properties;
properties.push_back(jsi::PropNameID::forUtf8(rt, "startTransition"));
properties.push_back(jsi::PropNameID::forUtf8(rt, "updateTransition"));
properties.push_back(jsi::PropNameID::forUtf8(rt, "finishTransition"));
properties.push_back(
jsi::PropNameID::forUtf8(rt, "disableSwipeBackForTopScreen"));
return properties;
}
JSI_HOST_FUNCTION(RNScreensTurboModule::startTransition) {
if (count < 1) {
throw jsi::JSError(
rt, "[RNScreens] `startTransition` method requires 1 argument.");
}
int stackTag = arguments[0].asNumber();
auto screenTags = startTransition_(stackTag);
jsi::Object screenTagsObject(rt);
jsi::Value topScreenTag, belowTopScreenTag, canStartTransition;
if (screenTags[0] > -1) {
topScreenTag = jsi::Value(screenTags[0]);
belowTopScreenTag = jsi::Value(screenTags[1]);
canStartTransition = jsi::Value(true);
} else {
topScreenTag = jsi::Value(-1);
belowTopScreenTag = jsi::Value(-1);
canStartTransition = jsi::Value(false);
}
screenTagsObject.setProperty(rt, "topScreenTag", topScreenTag);
screenTagsObject.setProperty(rt, "belowTopScreenTag", belowTopScreenTag);
screenTagsObject.setProperty(rt, "canStartTransition", canStartTransition);
return screenTagsObject;
}
JSI_HOST_FUNCTION(RNScreensTurboModule::updateTransition) {
if (count < 2) {
throw jsi::JSError(
rt, "[RNScreens] `updateTransition` requires 2 arguments.");
}
int stackTag = arguments[0].asNumber();
double progress = arguments[1].asNumber();
updateTransition_(stackTag, progress);
return jsi::Value::undefined();
}
JSI_HOST_FUNCTION(RNScreensTurboModule::finishTransition) {
if (count < 2) {
throw jsi::JSError(
rt, "[RNScreens] `finishTransition` requires 2 arguments.");
}
int stackTag = arguments[0].asNumber();
bool canceled = arguments[1].getBool();
finishTransition_(stackTag, canceled);
return jsi::Value::undefined();
}
JSI_HOST_FUNCTION(RNScreensTurboModule::disableSwipeBackForTopScreen) {
if (count < 1) {
throw jsi::JSError(
rt, "[RNScreens] `startTransition` method requires 1 argument.");
}
int stackTag = arguments[0].asNumber();
disableSwipeBackForTopScreen_(stackTag);
return jsi::Value::undefined();
}
} // namespace RNScreens

View File

@@ -0,0 +1,47 @@
#pragma once
// Needed on Paper only to hide the files from Swift build process
#if defined(__cplusplus)
#include <jsi/jsi.h>
#include <array>
#define JSI_HOST_FUNCTION(NAME) \
jsi::Value NAME( \
jsi::Runtime &rt, \
const jsi::Value &thisValue, \
const jsi::Value *arguments, \
size_t count)
using namespace facebook;
namespace RNScreens {
class RNScreensTurboModule : public jsi::HostObject {
static std::function<std::array<int, 2>(int)> startTransition_;
static std::function<void(int, double)> updateTransition_;
static std::function<void(int, bool)> finishTransition_;
static std::function<void(int)> disableSwipeBackForTopScreen_;
public:
static const char MODULE_NAME[];
RNScreensTurboModule(
std::function<std::array<int, 2>(int)> startTransition,
std::function<void(int, double)> updateTransition,
std::function<void(int, bool)> finishTransition,
std::function<void(int)> disableSwipeBackForTopScreen);
~RNScreensTurboModule() override;
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &name) override;
void set(jsi::Runtime &, const jsi::PropNameID &, const jsi::Value &)
override;
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
static JSI_HOST_FUNCTION(startTransition);
static JSI_HOST_FUNCTION(updateTransition);
static JSI_HOST_FUNCTION(finishTransition);
static JSI_HOST_FUNCTION(disableSwipeBackForTopScreen);
};
} // namespace RNScreens
#endif // __cplusplus