Skip to content

Commit

Permalink
refactor(Worklets): move PlatformLogger (#6794)
Browse files Browse the repository at this point in the history
## Summary

`PlatformLogger` remained in Reanimated during early steps of
establishing Worklets Module due to how difficult it was to move it back
then. Now it's very simple, so let's do it.

## Test plan

See in app if `LogExample` works.
  • Loading branch information
tjzel authored Dec 6, 2024
1 parent cf1f618 commit b79faa3
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <reanimated/NativeModules/ReanimatedModuleProxy.h>
#include <reanimated/RuntimeDecorators/ReanimatedWorkletRuntimeDecorator.h>
#include <reanimated/RuntimeDecorators/UIRuntimeDecorator.h>
#include <reanimated/Tools/CollectionUtils.h>
#include <reanimated/Tools/FeaturesConfig.h>
Expand Down Expand Up @@ -242,7 +241,6 @@ jsi::Value ReanimatedModuleProxy::createWorkletRuntime(
auto initializerShareable = extractShareableOrThrow<ShareableWorklet>(
rt, initializer, "[Reanimated] Initializer must be a worklet.");
workletRuntime->runGuarded(initializerShareable);
ReanimatedWorkletRuntimeDecorator::decorate(workletRuntime->getJSIRuntime());
return jsi::Object::createFromHostObject(rt, workletRuntime);
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <string>

namespace reanimated {
namespace worklets {

class PlatformLogger {
public:
Expand All @@ -13,4 +13,4 @@ class PlatformLogger {
static void log(const bool b);
};

} // namespace reanimated
} // namespace worklets
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <worklets/SharedItems/Shareables.h>
#include <worklets/Tools/JSISerializer.h>
#include <worklets/Tools/PlatformLogger.h>
#include <worklets/Tools/ReanimatedJSIUtils.h>
#include <worklets/WorkletRuntime/WorkletRuntime.h>
#include <worklets/WorkletRuntime/WorkletRuntimeDecorator.h>
Expand Down Expand Up @@ -76,6 +77,11 @@ void WorkletRuntimeDecorator::decorate(
evalWithSourceUrl));
#endif // NDEBUG

jsi_utils::installJsiFunction(
rt, "_log", [](jsi::Runtime &rt, const jsi::Value &value) {
PlatformLogger::log(stringifyJSIValue(rt, value));
});

jsi_utils::installJsiFunction(
rt, "_toString", [](jsi::Runtime &rt, const jsi::Value &value) {
return jsi::String::createFromUtf8(rt, stringifyJSIValue(rt, value));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <android/log.h>

#include <reanimated/Tools/PlatformLogger.h>
#include <worklets/Tools/PlatformLogger.h>

constexpr const auto tag = "Reanimated";
constexpr const auto tag = "Worklets";

namespace reanimated {
namespace worklets {

void PlatformLogger::log(const char *str) {
__android_log_print(ANDROID_LOG_VERBOSE, tag, "%s", str);
Expand All @@ -26,4 +26,4 @@ void PlatformLogger::log(const bool b) {
log(b ? "true" : "false");
}

} // namespace reanimated
} // namespace worklets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import <Foundation/Foundation.h>
#import <reanimated/Tools/PlatformLogger.h>
#import <worklets/Tools/PlatformLogger.h>

namespace reanimated {
namespace worklets {

void PlatformLogger::log(const char *str)
{
Expand All @@ -28,4 +28,4 @@
log(b ? "true" : "false");
}

} // namespace reanimated
} // namespace worklets

0 comments on commit b79faa3

Please sign in to comment.