forked from software-mansion/react-native-screens
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add formatting of all cpp (software-mansion#2138)
PR adding formatting of all cpp codebase.
- Loading branch information
Showing
10 changed files
with
180 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(¤tEnv, 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(¤tEnv, 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(¤tEnv, 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(¤tEnv, 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(¤tEnv, 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(¤tEnv, 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 8 additions & 7 deletions
15
common/cpp/react/renderer/components/rnscreens/RNSModalScreenShadowNode.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
common/cpp/react/renderer/components/rnscreens/RNSScreenShadowNode.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.