Skip to content

Commit

Permalink
chore: add formatting of all cpp (#2138)
Browse files Browse the repository at this point in the history
PR adding formatting of all cpp codebase.
  • Loading branch information
WoLewicki committed May 17, 2024
1 parent 07ce6f5 commit 3bde622
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 179 deletions.
179 changes: 86 additions & 93 deletions android/src/main/cpp/jni-adapter.cpp
Original file line number Diff line number Diff line change
@@ -1,110 +1,103 @@
#include <array>
#include <mutex>
#include <jni.h>
#include <jsi/jsi.h>
#include <array>
#include <mutex>
#include "RNScreensTurboModule.h"

using namespace facebook;

jobject globalThis;

extern "C"
JNIEXPORT void JNICALL
Java_com_swmansion_rnscreens_ScreensModule_nativeInstall(JNIEnv *env, jobject thiz, jlong jsiPtr) {
auto runtime = reinterpret_cast<jsi::Runtime*>(jsiPtr);
if (!runtime) {
return;
}
jsi::Runtime &rt = *runtime;
globalThis = env->NewGlobalRef(thiz);
JavaVM* jvm;
env->GetJavaVM(&jvm);
extern "C" JNIEXPORT void JNICALL
Java_com_swmansion_rnscreens_ScreensModule_nativeInstall(
JNIEnv *env,
jobject thiz,
jlong jsiPtr) {
auto runtime = reinterpret_cast<jsi::Runtime *>(jsiPtr);
if (!runtime) {
return;
}
jsi::Runtime &rt = *runtime;
globalThis = env->NewGlobalRef(thiz);
JavaVM *jvm;
env->GetJavaVM(&jvm);

const auto &startTransition = [jvm](int stackTag) -> std::array<int, 2> {
JNIEnv* currentEnv;
if (jvm->AttachCurrentThread(&currentEnv, nullptr) != JNI_OK) {
return {0, 0};
}
jclass javaClass = currentEnv->GetObjectClass(globalThis);
jmethodID methodID = currentEnv->GetMethodID(
javaClass,
"startTransition",
"(Ljava/lang/Integer;)[I"
);
jclass integerClass = currentEnv->FindClass("java/lang/Integer");
jmethodID integerConstructor = currentEnv->GetMethodID(integerClass, "<init>", "(I)V");
jobject integerArg = currentEnv->NewObject(integerClass, integerConstructor, stackTag);
jintArray resultArray = (jintArray) currentEnv->CallObjectMethod(
globalThis,
methodID,
integerArg
);
std::array<int, 2> result = {-1, -1};
jint* elements = currentEnv->GetIntArrayElements(resultArray, nullptr);
if (elements != nullptr) {
result[0] = elements[0];
result[1] = elements[1];
currentEnv->ReleaseIntArrayElements(resultArray, elements, JNI_ABORT);
}
return result;
};
const auto &startTransition = [jvm](int stackTag) -> std::array<int, 2> {
JNIEnv *currentEnv;
if (jvm->AttachCurrentThread(&currentEnv, nullptr) != JNI_OK) {
return {0, 0};
}
jclass javaClass = currentEnv->GetObjectClass(globalThis);
jmethodID methodID = currentEnv->GetMethodID(
javaClass, "startTransition", "(Ljava/lang/Integer;)[I");
jclass integerClass = currentEnv->FindClass("java/lang/Integer");
jmethodID integerConstructor =
currentEnv->GetMethodID(integerClass, "<init>", "(I)V");
jobject integerArg =
currentEnv->NewObject(integerClass, integerConstructor, stackTag);
jintArray resultArray = (jintArray)currentEnv->CallObjectMethod(
globalThis, methodID, integerArg);
std::array<int, 2> result = {-1, -1};
jint *elements = currentEnv->GetIntArrayElements(resultArray, nullptr);
if (elements != nullptr) {
result[0] = elements[0];
result[1] = elements[1];
currentEnv->ReleaseIntArrayElements(resultArray, elements, JNI_ABORT);
}
return result;
};

const auto &updateTransition = [jvm](int stackTag, double progress){
JNIEnv* currentEnv;
if (jvm->AttachCurrentThread(&currentEnv, nullptr) != JNI_OK) {
return;
}
jclass javaClass = currentEnv->GetObjectClass(globalThis);
jmethodID methodID = currentEnv->GetMethodID(
javaClass,
"updateTransition",
"(D)V"
);
currentEnv->CallVoidMethod(globalThis, methodID, progress);
};
const auto &updateTransition = [jvm](int stackTag, double progress) {
JNIEnv *currentEnv;
if (jvm->AttachCurrentThread(&currentEnv, nullptr) != JNI_OK) {
return;
}
jclass javaClass = currentEnv->GetObjectClass(globalThis);
jmethodID methodID =
currentEnv->GetMethodID(javaClass, "updateTransition", "(D)V");
currentEnv->CallVoidMethod(globalThis, methodID, progress);
};

const auto &finishTransition = [jvm](int stackTag, bool canceled){
JNIEnv* currentEnv;
if (jvm->AttachCurrentThread(&currentEnv, nullptr) != JNI_OK) {
return;
}
jclass javaClass = currentEnv->GetObjectClass(globalThis);
jmethodID methodID = currentEnv->GetMethodID(
javaClass,
"finishTransition",
"(Ljava/lang/Integer;Z)V"
);
jclass integerClass = currentEnv->FindClass("java/lang/Integer");
jmethodID integerConstructor = currentEnv->GetMethodID(integerClass, "<init>", "(I)V");
jobject integerArg = currentEnv->NewObject(integerClass, integerConstructor, stackTag);
currentEnv->CallVoidMethod(globalThis, methodID, integerArg, canceled);
};
const auto &finishTransition = [jvm](int stackTag, bool canceled) {
JNIEnv *currentEnv;
if (jvm->AttachCurrentThread(&currentEnv, nullptr) != JNI_OK) {
return;
}
jclass javaClass = currentEnv->GetObjectClass(globalThis);
jmethodID methodID = currentEnv->GetMethodID(
javaClass, "finishTransition", "(Ljava/lang/Integer;Z)V");
jclass integerClass = currentEnv->FindClass("java/lang/Integer");
jmethodID integerConstructor =
currentEnv->GetMethodID(integerClass, "<init>", "(I)V");
jobject integerArg =
currentEnv->NewObject(integerClass, integerConstructor, stackTag);
currentEnv->CallVoidMethod(globalThis, methodID, integerArg, canceled);
};

const auto &disableSwipeBackForTopScreen = [](int _stackTag){
// no implementation for Android
};
const auto &disableSwipeBackForTopScreen = [](int _stackTag) {
// no implementation for Android
};

auto rnScreensModule = std::make_shared<RNScreens::RNScreensTurboModule>(
startTransition,
updateTransition,
finishTransition,
disableSwipeBackForTopScreen
);
auto rnScreensModuleHostObject = jsi::Object::createFromHostObject(rt, rnScreensModule);
rt.global().setProperty(
rt,
RNScreens::RNScreensTurboModule::MODULE_NAME,
std::move(rnScreensModuleHostObject)
);
auto rnScreensModule = std::make_shared<RNScreens::RNScreensTurboModule>(
startTransition,
updateTransition,
finishTransition,
disableSwipeBackForTopScreen);
auto rnScreensModuleHostObject =
jsi::Object::createFromHostObject(rt, rnScreensModule);
rt.global().setProperty(
rt,
RNScreens::RNScreensTurboModule::MODULE_NAME,
std::move(rnScreensModuleHostObject));
}

void JNICALL JNI_OnUnload(JavaVM *jvm, void *) {
JNIEnv *env;
if (jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
return;
}
if (globalThis != nullptr) {
env->DeleteGlobalRef(globalThis);
globalThis = nullptr;
}
JNIEnv *env;
if (jvm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) {
return;
}
if (globalThis != nullptr) {
env->DeleteGlobalRef(globalThis);
globalThis = nullptr;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <react/debug/react_native_assert.h>
#include "RNSModalScreenShadowNode.h"
#include <react/renderer/core/ConcreteComponentDescriptor.h>
#include "RNSModalScreenShadowNode.h"

namespace facebook {
namespace react {
Expand All @@ -12,16 +12,15 @@ class RNSModalScreenComponentDescriptor final
public:
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;

void adopt(ShadowNode& shadowNode) const override {
react_native_assert(
dynamic_cast<RNSModalScreenShadowNode*>(&shadowNode));
auto& screenShadowNode =
static_cast<RNSModalScreenShadowNode&>(shadowNode);
void adopt(ShadowNode &shadowNode) const override {
react_native_assert(dynamic_cast<RNSModalScreenShadowNode *>(&shadowNode));
auto &screenShadowNode =
static_cast<RNSModalScreenShadowNode &>(shadowNode);

react_native_assert(
dynamic_cast<YogaLayoutableShadowNode*>(&screenShadowNode));
auto& layoutableShadowNode =
dynamic_cast<YogaLayoutableShadowNode&>(screenShadowNode);
dynamic_cast<YogaLayoutableShadowNode *>(&screenShadowNode));
auto &layoutableShadowNode =
dynamic_cast<YogaLayoutableShadowNode &>(screenShadowNode);

auto state =
std::static_pointer_cast<const RNSModalScreenShadowNode::ConcreteState>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#pragma once

#include "RNSScreenState.h"
#include <jsi/jsi.h>
#include <react/renderer/components/rnscreens/EventEmitters.h>
#include <react/renderer/components/rnscreens/Props.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
#include "RNSScreenState.h"

namespace facebook {
namespace react {

JSI_EXPORT extern const char RNSModalScreenComponentName[];

class JSI_EXPORT RNSModalScreenShadowNode final : public ConcreteViewShadowNode<
RNSModalScreenComponentName,
RNSScreenProps,
RNSScreenEventEmitter,
RNSScreenState> {
class JSI_EXPORT RNSModalScreenShadowNode final
: public ConcreteViewShadowNode<
RNSModalScreenComponentName,
RNSScreenProps,
RNSScreenEventEmitter,
RNSScreenState> {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <react/debug/react_native_assert.h>
#include "RNSScreenShadowNode.h"
#include <react/renderer/core/ConcreteComponentDescriptor.h>
#include "RNSScreenShadowNode.h"

namespace facebook {
namespace react {
Expand All @@ -12,16 +12,14 @@ class RNSScreenComponentDescriptor final
public:
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;

void adopt(ShadowNode& shadowNode) const override {
react_native_assert(
dynamic_cast<RNSScreenShadowNode*>(&shadowNode));
auto& screenShadowNode =
static_cast<RNSScreenShadowNode&>(shadowNode);
void adopt(ShadowNode &shadowNode) const override {
react_native_assert(dynamic_cast<RNSScreenShadowNode *>(&shadowNode));
auto &screenShadowNode = static_cast<RNSScreenShadowNode &>(shadowNode);

react_native_assert(
dynamic_cast<YogaLayoutableShadowNode*>(&screenShadowNode));
auto& layoutableShadowNode =
dynamic_cast<YogaLayoutableShadowNode&>(screenShadowNode);
dynamic_cast<YogaLayoutableShadowNode *>(&screenShadowNode));
auto &layoutableShadowNode =
dynamic_cast<YogaLayoutableShadowNode &>(screenShadowNode);

auto state =
std::static_pointer_cast<const RNSScreenShadowNode::ConcreteState>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#pragma once

#include "RNSScreenState.h"
#include <jsi/jsi.h>
#include <react/renderer/components/rnscreens/EventEmitters.h>
#include <react/renderer/components/rnscreens/Props.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
#include "RNSScreenState.h"

namespace facebook {
namespace react {

JSI_EXPORT extern const char RNSScreenComponentName[];

class JSI_EXPORT RNSScreenShadowNode final : public ConcreteViewShadowNode<
RNSScreenComponentName,
RNSScreenProps,
RNSScreenEventEmitter,
RNSScreenState> {
RNSScreenComponentName,
RNSScreenProps,
RNSScreenEventEmitter,
RNSScreenState> {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace react {
#ifdef ANDROID
folly::dynamic RNSScreenState::getDynamic() const {
return folly::dynamic::object("frameWidth", frameSize.width)(
"frameHeight", frameSize.height)("contentOffsetX", contentOffset.x)("contentOffsetY", contentOffset.y);
"frameHeight", frameSize.height)("contentOffsetX", contentOffset.x)(
"contentOffsetY", contentOffset.y);
}
#endif

Expand Down
18 changes: 8 additions & 10 deletions common/cpp/react/renderer/components/rnscreens/RNSScreenState.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <react/renderer/graphics/Float.h>
#include <react/renderer/core/graphicsConversions.h>
#include <react/renderer/graphics/Float.h>

#ifdef ANDROID
#include <folly/dynamic.h>
Expand All @@ -17,23 +17,21 @@ class JSI_EXPORT RNSScreenState final {
using Shared = std::shared_ptr<const RNSScreenState>;

RNSScreenState(){};
RNSScreenState(Size frameSize_, Point contentOffset_) : frameSize(frameSize_), contentOffset(contentOffset_){};
RNSScreenState(Size frameSize_, Point contentOffset_)
: frameSize(frameSize_), contentOffset(contentOffset_){};

#ifdef ANDROID
RNSScreenState(
RNSScreenState const &previousState,
folly::dynamic data)
RNSScreenState(RNSScreenState const &previousState, folly::dynamic data)
: frameSize(Size{
(Float)data["frameWidth"].getDouble(),
(Float)data["frameHeight"].getDouble()}),
(Float)data["frameHeight"].getDouble()}),
contentOffset(Point{
(Float)data["contentOffsetX"].getDouble(),
(Float)data["contentOffsetY"].getDouble()})
{};
(Float)data["contentOffsetY"].getDouble()}){};
#endif

const Size frameSize{};
Point contentOffset;
const Size frameSize{};
Point contentOffset;

#ifdef ANDROID
folly::dynamic getDynamic() const;
Expand Down
Loading

0 comments on commit 3bde622

Please sign in to comment.