Skip to content

Commit

Permalink
fix: setting up this referencing callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
tjzel committed Jan 16, 2025
1 parent 0dda87c commit cf8aa1d
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 25 deletions.
12 changes: 9 additions & 3 deletions apps/fabric-example/ios/FabricExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@
};
1232BDDFC9DE5BCE2776187D /* [CP-User] Generate metadata for clangd */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
alwaysOutOfDate = true;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -573,7 +573,10 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = "$(inherited) ";
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../../../node_modules/react-native";
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
Expand Down Expand Up @@ -646,7 +649,10 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = "$(inherited) ";
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down
2 changes: 1 addition & 1 deletion apps/fabric-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2229,7 +2229,7 @@ SPEC CHECKSUMS:
RNScreens: d0854539b51a53e38b61bcc9fb402439a9c73b26
RNSVG: 7e38044415125a1d108294377de261d2fe2c54c9
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: dd05f79b1943c96893294ee5040576aa6e8a8d82
Yoga: 0c8754b0ea9edb13b6ce6b60f0f69eb5f164f16a

PODFILE CHECKSUM: 4a9e0af2552a3fcd2303b56ad75e373f8bae65b9

Expand Down
2 changes: 1 addition & 1 deletion apps/macos-example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@ SPEC CHECKSUMS:
RNReanimated: ed490424d3b8b9f2acd104577c73b374fc79310b
RNSVG: 669ed128ab9005090c612a0d627dbecb6ab5c76f
SocketRocket: 9ee265c4b5ae2382d18e4ee1d2dd2d7af0ff1ab5
Yoga: 209f62622a01344dbb9fa8d348610eaeb7df2cca
Yoga: 446e6f351a519539ff00a1159fe41e589aab1b94

PODFILE CHECKSUM: 8d50cc2acc9f6a6b1a12bd9106b86385ad72266f

Expand Down
2 changes: 1 addition & 1 deletion apps/paper-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ SPEC CHECKSUMS:
RNScreens: 81237378a6d7921fb2dbb6a6c6c45c3d8cc696bb
RNSVG: 515a902fc18a375907eb4c3abec0b803fbfa37ef
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: dd05f79b1943c96893294ee5040576aa6e8a8d82
Yoga: 0c8754b0ea9edb13b6ce6b60f0f69eb5f164f16a

PODFILE CHECKSUM: f6c84e0ec8eddea6d3ee15329987727bd1e6ff08

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
};
EC2A315BF2310B4CCE81E020 /* [CP-User] Generate metadata for clangd */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
alwaysOutOfDate = true;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -579,7 +579,10 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = "$(inherited) ";
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../../../node_modules/react-native";
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
Expand Down Expand Up @@ -652,7 +655,10 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = "$(inherited) ";
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down
2 changes: 1 addition & 1 deletion apps/tvos-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ SPEC CHECKSUMS:
ReactCommon: b927fd46115bd2acb146e24cf1a08f22abda8b3f
RNReanimated: 3a5e1e235c940894097b0734aad9ebce45431ddd
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: 2b0e5affb9ab46e4ebad33530df829c153c323d8
Yoga: 651e5fd560c7e408ab9d9ca44b8de1b622d7f0cc

PODFILE CHECKSUM: 79e1477a8eb76b717bdd7c1610f7f8e6772536a9

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ ReanimatedModuleProxy::ReanimatedModuleProxy(
valueUnpackerCode_(workletsModuleProxy->getValueUnpackerCode()),
eventHandlerRegistry_(std::make_unique<EventHandlerRegistry>()),
requestRender_(platformDepMethodsHolder.requestRender),
onRenderCallback_([weakReanimatedModuleProxy =
weak_from_this()](const double timestampMs) {
auto reanimatedModuleProxy = weakReanimatedModuleProxy.lock();
if (!reanimatedModuleProxy) {
return;
}

reanimatedModuleProxy->renderRequested_ = false;
reanimatedModuleProxy->onRender(timestampMs);
}),
animatedSensorModule_(platformDepMethodsHolder),
jsLogger_(
std::make_shared<JSLogger>(workletsModuleProxy->getJSScheduler())),
Expand All @@ -82,11 +72,22 @@ ReanimatedModuleProxy::ReanimatedModuleProxy(
platformDepMethodsHolder.subscribeForKeyboardEvents),
unsubscribeFromKeyboardEventsFunction_(
platformDepMethodsHolder.unsubscribeFromKeyboardEvents) {
commonInit(platformDepMethodsHolder);
}

void ReanimatedModuleProxy::commonInit(
void ReanimatedModuleProxy::init(
const PlatformDepMethodsHolder &platformDepMethodsHolder) {
auto onRenderCallback = [weakReanimatedModuleProxy =
weak_from_this()](const double timestampMs) {
auto reanimatedModuleProxy = weakReanimatedModuleProxy.lock();
if (!reanimatedModuleProxy) {
return;
}

reanimatedModuleProxy->renderRequested_ = false;
reanimatedModuleProxy->onRender(timestampMs);
};
onRenderCallback_ = std::move(onRenderCallback);

auto requestAnimationFrame = [weakReanimatedModuleProxy = weak_from_this()](
jsi::Runtime &rt,
const jsi::Value &callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class ReanimatedModuleProxy
const bool isBridgeless,
const bool isReducedMotion);

// We need this init method to initialize callbacks with
// weak_from_this() which is available only after the object
// is fully constructed.
void init(const PlatformDepMethodsHolder &platformDepMethodsHolder);

~ReanimatedModuleProxy();

jsi::Value registerEventHandler(
Expand Down Expand Up @@ -164,8 +169,6 @@ class ReanimatedModuleProxy
}

private:
void commonInit(const PlatformDepMethodsHolder &platformDepMethodsHolder);

void requestAnimationFrame(jsi::Runtime &rt, const jsi::Value &callback);

#ifdef RCT_NEW_ARCH_ENABLED
Expand All @@ -184,7 +187,7 @@ class ReanimatedModuleProxy
const RequestRenderFunction requestRender_;
std::vector<std::shared_ptr<jsi::Value>> frameCallbacks_;
volatile bool renderRequested_{false};
const std::function<void(const double)> onRenderCallback_;
std::function<void(const double)> onRenderCallback_;
AnimatedSensorModule animatedSensorModule_;
const std::shared_ptr<JSLogger> jsLogger_;
std::shared_ptr<LayoutAnimationsManager> layoutAnimationsManager_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ NativeProxy::NativeProxy(
isBridgeless,
getIsReducedMotion())),
layoutAnimations_(std::move(layoutAnimations)) {
reanimatedModuleProxy_->init(getPlatformDependentMethods());
#ifdef RCT_NEW_ARCH_ENABLED
commonInit(fabricUIManager);
#endif // RCT_NEW_ARCH_ENABLED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static inline bool getIsReducedMotion()

auto reanimatedModuleProxy = std::make_shared<ReanimatedModuleProxy>(
workletsModuleProxy, rnRuntime, jsInvoker, platformDepMethodsHolder, isBridgeless, getIsReducedMotion());
reanimatedModuleProxy->init(platformDepMethodsHolder);

commonInit(reaModule, workletsModuleProxy->getUIWorkletRuntime()->getJSIRuntime(), reanimatedModuleProxy);
// Layout Animation callbacks setup
Expand Down

0 comments on commit cf8aa1d

Please sign in to comment.