Skip to content
Merged
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
7 changes: 3 additions & 4 deletions .github/workflows/lint-clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- main
paths:
- '.github/workflows/lint-clang-tidy.yml'
- 'scripts/clang-tidy-lint.sh'

merge_group:
branches:
Expand All @@ -15,6 +16,7 @@ on:
pull_request:
paths:
- '.github/workflows/lint-clang-tidy.yml'
- 'scripts/clang-tidy-lint.sh'
workflow_call:
workflow_dispatch:

Expand All @@ -30,12 +32,9 @@ jobs:

- name: Install monorepo node dependencies
run: yarn install --immutable
- name: Build Worklets package
run: yarn workspace react-native-worklets build
- name: Build Reanimated package
run: yarn workspace react-native-reanimated build

- name: Clang-tidy lint Worklets
run: yarn workspace react-native-worklets lint:clang-tidy

- name: Clang-tidy lint Reanimated
run: yarn workspace react-native-reanimated lint:clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bool DelayedItemComparator<TValue>::operator()(const DelayedItem<TValue> &lhs, c
}

template <typename TValue>
void DelayedItemsManager<TValue>::add(const double timestamp, const TValue value) {
void DelayedItemsManager<TValue>::add(const double timestamp, const TValue &value) {
auto result = itemsSet_.emplace(timestamp, value);
if (result.second) {
itemsMap_[result.first->value] = result.first;
Expand All @@ -38,7 +38,7 @@ typename DelayedItemsManager<TValue>::Item DelayedItemsManager<TValue>::pop() {
}

template <typename TValue>
bool DelayedItemsManager<TValue>::remove(const TValue value) {
bool DelayedItemsManager<TValue>::remove(const TValue &value) {
auto it = itemsMap_.find(value);

if (it == itemsMap_.end()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class DelayedItemsManager {
ItemMap itemsMap_;

public:
void add(double timestamp, TValue value);
void add(double timestamp, const TValue &value);
Item pop();
bool remove(TValue value);
bool remove(const TValue &value);
const Item &top() const;
bool empty() const;
size_t size() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ std::optional<MountingTransaction> LayoutAnimationsProxy_Experimental::pullTrans
ShadowViewMutationList filteredMutations;
auto rootChildCount = static_cast<int>(lightNodes_[surfaceId]->children.size());
const std::vector<std::shared_ptr<MutationNode>> roots;
const bool isInTransition = transitionState_;
const bool isInTransition = static_cast<bool>(transitionState_);

if (isInTransition) {
updateLightTree(propsParserContext, mutations, filteredMutations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct LayoutAnimationsProxy_Experimental : public LayoutAnimationsProxyCommon,
mutable Tag transitionTag_;
mutable double transitionProgress_;
mutable bool transitionUpdated_;
mutable TransitionState transitionState_ = NONE;
mutable TransitionState transitionState_ = TransitionState::NONE;
mutable SurfaceId transitioningSurfaceId_ = -1;
mutable std::unordered_map<SurfaceId, std::shared_ptr<LightNode>> topScreen;
mutable int containerTag_ = 10000002;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ std::optional<SurfaceId> LayoutAnimationsProxy_Legacy::endLayoutAnimation(int ta

auto node = nodeForTag_[tag];
auto mutationNode = std::static_pointer_cast<MutationNode>(node);
mutationNode->state = DEAD;
mutationNode->state = ExitingState_Legacy::DEAD;
auto &[deadNodes] = surfaceContext_[surfaceId];
deadNodes.insert(mutationNode);

Expand Down Expand Up @@ -172,7 +172,7 @@ void LayoutAnimationsProxy_Legacy::parseRemoveMutations(
}
}
if (!deletedViews.contains(mutation.oldChildShadowView.tag)) {
mutationNode->state = MOVED;
mutationNode->state = ExitingState_Legacy::MOVED;
movedViews.insert_or_assign(mutation.oldChildShadowView.tag, -1);
}
nodeForTag_[tag] = mutationNode;
Expand Down Expand Up @@ -245,11 +245,11 @@ void LayoutAnimationsProxy_Legacy::handleRemovals(
if (!startAnimationsRecursively(node, true, shouldAnimate, false, filteredMutations)) {
filteredMutations.push_back(node->mutation);
node->unflattenedParent->removeChildFromUnflattenedTree(node); //???
if (node->state != MOVED) {
if (node->state != ExitingState_Legacy::MOVED) {
maybeCancelAnimation(node->tag);
filteredMutations.push_back(ShadowViewMutation::DeleteMutation(node->mutation.oldChildShadowView));
nodeForTag_.erase(node->tag);
node->state = DELETED;
node->state = ExitingState_Legacy::DELETED;
#ifdef LAYOUT_ANIMATIONS_LOGS
LOG(INFO) << "delete " << node->tag << std::endl;
#endif
Expand All @@ -258,7 +258,7 @@ void LayoutAnimationsProxy_Legacy::handleRemovals(
}

for (const auto &node : deadNodes) {
if (node->state != DELETED) {
if (node->state != ExitingState_Legacy::DELETED) {
endAnimationsRecursively(node, filteredMutations);
maybeDropAncestors(node->unflattenedParent, node, filteredMutations);
}
Expand Down Expand Up @@ -429,12 +429,12 @@ void LayoutAnimationsProxy_Legacy::endAnimationsRecursively(
const std::shared_ptr<MutationNode> &node,
ShadowViewMutationList &mutations) const {
maybeCancelAnimation(node->tag);
node->state = DELETED;
node->state = ExitingState_Legacy::DELETED;
// iterate from the end, so that children
// with higher indices appear first in the mutations list
for (auto it = node->unflattenedChildren.rbegin(); it != node->unflattenedChildren.rend(); it++) {
auto &subNode = *it;
if (subNode->state != DELETED) {
if (subNode->state != ExitingState_Legacy::DELETED) {
endAnimationsRecursively(subNode, mutations);
}
}
Expand All @@ -457,11 +457,11 @@ void LayoutAnimationsProxy_Legacy::maybeDropAncestors(

auto node = std::static_pointer_cast<MutationNode>(parent);

if (node->children.size() == 0 && node->state != ANIMATING) {
if (node->children.size() == 0 && node->state != ExitingState_Legacy::ANIMATING) {
nodeForTag_.erase(node->tag);
cleanupMutations.push_back(node->mutation);
maybeCancelAnimation(node->tag);
node->state = DELETED;
node->state = ExitingState_Legacy::DELETED;
#ifdef LAYOUT_ANIMATIONS_LOGS
LOG(INFO) << "delete " << node->tag << std::endl;
#endif
Expand Down Expand Up @@ -492,7 +492,7 @@ bool LayoutAnimationsProxy_Legacy::startAnimationsRecursively(
bool hasAnimatedChildren = false;

shouldRemoveSubviewsWithoutAnimations =
shouldRemoveSubviewsWithoutAnimations && (!hasExitAnimation || node->state == MOVED);
shouldRemoveSubviewsWithoutAnimations && (!hasExitAnimation || node->state == ExitingState_Legacy::MOVED);
std::vector<std::shared_ptr<MutationNode>> toBeRemoved;

// iterate from the end, so that children
Expand All @@ -503,8 +503,8 @@ bool LayoutAnimationsProxy_Legacy::startAnimationsRecursively(
LOG(INFO) << "child " << subNode->tag << " "
<< " " << shouldAnimate << " " << shouldRemoveSubviewsWithoutAnimations << std::endl;
#endif
if (subNode->state != UNDEFINED && subNode->state != MOVED) {
if (shouldAnimate && subNode->state != DEAD) {
if (subNode->state != ExitingState_Legacy::UNDEFINED && subNode->state != ExitingState_Legacy::MOVED) {
if (shouldAnimate && subNode->state != ExitingState_Legacy::DEAD) {
hasAnimatedChildren = true;
} else {
endAnimationsRecursively(subNode, mutations);
Expand All @@ -516,29 +516,29 @@ bool LayoutAnimationsProxy_Legacy::startAnimationsRecursively(
LOG(INFO) << "child " << subNode->tag << " start animations returned true " << std::endl;
#endif
hasAnimatedChildren = true;
} else if (subNode->state == MOVED) {
} else if (subNode->state == ExitingState_Legacy::MOVED) {
mutations.push_back(subNode->mutation);
toBeRemoved.push_back(subNode);
} else if (shouldRemoveSubviewsWithoutAnimations) {
maybeCancelAnimation(subNode->tag);
mutations.push_back(subNode->mutation);
toBeRemoved.push_back(subNode);
subNode->state = DELETED;
subNode->state = ExitingState_Legacy::DELETED;
nodeForTag_.erase(subNode->tag);
#ifdef LAYOUT_ANIMATIONS_LOGS
LOG(INFO) << "delete " << subNode->tag << std::endl;
#endif
mutations.push_back(ShadowViewMutation::DeleteMutation(subNode->mutation.oldChildShadowView));
} else {
subNode->state = WAITING;
subNode->state = ExitingState_Legacy::WAITING;
}
}

for (auto &subNode : toBeRemoved) {
node->removeChildFromUnflattenedTree(subNode);
}

if (node->state == MOVED) {
if (node->state == ExitingState_Legacy::MOVED) {
auto replacement = std::make_shared<Node>(*node);
for (const auto &subNode : node->children) {
subNode->parent = replacement;
Expand All @@ -553,7 +553,7 @@ bool LayoutAnimationsProxy_Legacy::startAnimationsRecursively(
bool wantAnimateExit = hasExitAnimation || hasAnimatedChildren;

if (hasExitAnimation) {
node->state = ANIMATING;
node->state = ExitingState_Legacy::ANIMATING;
startExitingAnimation(node->tag, node->mutation);
} else {
layoutAnimationsManager_->clearLayoutAnimationConfig(node->tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ReanimatedModuleProxy;

using namespace facebook;

typedef enum ExitingState_Legacy : std::uint8_t {
typedef enum class ExitingState_Legacy : std::uint8_t {
UNDEFINED = 1,
WAITING = 2,
ANIMATING = 4,
Expand Down Expand Up @@ -60,7 +60,7 @@ struct Node {
*/
struct MutationNode : public Node {
ShadowViewMutation mutation;
ExitingState_Legacy state = UNDEFINED;
ExitingState_Legacy state = ExitingState_Legacy::UNDEFINED;
explicit MutationNode(ShadowViewMutation &mutation) : Node(mutation.oldChildShadowView.tag), mutation(mutation) {}
MutationNode(ShadowViewMutation &mutation, Node &&node) : Node(std::move(node)), mutation(mutation) {}
bool isMutationNode() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace reanimated {

enum BeforeOrAfter : std::uint8_t { BEFORE = 0, AFTER = 1 };
enum BeforeOrAfter : std::uint8_t { BEFORE = 0, AFTER = 1 }; // NOLINT

struct Rect {
double width, height;
Expand Down Expand Up @@ -66,15 +66,15 @@ typedef enum class ExitingState : std::uint8_t {

struct MutationNode;

enum TransitionState : std::uint8_t {
enum class TransitionState : std::uint8_t {
NONE = 0,
START = 1,
ACTIVE = 2,
END = 3,
CANCELLED = 4,
};

enum Intent : std::uint8_t {
enum class Intent : std::uint8_t {
NO_INTENT = 0,
TO_MOVE = 1,
TO_DELETE = 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <react/renderer/components/scrollview/ScrollViewState.h>
#include <reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.h>
#include <reanimated/LayoutAnimations/LayoutAnimationsUtils.h>
#include <reanimated/Tools/ReanimatedSystraceSection.h>
#ifndef ANDROID
#if __has_include(<react/renderer/components/rnscreens/Props.h>)
Expand Down Expand Up @@ -62,9 +63,11 @@ void LayoutAnimationsProxy_Experimental::findSharedElementsOnScreen(
auto newTransform = parseParentTransforms(node, absolutePositions);
const auto &parent = node->parent.lock();
react_native_assert(parent && "Parent node is nullptr");
transform[index] = std::move(newTransform);
snapshot[index] = copy;
parentTag[index] = parent->current.tag;

int indexNum = static_cast<int>(index);
transform[indexNum] = std::move(newTransform);
snapshot[indexNum] = copy;
parentTag[indexNum] = parent->current.tag;

if (parentTag[BEFORE] && parentTag[AFTER]) {
transitions_.emplace_back(sharedTag, transition);
Expand All @@ -88,11 +91,11 @@ void LayoutAnimationsProxy_Experimental::handleProgressTransition(
}
transitionUpdated_ = false;

if (!mutations.empty() || !transitionState_) {
if (!mutations.empty() || !static_cast<bool>(transitionState_)) {
return;
}

if (transitionState_ == START) {
if (transitionState_ == TransitionState::START) {
auto root = lightNodes_[surfaceId];
auto beforeTopScreen = topScreen[surfaceId];
auto afterTopScreen = lightNodes_[transitionTag_];
Expand All @@ -119,7 +122,7 @@ void LayoutAnimationsProxy_Experimental::handleProgressTransition(
startProgressTransition(containerTag, before, after, surfaceId);
}
}
} else if (transitionState_ == ACTIVE) {
} else if (transitionState_ == TransitionState::ACTIVE) {
for (auto tag : activeTransitions_) {
auto layoutAnimation = layoutAnimations_[tag];
auto &updateMap = surfaceManager.getUpdateMap(layoutAnimation.finalView.surfaceId);
Expand Down Expand Up @@ -153,23 +156,23 @@ void LayoutAnimationsProxy_Experimental::handleProgressTransition(
}
}

if (transitionState_ == START) {
transitionState_ = ACTIVE;
} else if (transitionState_ == END || transitionState_ == CANCELLED) {
if (transitionState_ == TransitionState::START) {
transitionState_ = TransitionState::ACTIVE;
} else if (transitionState_ == TransitionState::END || transitionState_ == TransitionState::CANCELLED) {
for (auto tag : activeTransitions_) {
sharedContainersToRemove_.push_back(tag);
tagsToRestore_.push_back(restoreMap_[tag][AFTER]);
if (transitionState_ == CANCELLED) {
if (transitionState_ == TransitionState::CANCELLED) {
tagsToRestore_.push_back(restoreMap_[tag][BEFORE]);
}
}
if (transitionState_ == END) {
if (transitionState_ == TransitionState::END) {
topScreen[surfaceId] = lightNodes_[transitionTag_];
synchronized_ = false;
}
sharedTransitionManager_->containerTags_.clear();
activeTransitions_.clear();
transitionState_ = NONE;
transitionState_ = TransitionState::NONE;
}
}

Expand Down Expand Up @@ -278,8 +281,9 @@ void LayoutAnimationsProxy_Experimental::hideTransitioningViews(
ShadowViewMutationList &filteredMutations,
const PropsParserContext &propsParserContext) const {
for (auto &[sharedTag, transition] : transitions_) {
const auto &shadowView = transition.snapshot[index];
const auto &parentTag = transition.parentTag[index];
int indexNum = static_cast<int>(index);
Comment thread
wisniewskij marked this conversation as resolved.
const auto &shadowView = transition.snapshot[indexNum];
const auto &parentTag = transition.parentTag[indexNum];
auto m = ShadowViewMutation::UpdateMutation(
shadowView, cloneViewWithoutOpacity(shadowView, propsParserContext), parentTag);
filteredMutations.push_back(m);
Expand All @@ -303,11 +307,11 @@ std::optional<SurfaceId> LayoutAnimationsProxy_Experimental::onTransitionProgres
// transitions (maybe that's ok?)
if (!isClosing && !isGoingForward && !isAndroid) {
transitionProgress_ = progress;
if (transitionState_ == NONE && progress < 1) {
transitionState_ = START;
if (transitionState_ == TransitionState::NONE && progress < 1) {
transitionState_ = TransitionState::START;
transitionTag_ = tag;
} else if (transitionState_ == ACTIVE && progress == 1) {
transitionState_ = END;
} else if (transitionState_ == TransitionState::ACTIVE && progress == 1) {
transitionState_ = TransitionState::END;
}
const auto &node = lightNodes_[tag];
react_native_assert(node && "LightNode is nullptr");
Expand All @@ -320,8 +324,8 @@ std::optional<SurfaceId> LayoutAnimationsProxy_Experimental::onTransitionProgres

std::optional<SurfaceId> LayoutAnimationsProxy_Experimental::onGestureCancel() {
auto lock = std::unique_lock<std::recursive_mutex>(mutex);
if (transitionState_) {
transitionState_ = CANCELLED;
if (static_cast<bool>(transitionState_)) {
transitionState_ = TransitionState::CANCELLED;
transitionUpdated_ = true;
react_native_assert(transitioningSurfaceId_ != -1 && "Cancelling non-observed transition");

Expand Down
Loading
Loading