Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define RCT_NEW_ARCH_ENABLED 1
#ifdef RCT_NEW_ARCH_ENABLED

#include <reanimated/Fabric/PropsRegistry.h>
Expand All @@ -10,30 +9,9 @@ std::lock_guard<std::mutex> PropsRegistry::createLock() const {
return std::lock_guard<std::mutex>(mutex_);
}

#ifdef RCT_NEW_ARCH_ENABLED
void PropsRegistry::update(
const std::shared_ptr<const ShadowNode> &shadowNode,
folly::dynamic &&props,
double timestamp) {
const auto tag = shadowNode->getTag();
const auto it = map_.find(tag);
if (it == map_.cend()) {
// we need to store ShadowNode because `ShadowNode::getFamily`
// returns `ShadowNodeFamily const &` which is non-owning
map_[tag] = std::make_pair(shadowNode, props);
timestampMap_[shadowNode->getTag()] = timestamp;
} else {
// no need to update `.first` because ShadowNode's family never changes
// merge new props with old props
it->second.second.update(props);

timestampMap_[shadowNode->getTag()] = timestamp;
}
}
#else
void PropsRegistry::update(
const std::shared_ptr<const ShadowNode> &shadowNode,
folly::dynamic &&props) {
folly::dynamic &&props) {
const auto tag = shadowNode->getTag();
const auto it = map_.find(tag);
if (it == map_.cend()) {
Expand All @@ -46,7 +24,6 @@ void PropsRegistry::update(
it->second.second.update(props);
}
}
#endif // RCT_NEW_ARCH_ENABLED

void PropsRegistry::for_each(std::function<void(
const ShadowNodeFamily &family,
Expand Down Expand Up @@ -127,42 +104,6 @@ void PropsRegistry::removeImmediateRemovableNodes() {
immediateRemovableShadowNodes_.clear();
}

#ifdef RCT_NEW_ARCH_ENABLED
jsi::Value PropsRegistry::getUpdatesOlderThanTimestamp(jsi::Runtime &rt, const double timestamp) {
std::vector<std::pair<Tag, std::reference_wrapper<const folly::dynamic>>> updates;

for (const auto &[viewTag, pair] : map_) {
if (timestampMap_.at(viewTag) < timestamp) {
updates.emplace_back(viewTag, std::cref(pair.second));
}
}

const jsi::Array array(rt, updates.size());
size_t i = 0;
for (const auto &[viewTag, styleProps] : updates) {
const jsi::Object item(rt);
item.setProperty(rt, "viewTag", viewTag);
item.setProperty(rt, "styleProps", jsi::valueFromDynamic(rt, styleProps.get()));
array.setValueAtIndex(rt, i++, item);
}

return jsi::Value(rt, array);
}

void PropsRegistry::removeUpdatesOlderThanTimestamp(const double timestamp) {
for (auto it = timestampMap_.begin(); it != timestampMap_.end();) {
const auto viewTag = it->first;
const auto viewTimestamp = it->second;
if (viewTimestamp < timestamp) {
it = timestampMap_.erase(it);
map_.erase(viewTag);
} else {
it++;
}
}
}
#endif // RCT_NEW_ARCH_ENABLED

} // namespace reanimated

#endif // RCT_NEW_ARCH_ENABLED
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,16 @@ class PropsRegistry {
std::lock_guard<std::mutex> createLock() const;
// returns a lock you need to hold when calling any of the methods below

#ifdef RCT_NEW_ARCH_ENABLED
void update(
const std::shared_ptr<const ShadowNode> &shadowNode,
folly::dynamic &&props,
double timestamp);
#else
void update(
const std::shared_ptr<const ShadowNode> &shadowNode,
folly::dynamic &&props);
#endif // RCT_NEW_ARCH_ENABLED

void for_each(std::function<void(
const ShadowNodeFamily &family,
const folly::dynamic &props)> callback) const;

void remove(const Tag tag);

#ifdef RCT_NEW_ARCH_ENABLED
jsi::Value getUpdatesOlderThanTimestamp(jsi::Runtime &rt, double timestamp);
void removeUpdatesOlderThanTimestamp(double timestamp);
#endif // RCT_NEW_ARCH_ENABLED

void pauseReanimatedCommits() {
isPaused_ = true;
}
Expand Down Expand Up @@ -93,7 +81,6 @@ class PropsRegistry {

std::atomic<bool> isPaused_;
std::atomic<bool> shouldCommitAfterPause_;
std::unordered_map<Tag, double> timestampMap_; // viewTag -> timestamp, protected by `mutex_`
};

} // namespace reanimated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit(
return newRootShadowNode;
}

#ifdef RCT_NEW_ARCH_ENABLED
if (commitOptions.source != ShadowTreeCommitSource::React) {
return newRootShadowNode;
}
#endif // RCT_NEW_ARCH_ENABLED

// ShadowTree not commited by Reanimated, apply updates from PropsRegistry
reaShadowNode->unsetReanimatedMountTrait();
RootShadowNode::Unshared rootNode = newRootShadowNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ Props::Shared mergeProps(
const auto &propsVector = it->second;
auto newProps = shadowNode.getProps();

// [note for piaskowyk]: I tried to remove this changes since we already have similar fixes from under the FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS flag,
// but removing these changes causes noticable performance degradation
#ifdef ANDROID
if (propsVector.size() > 1) {
folly::dynamic newPropsDynamic = folly::dynamic::object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ ReanimatedModuleProxy::ReanimatedModuleProxy(
valueUnpackerCode_)),
eventHandlerRegistry_(std::make_unique<EventHandlerRegistry>()),
requestRender_(platformDepMethodsHolder.requestRender),
#ifdef RCT_NEW_ARCH_ENABLED
getAnimationTimestamp_(platformDepMethodsHolder.getAnimationTimestamp),
#endif // RCT_NEW_ARCH_ENABLED
animatedSensorModule_(platformDepMethodsHolder),
jsLogger_(
std::make_shared<JSLogger>(workletsModuleProxy->getJSScheduler())),
Expand Down Expand Up @@ -756,22 +753,6 @@ jsi::Value ReanimatedModuleProxy::filterNonAnimatableProps(
}
return nonAnimatableProps;
}

jsi::Value ReanimatedModuleProxy::getSettledUpdates(jsi::Runtime &rt) {
// TODO(future): use unified timestamp
const auto currentTimestamp = getAnimationTimestamp_();

const auto lock = propsRegistry_->createLock();

// TODO: fix bug when threshold difference is smaller than 1 second
// TODO(future): flush updates from CSS animations and CSS transitions registries
propsRegistry_->removeUpdatesOlderThanTimestamp(currentTimestamp - 2000); // 2 seconds

// TODO(future): find a better way to obtain timestamp for removing updates
// TODO(future): move removing old updates to separate method

return propsRegistry_->getUpdatesOlderThanTimestamp(rt, currentTimestamp - 1000); // 1 second
}
#endif // RCT_NEW_ARCH_ENABLED

bool ReanimatedModuleProxy::handleEvent(
Expand Down Expand Up @@ -886,9 +867,6 @@ void ReanimatedModuleProxy::performOperations(const bool isTriggeredByEvent, con
propsRegistry_->shouldReanimatedSkipCommit()) {
propsRegistry_->pleaseCommitAfterPause();
}
#ifdef RCT_NEW_ARCH_ENABLED
const auto currentTimestamp = this->getAnimationTimestamp_();
#endif // RCT_NEW_ARCH_ENABLED

// Even if only non-layout props are changed, we need to store the update
// in PropsRegistry anyway so that React doesn't overwrite it in the next
Expand All @@ -906,12 +884,7 @@ void ReanimatedModuleProxy::performOperations(const bool isTriggeredByEvent, con

// Still need to convert to dynamic for propsRegistry
folly::dynamic propsDynamic = dynamicFromValue(rt, *props);

#ifdef RCT_NEW_ARCH_ENABLED
propsRegistry_->update(shadowNode, std::move(propsDynamic), currentTimestamp);
#else
propsRegistry_->update(shadowNode, std::move(propsDynamic));
#endif // RCT_NEW_ARCH_ENABLED
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,6 @@ class ReanimatedModuleProxy
return workletsModuleProxy_;
}

#ifdef RCT_NEW_ARCH_ENABLED
#ifdef ANDROID
jsi::Value getSettledUpdates(jsi::Runtime &rt) override;
#else // IOS
jsi::Value getSettledUpdates(jsi::Runtime &rt);
#endif // ANDROID
#endif // RCT_NEW_ARCH_ENABLED

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

Expand All @@ -229,7 +221,6 @@ class ReanimatedModuleProxy

std::unique_ptr<EventHandlerRegistry> eventHandlerRegistry_;
const RequestRenderFunction requestRender_;
const GetAnimationTimestampFunction getAnimationTimestamp_;
std::vector<std::shared_ptr<jsi::Value>> frameCallbacks_;
volatile bool renderRequested_{false};
std::function<void(const double)> onRenderCallback_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,6 @@ static jsi::Value REANIMATED_SPEC_PREFIX(setNodeRemovalCallback)(
return jsi::Value::undefined();
}

static jsi::Value REANIMATED_SPEC_PREFIX(
getSettledUpdates)(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value *args, size_t) {
return static_cast<ReanimatedModuleProxySpec *>(&turboModule)->getSettledUpdates(rt);
}

#endif // RCT_NEW_ARCH_ENABLED

ReanimatedModuleProxySpec::ReanimatedModuleProxySpec(
Expand Down Expand Up @@ -243,8 +238,6 @@ ReanimatedModuleProxySpec::ReanimatedModuleProxySpec(
MethodMetadata{1, REANIMATED_SPEC_PREFIX(unmarkNodeAsRemovable)};
methodMap_["setNodeRemovalCallback"] =
MethodMetadata{1, REANIMATED_SPEC_PREFIX(setNodeRemovalCallback)};
methodMap_["getSettledUpdates"] =
MethodMetadata{1, REANIMATED_SPEC_PREFIX(getSettledUpdates)};
#endif // RCT_NEW_ARCH_ENABLED
}
} // namespace reanimated
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class JSI_EXPORT ReanimatedModuleProxySpec : public TurboModule {
virtual void setNodeRemovalCallback(
jsi::Runtime &rt,
const jsi::Value &callback) = 0;
virtual jsi::Value getSettledUpdates(jsi::Runtime &rt) = 0;
#endif // RCT_NEW_ARCH_ENABLED
};

Expand Down
4 changes: 1 addition & 3 deletions packages/react-native-reanimated/src/Colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,7 @@ export const hsvToColor = (
return rgbaColor(r, g, b, a);
};

export function processColorInitially(
color: unknown
): number | null | undefined {
function processColorInitially(color: unknown): number | null | undefined {
'worklet';
if (color === null || color === undefined) {
return color;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
IReanimatedModule,
IWorkletsModule,
LayoutAnimationBatchItem,
SettledUpdate,
ShadowNodeWrapper,
ShareableRef,
Value3D,
Expand Down Expand Up @@ -200,10 +199,6 @@ See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooti
setNodeRemovalCallback(callback: (tag: number, isFrozen: boolean) => void) {
this.#reanimatedModuleProxy.setNodeRemovalCallback(callback);
}

getSettledUpdates(): SettledUpdate[] {
return this.#reanimatedModuleProxy.getSettledUpdates();
}
}

class DummyReanimatedModuleProxy implements ReanimatedModuleProxy {
Expand Down Expand Up @@ -243,8 +238,4 @@ class DummyReanimatedModuleProxy implements ReanimatedModuleProxy {
getViewProp() {
return null!;
}

getSettledUpdates(): SettledUpdate[] {
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import type {
IReanimatedModule,
IWorkletsModule,
SettledUpdate,
ShadowNodeWrapper,
ShareableRef,
Value3D,
Expand Down Expand Up @@ -268,12 +267,6 @@ class JSReanimated implements IReanimatedModule {
}
}

getSettledUpdates(): SettledUpdate[] {
throw new ReanimatedError(
'`getSettledUpdates` is not available in JSReanimated.'
);
}

detectPlatform() {
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
if (userAgent === undefined) {
Expand Down
Loading
Loading