Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "LayoutAnimationsManager.h"
#include "CollectionUtils.h"
#include "Macros.h"
#include "Shareables.h"

#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
#include <utility>
#endif

Expand Down Expand Up @@ -58,11 +59,11 @@ void LayoutAnimationsManager::clearLayoutAnimationConfig(int tag) {
exitingAnimations_.erase(tag);
layoutAnimations_.erase(tag);
shouldAnimateExitingForTag_.erase(tag);
#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
const auto &pair = viewsScreenSharedTagMap_[tag];
screenSharedTagSet_.erase(pair);
viewsScreenSharedTagMap_.erase(tag);
#endif // NDEBUG
#endif // REANIMATED_NDEBUG

sharedTransitionAnimations_.erase(tag);
auto const &groupName = viewTagToSharedTag_[tag];
Expand Down Expand Up @@ -135,7 +136,7 @@ int LayoutAnimationsManager::findPrecedingViewTagForTransition(int tag) {
return -1;
}

#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
std::string LayoutAnimationsManager::getScreenSharedTagPairString(
const int screenTag,
const std::string &sharedTag) const {
Expand All @@ -159,7 +160,7 @@ void LayoutAnimationsManager::checkDuplicateSharedTag(
viewsScreenSharedTagMap_[viewTag] = pair;
screenSharedTagSet_.insert(pair);
}
#endif // NDEBUG
#endif // REANIMATED_NDEBUG

std::unordered_map<int, std::shared_ptr<Shareable>>
&LayoutAnimationsManager::getConfigsForType(LayoutAnimationType type) {
Expand Down
9 changes: 5 additions & 4 deletions Common/cpp/LayoutAnimations/LayoutAnimationsManager.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#pragma once

#include "LayoutAnimationType.h"
#include "Macros.h"
#include "Shareables.h"

#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
#include "JSLogger.h"
#endif

Expand All @@ -23,7 +24,7 @@ using namespace facebook;

class LayoutAnimationsManager {
public:
#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
explicit LayoutAnimationsManager(const std::shared_ptr<JSLogger> &jsLogger)
: jsLogger_(jsLogger) {}
#endif
Expand All @@ -43,7 +44,7 @@ class LayoutAnimationsManager {
void clearLayoutAnimationConfig(int tag);
void cancelLayoutAnimation(jsi::Runtime &rt, int tag);
int findPrecedingViewTagForTransition(int tag);
#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
std::string getScreenSharedTagPairString(
const int screenTag,
const std::string &sharedTag) const;
Expand All @@ -54,7 +55,7 @@ class LayoutAnimationsManager {
std::unordered_map<int, std::shared_ptr<Shareable>> &getConfigsForType(
LayoutAnimationType type);

#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
std::shared_ptr<JSLogger> jsLogger_;
// This set's function is to detect duplicate sharedTags on a single screen
// it contains strings in form: "reactScreenTag:sharedTag"
Expand Down
3 changes: 2 additions & 1 deletion Common/cpp/NativeModules/NativeReanimatedModule.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "NativeReanimatedModule.h"
#include "Macros.h"

#ifdef RCT_NEW_ARCH_ENABLED
#if REACT_NATIVE_MINOR_VERSION >= 72
Expand Down Expand Up @@ -64,7 +65,7 @@ NativeReanimatedModule::NativeReanimatedModule(
onRender(timestampMs);
}),
animatedSensorModule_(platformDepMethodsHolder),
#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
layoutAnimationsManager_(std::make_shared<JSLogger>(jsScheduler_)),
#endif
#ifdef RCT_NEW_ARCH_ENABLED
Expand Down
4 changes: 3 additions & 1 deletion Common/cpp/NativeModules/NativeReanimatedModule.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "Macros.h"

#ifdef RCT_NEW_ARCH_ENABLED
#include <react/renderer/uimanager/UIManager.h>
#endif
Expand Down Expand Up @@ -210,7 +212,7 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
const KeyboardEventSubscribeFunction subscribeForKeyboardEventsFunction_;
const KeyboardEventUnsubscribeFunction unsubscribeFromKeyboardEventsFunction_;

#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
SingleInstanceChecker<NativeReanimatedModule> singleInstanceChecker_;
#endif
};
Expand Down
9 changes: 5 additions & 4 deletions Common/cpp/ReanimatedRuntime/RNRuntimeDecorator.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "RNRuntimeDecorator.h"
#ifndef NDEBUG
#include "Macros.h"
#ifndef REANIMATED_NDEBUG
#include "ReanimatedVersion.h"
#endif // NDEBUG
#endif // REANIMATED_NDEBUG

namespace reanimated {

Expand Down Expand Up @@ -31,9 +32,9 @@ void RNRuntimeDecorator::decorate(
#endif // RCT_NEW_ARCH_ENABLED
rnRuntime.global().setProperty(rnRuntime, "_IS_FABRIC", isFabric);

#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
checkJSVersion(rnRuntime);
#endif // NDEBUG
#endif // REANIMATED_NDEBUG

rnRuntime.global().setProperty(
rnRuntime, "_REANIMATED_IS_REDUCED_MOTION", isReducedMotion);
Expand Down
5 changes: 3 additions & 2 deletions Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ReanimatedHermesRuntime.h"
#include "Macros.h"

// Only include this file in Hermes-enabled builds as some platforms (like tvOS)
// don't support hermes and it causes the compilation to fail.
Expand Down Expand Up @@ -92,7 +93,7 @@ ReanimatedHermesRuntime::ReanimatedHermesRuntime(
jsQueue->quitSynchronous();
#endif // HERMES_ENABLE_DEBUGGER

#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
facebook::hermes::HermesRuntime *wrappedRuntime = runtime_.get();
jsi::Value evalWithSourceMap = jsi::Function::createFromHostFunction(
*runtime_,
Expand All @@ -119,7 +120,7 @@ ReanimatedHermesRuntime::ReanimatedHermesRuntime(
});
runtime_->global().setProperty(
*runtime_, "evalWithSourceMap", evalWithSourceMap);
#endif // NDEBUG
#endif // REANIMATED_NDEBUG
}

ReanimatedHermesRuntime::~ReanimatedHermesRuntime() {
Expand Down
6 changes: 4 additions & 2 deletions Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "Macros.h"

// JS_RUNTIME_HERMES is only set on Android so we have to check __has_include
// on iOS.
#if __APPLE__ && \
Expand Down Expand Up @@ -50,7 +52,7 @@ using namespace facebook::hermes::inspector;
struct ReanimatedReentrancyCheck {
// This is effectively a very subtle and complex assert, so only
// include it in builds which would include asserts.
#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
ReanimatedReentrancyCheck() : tid(std::thread::id()), depth(0) {}

void before() {
Expand Down Expand Up @@ -111,7 +113,7 @@ struct ReanimatedReentrancyCheck {
// This is not atomic, as it is only written or read from the owning
// thread.
unsigned int depth;
#endif // NDEBUG
#endif // REANIMATED_NDEBUG
};

// This is in fact a subclass of jsi::Runtime! WithRuntimeDecorator is a
Expand Down
3 changes: 2 additions & 1 deletion Common/cpp/ReanimatedRuntime/WorkletRuntimeDecorator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "WorkletRuntimeDecorator.h"
#include "JSISerializer.h"
#include "Macros.h"
#include "ReanimatedJSIUtils.h"
#include "Shareables.h"

Expand Down Expand Up @@ -40,7 +41,7 @@ void WorkletRuntimeDecorator::decorate(
#endif // RCT_NEW_ARCH_ENABLED
rt.global().setProperty(rt, "_IS_FABRIC", isFabric);

#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
auto evalWithSourceUrl = [](jsi::Runtime &rt,
const jsi::Value &thisValue,
const jsi::Value *args,
Expand Down
7 changes: 4 additions & 3 deletions Common/cpp/SharedItems/Shareables.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Shareables.h"
#include "Macros.h"

using namespace facebook;

Expand All @@ -10,7 +11,7 @@ jsi::Function getValueUnpacker(jsi::Runtime &rt) {
return valueUnpacker.asObject(rt).asFunction(rt);
}

#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG

static const auto callGuardLambda = [](facebook::jsi::Runtime &rt,
const facebook::jsi::Value &thisVal,
Expand All @@ -36,7 +37,7 @@ jsi::Function getCallGuard(jsi::Runtime &rt) {
rt, jsi::PropNameID::forAscii(rt, "callGuard"), 1, callGuardLambda);
}

#endif // NDEBUG
#endif // REANIMATED_NDEBUG

jsi::Value makeShareableClone(
jsi::Runtime &rt,
Expand Down Expand Up @@ -242,7 +243,7 @@ jsi::Value ShareableRemoteFunction::toJSValue(jsi::Runtime &rt) {
if (&rt == runtime_) {
return jsi::Value(rt, *function_);
} else {
#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
return getValueUnpacker(rt).call(
rt,
ShareableJSRef::newHostObject(rt, shared_from_this()),
Expand Down
7 changes: 4 additions & 3 deletions Common/cpp/SharedItems/Shareables.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include <utility>
#include <vector>
#include "Macros.h"

#include "WorkletRuntimeRegistry.h"

Expand All @@ -14,9 +15,9 @@ namespace reanimated {

jsi::Function getValueUnpacker(jsi::Runtime &rt);

#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
jsi::Function getCallGuard(jsi::Runtime &rt);
#endif // NDEBUG
#endif // REANIMATED_NDEBUG

// If possible, please use `WorkletRuntime::runGuarded` instead.
template <typename... Args>
Expand All @@ -28,7 +29,7 @@ inline void runOnRuntimeGuarded(
// function directly. CallGuard provides a way of capturing exceptions in
// JavaScript and propagating them to the main React Native thread such that
// they can be presented using RN's LogBox.
#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
getCallGuard(rt).call(rt, function, args...);
#else
function.asObject(rt).asFunction(rt).call(rt, args...);
Expand Down
7 changes: 4 additions & 3 deletions Common/cpp/Tools/JSLogger.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef NDEBUG
#include "Macros.h"
#ifndef REANIMATED_NDEBUG

#include "JSLogger.h"
#include <memory>
#include "JSLogger.h"

namespace reanimated {

Expand All @@ -15,4 +16,4 @@ void JSLogger::warnOnJS(const std::string &warning) const {

} // namespace reanimated

#endif // NDEBUG
#endif // REANIMATED_NDEBUG
5 changes: 3 additions & 2 deletions Common/cpp/Tools/JSLogger.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#ifndef NDEBUG
#include "Macros.h"
#ifndef REANIMATED_NDEBUG

#pragma once

Expand All @@ -21,4 +22,4 @@ class JSLogger {

} // namespace reanimated

#endif // NDEBUG
#endif // REANIMATED_NDEBUG
31 changes: 31 additions & 0 deletions Common/cpp/Tools/Macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

/*
We need this macro due to migration from DEBUG to NDEBUG macro. XCode does only
inject DEBUG out-of-the-box for Apps (unless the user removes that) so NDEBUG
has to be added manually. Unfortunately, as of now we have no way of injecting
NDEBUG into user's App on iOS without asking him to do: `PRODUCTION=1 pod
install. However, since
https://github.com/facebook/react-native/commit/93fdcbaed0f69b268e1ae708a52df9463aae2d53
RN user's are no longer asked to do `PRODUCTION=1` and NDEBUG is injected by RN
automatically (on Fabric only). Therefore, we do the following:
- on Android we just look-up NDEBUG
- on iOS we look-up NDEBUG (we inject it in .podspec when `PRODUCTION=1`)
- if NDEBUG is not defined we check if Fabric is disabled
- if Fabric is disabled, we check for out-of-the-box DEBUG
- if DEBUG isn't defined it's almost safe to assume a release build
*/

#ifndef REANIMATED_NDEBUG
#ifdef NDEBUG
#define REANIMATED_NDEBUG 1
#else // NDEBUG
#ifdef __APPLE__
#ifndef RCT_NEW_ARCH_ENABLED
#ifndef DEBUG
#define REANIMATED_NDEBUG 1
#endif // DEBUG
#endif // RCT_NEW_ARCH_ENABLED
#endif // __APPLE__
#endif // NDEBUG
#endif // REANIMATED_NDEBUG
5 changes: 3 additions & 2 deletions Common/cpp/Tools/ReanimatedVersion.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ReanimatedVersion.h"
#include <regex>
#include <string>
#include "Macros.h"

#ifdef REANIMATED_VERSION
#define STRINGIZE(x) #x
Expand All @@ -18,7 +19,7 @@ std::string getReanimatedCppVersion() {

// This function is pretty much a copy of
// `src/reanimated2/platform-specific/checkVersion.ts`.
#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
bool matchVersion(const std::string &version1, const std::string &version2) {
std::regex pattern("^\\d+\\.\\d+\\.\\d+$");
if (std::regex_match(version1, pattern) &&
Expand Down Expand Up @@ -68,6 +69,6 @@ void checkJSVersion(jsi::Runtime &rnRuntime) {
"_REANIMATED_VERSION_CPP",
jsi::String::createFromUtf8(rnRuntime, cppVersion));
}
#endif // NDEBUG
#endif // REANIMATED_NDEBUG

}; // namespace reanimated
5 changes: 3 additions & 2 deletions Common/cpp/Tools/ReanimatedVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

#include <jsi/jsi.h>
#include <string>
#include "Macros.h"

using namespace facebook;

namespace reanimated {

std::string getReanimatedCppVersion();

#ifndef NDEBUG
#ifndef REANIMATED_NDEBUG
bool matchVersion(const std::string &, const std::string &);
void checkJSVersion(jsi::Runtime &);
#endif // NDEBUG
#endif // REANIMATED_NDEBUG

}; // namespace reanimated
6 changes: 4 additions & 2 deletions Common/cpp/Tools/SingleInstanceChecker.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#ifndef NDEBUG
#include "Macros.h"

#ifndef REANIMATED_NDEBUG

#include <cxxabi.h>

Expand Down Expand Up @@ -68,4 +70,4 @@ SingleInstanceChecker<T>::~SingleInstanceChecker() {

} // namespace reanimated

#endif // NDEBUG
#endif // REANIMATED_NDEBUG
Loading