diff --git a/.github/workflows/lint-clang-tidy.yml b/.github/workflows/lint-clang-tidy.yml index c022d6e7c0b5..3c305a0df82d 100644 --- a/.github/workflows/lint-clang-tidy.yml +++ b/.github/workflows/lint-clang-tidy.yml @@ -7,6 +7,7 @@ on: - main paths: - '.github/workflows/lint-clang-tidy.yml' + - 'scripts/clang-tidy-lint.sh' merge_group: branches: @@ -15,6 +16,7 @@ on: pull_request: paths: - '.github/workflows/lint-clang-tidy.yml' + - 'scripts/clang-tidy-lint.sh' workflow_call: workflow_dispatch: @@ -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 diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.cpp index e989c2b23306..fd65b26bff19 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.cpp @@ -18,7 +18,7 @@ bool DelayedItemComparator::operator()(const DelayedItem &lhs, c } template -void DelayedItemsManager::add(const double timestamp, const TValue value) { +void DelayedItemsManager::add(const double timestamp, const TValue &value) { auto result = itemsSet_.emplace(timestamp, value); if (result.second) { itemsMap_[result.first->value] = result.first; @@ -38,7 +38,7 @@ typename DelayedItemsManager::Item DelayedItemsManager::pop() { } template -bool DelayedItemsManager::remove(const TValue value) { +bool DelayedItemsManager::remove(const TValue &value) { auto it = itemsMap_.find(value); if (it == itemsMap_.end()) { diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.h b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.h index 54fb72840156..ff84a60c0458 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.h @@ -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; diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.cpp index ba22e753391e..d904bf59a9e8 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.cpp @@ -32,7 +32,7 @@ std::optional LayoutAnimationsProxy_Experimental::pullTrans ShadowViewMutationList filteredMutations; auto rootChildCount = static_cast(lightNodes_[surfaceId]->children.size()); const std::vector> roots; - const bool isInTransition = transitionState_; + const bool isInTransition = static_cast(transitionState_); if (isInTransition) { updateLightTree(propsParserContext, mutations, filteredMutations); diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.h b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.h index 95604fd13638..eca44e4cf651 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.h @@ -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> topScreen; mutable int containerTag_ = 10000002; diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp index f39ba96f8770..3ee855c43269 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp @@ -124,7 +124,7 @@ std::optional LayoutAnimationsProxy_Legacy::endLayoutAnimation(int ta auto node = nodeForTag_[tag]; auto mutationNode = std::static_pointer_cast(node); - mutationNode->state = DEAD; + mutationNode->state = ExitingState_Legacy::DEAD; auto &[deadNodes] = surfaceContext_[surfaceId]; deadNodes.insert(mutationNode); @@ -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; @@ -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 @@ -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); } @@ -429,12 +429,12 @@ void LayoutAnimationsProxy_Legacy::endAnimationsRecursively( const std::shared_ptr &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); } } @@ -457,11 +457,11 @@ void LayoutAnimationsProxy_Legacy::maybeDropAncestors( auto node = std::static_pointer_cast(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 @@ -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> toBeRemoved; // iterate from the end, so that children @@ -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); @@ -516,21 +516,21 @@ 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; } } @@ -538,7 +538,7 @@ bool LayoutAnimationsProxy_Legacy::startAnimationsRecursively( node->removeChildFromUnflattenedTree(subNode); } - if (node->state == MOVED) { + if (node->state == ExitingState_Legacy::MOVED) { auto replacement = std::make_shared(*node); for (const auto &subNode : node->children) { subNode->parent = replacement; @@ -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); diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h index 5946b958d53b..e9a5e9959e89 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h @@ -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, @@ -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; diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h index f8cdaaa397f2..a5c860f72689 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h @@ -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; @@ -66,7 +66,7 @@ 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, @@ -74,7 +74,7 @@ enum TransitionState : std::uint8_t { CANCELLED = 4, }; -enum Intent : std::uint8_t { +enum class Intent : std::uint8_t { NO_INTENT = 0, TO_MOVE = 1, TO_DELETE = 2, diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/SharedTransitions.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/SharedTransitions.cpp index a8e08d255a75..c94f9bd69ee2 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/SharedTransitions.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/SharedTransitions.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #ifndef ANDROID #if __has_include() @@ -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(index); + transform[indexNum] = std::move(newTransform); + snapshot[indexNum] = copy; + parentTag[indexNum] = parent->current.tag; if (parentTag[BEFORE] && parentTag[AFTER]) { transitions_.emplace_back(sharedTag, transition); @@ -88,11 +91,11 @@ void LayoutAnimationsProxy_Experimental::handleProgressTransition( } transitionUpdated_ = false; - if (!mutations.empty() || !transitionState_) { + if (!mutations.empty() || !static_cast(transitionState_)) { return; } - if (transitionState_ == START) { + if (transitionState_ == TransitionState::START) { auto root = lightNodes_[surfaceId]; auto beforeTopScreen = topScreen[surfaceId]; auto afterTopScreen = lightNodes_[transitionTag_]; @@ -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); @@ -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; } } @@ -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(index); + 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); @@ -303,11 +307,11 @@ std::optional 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"); @@ -320,8 +324,8 @@ std::optional LayoutAnimationsProxy_Experimental::onTransitionProgres std::optional LayoutAnimationsProxy_Experimental::onGestureCancel() { auto lock = std::unique_lock(mutex); - if (transitionState_) { - transitionState_ = CANCELLED; + if (static_cast(transitionState_)) { + transitionState_ = TransitionState::CANCELLED; transitionUpdated_ = true; react_native_assert(transitioningSurfaceId_ != -1 && "Cancelling non-observed transition"); diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp index 2fb3e0f3f466..0d4efb14beb8 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp @@ -7,31 +7,31 @@ namespace reanimated { void UIRuntimeDecorator::decorate( jsi::Runtime &uiRuntime, - ObtainPropFunction obtainPropFunction, - UpdatePropsFunction updateProps, - MeasureFunction measure, - DispatchCommandFunction dispatchCommand, - GetAnimationTimestampFunction getAnimationTimestamp, - SetGestureStateFunction setGestureState, - ProgressLayoutAnimationFunction progressLayoutAnimation, - EndLayoutAnimationFunction endLayoutAnimation, - MaybeFlushUIUpdatesQueueFunction maybeFlushUIUpdatesQueue) { - - jsi_utils::installJsiFunction(uiRuntime, "_updateProps", std::move(updateProps)); - jsi_utils::installJsiFunction(uiRuntime, "_dispatchCommand", std::move(dispatchCommand)); - jsi_utils::installJsiFunction(uiRuntime, "_measure", std::move(measure)); - jsi_utils::installJsiFunction(uiRuntime, "_getAnimationTimestamp", std::move(getAnimationTimestamp)); - jsi_utils::installJsiFunction(uiRuntime, "_notifyAboutProgress", std::move(progressLayoutAnimation)); - jsi_utils::installJsiFunction(uiRuntime, "_notifyAboutEnd", std::move(endLayoutAnimation)); - jsi_utils::installJsiFunction(uiRuntime, "_setGestureState", std::move(setGestureState)); - jsi_utils::installJsiFunction(uiRuntime, "_obtainProp", std::move(obtainPropFunction)); - - subscribeForMicrotasksFinalization(uiRuntime, std::move(maybeFlushUIUpdatesQueue)); + const ObtainPropFunction &obtainPropFunction, + const UpdatePropsFunction &updateProps, + const MeasureFunction &measure, + const DispatchCommandFunction &dispatchCommand, + const GetAnimationTimestampFunction &getAnimationTimestamp, + const SetGestureStateFunction &setGestureState, + const ProgressLayoutAnimationFunction &progressLayoutAnimation, + const EndLayoutAnimationFunction &endLayoutAnimation, + const MaybeFlushUIUpdatesQueueFunction &maybeFlushUIUpdatesQueue) { + + jsi_utils::installJsiFunction(uiRuntime, "_updateProps", updateProps); + jsi_utils::installJsiFunction(uiRuntime, "_dispatchCommand", dispatchCommand); + jsi_utils::installJsiFunction(uiRuntime, "_measure", measure); + jsi_utils::installJsiFunction(uiRuntime, "_getAnimationTimestamp", getAnimationTimestamp); + jsi_utils::installJsiFunction(uiRuntime, "_notifyAboutProgress", progressLayoutAnimation); + jsi_utils::installJsiFunction(uiRuntime, "_notifyAboutEnd", endLayoutAnimation); + jsi_utils::installJsiFunction(uiRuntime, "_setGestureState", setGestureState); + jsi_utils::installJsiFunction(uiRuntime, "_obtainProp", obtainPropFunction); + + subscribeForMicrotasksFinalization(uiRuntime, maybeFlushUIUpdatesQueue); } void UIRuntimeDecorator::subscribeForMicrotasksFinalization( jsi::Runtime &uiRuntime, - MaybeFlushUIUpdatesQueueFunction maybeFlushUIUpdatesQueue) { + const MaybeFlushUIUpdatesQueueFunction &maybeFlushUIUpdatesQueue) { auto maybeMicrotaskQueueFinalizers = uiRuntime.global().getProperty(uiRuntime, "_microtaskQueueFinalizers"); if (maybeMicrotaskQueueFinalizers.isUndefined()) { @@ -50,7 +50,7 @@ void UIRuntimeDecorator::subscribeForMicrotasksFinalization( uiRuntime, jsi::PropNameID::forAscii(uiRuntime, "_maybeFlushUIUpdatesQueue"), 0, - jsi_utils::createHostFunction(std::move(maybeFlushUIUpdatesQueue)))); + jsi_utils::createHostFunction(maybeFlushUIUpdatesQueue))); } } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h b/packages/react-native-reanimated/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h index b86ac41f84c2..35ffacafb2dc 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h @@ -12,20 +12,20 @@ class UIRuntimeDecorator { public: static void decorate( jsi::Runtime &uiRuntime, - const ObtainPropFunction obtainPropFunction, - const UpdatePropsFunction updateProps, - const MeasureFunction measure, - const DispatchCommandFunction dispatchCommand, - const GetAnimationTimestampFunction getAnimationTimestamp, - const SetGestureStateFunction setGestureState, - const ProgressLayoutAnimationFunction progressLayoutAnimation, - const EndLayoutAnimationFunction endLayoutAnimation, - const MaybeFlushUIUpdatesQueueFunction maybeFlushUIUpdatesQueue); + const ObtainPropFunction &obtainPropFunction, + const UpdatePropsFunction &updateProps, + const MeasureFunction &measure, + const DispatchCommandFunction &dispatchCommand, + const GetAnimationTimestampFunction &getAnimationTimestamp, + const SetGestureStateFunction &setGestureState, + const ProgressLayoutAnimationFunction &progressLayoutAnimation, + const EndLayoutAnimationFunction &endLayoutAnimation, + const MaybeFlushUIUpdatesQueueFunction &maybeFlushUIUpdatesQueue); private: static void subscribeForMicrotasksFinalization( jsi::Runtime &uiRuntime, - MaybeFlushUIUpdatesQueueFunction maybeFlushUIUpdatesQueue); + const MaybeFlushUIUpdatesQueueFunction &maybeFlushUIUpdatesQueue); }; } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/Tools/ReaJSIUtils.h b/packages/react-native-reanimated/Common/cpp/reanimated/Tools/ReaJSIUtils.h index d1556c33dcd7..c87b872bb5ba 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/Tools/ReaJSIUtils.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/Tools/ReaJSIUtils.h @@ -75,7 +75,7 @@ inline std::tuple convertArgs(jsi::Runtime &rt, const jsi::Value *ar // native C++ types needed to call `function` template std::tuple -getArgsForFunction(std::function, jsi::Runtime &rt, const jsi::Value *args, const size_t count) { +getArgsForFunction(const std::function &, jsi::Runtime &rt, const jsi::Value *args, const size_t count) { react_native_assert(sizeof...(Args) == count && "Argument list has different length than expected"); return convertArgs(rt, args); } @@ -85,7 +85,7 @@ getArgsForFunction(std::function, jsi::Runtime &rt, const jsi::Val // passing `rt` as the first argument template std::tuple getArgsForFunction( - std::function, + const std::function &, jsi::Runtime &rt, const jsi::Value *args, const size_t count) { @@ -117,7 +117,7 @@ inline jsi::Value apply(std::function function, std::tuple -jsi::HostFunctionType createHostFunction(Fun function) { +jsi::HostFunctionType createHostFunction(const Fun &function) { return [function](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, const size_t count) { auto argz = getArgsForFunction(function, rt, args, count); return apply(function, std::move(argz)); @@ -127,7 +127,7 @@ jsi::HostFunctionType createHostFunction(Fun function) { // returns a function with JSI calling convention // from a native function `function` returning a string template -jsi::HostFunctionType createHostFunction(std::function function) { +jsi::HostFunctionType createHostFunction(const std::function &function) { return [function](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, const size_t count) { auto argz = getArgsForFunction(function, rt, args, count); return apply(rt, function, std::move(argz)); @@ -151,7 +151,7 @@ struct takes_runtime { // and installs it as a global function named `name` // in the `rt` JS runtime template -void installJsiFunction(jsi::Runtime &rt, std::string_view name, std::function function) { +void installJsiFunction(jsi::Runtime &rt, std::string_view name, const std::function &function) { auto clb = createHostFunction(function); auto argsCount = sizeof...(Args) - takes_runtime::value; jsi::Value jsiFunction = diff --git a/packages/react-native-reanimated/package.json b/packages/react-native-reanimated/package.json index 589502f22864..f0c9237bb248 100644 --- a/packages/react-native-reanimated/package.json +++ b/packages/react-native-reanimated/package.json @@ -14,7 +14,7 @@ "lint:js": "eslint src __tests__ __typetests__ && yarn prettier --check src __tests__ __typetests__", "lint:android": "../../scripts/validate-android.sh && ./android/gradlew -p android spotlessCheck -q && ../../scripts/cpplint.sh android/src && yarn format:android:cpp --dry-run -Werror && yarn lint:cmake", "lint:common": "../../scripts/validate-common.sh && ../../scripts/cpplint.sh Common && yarn format:common --dry-run -Werror", - "lint:clang-tidy": "find Common -iname \"*.h\" -o -iname \"*.cpp\" | xargs ../../scripts/clang-tidy-lint.sh", + "lint:clang-tidy": "../../scripts/clang-tidy-lint.sh \"Common\"", "lint:apple": "../../scripts/validate-apple.sh && yarn format:apple --dry-run -Werror", "lint:cmake": "find ./android -type d \\( -name build -o -name .cxx \\) -prune -o -type f -name 'CMakeLists.txt' -print | xargs ../../scripts/lint-cmake.sh", "format": "yarn format:js && yarn format:apple && yarn format:android && yarn format:common", diff --git a/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Serializable.h b/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Serializable.h index 1c20158074ff..a67df49654e4 100644 --- a/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Serializable.h +++ b/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Serializable.h @@ -52,7 +52,7 @@ class RetainingSerializable : virtual public BaseClass { explicit RetainingSerializable(jsi::Runtime &rt, Args &&...args) : BaseClass(rt, std::forward(args)...), primaryRuntime_(&rt) {} - jsi::Value toJSValue(jsi::Runtime &rt) { + jsi::Value toJSValue(jsi::Runtime &rt) override { if (&rt == primaryRuntime_) { // TODO: it is suboptimal to generate new object every time getJS is // called on host runtime – the objects we are generating already exists @@ -74,7 +74,7 @@ class RetainingSerializable : virtual public BaseClass { return BaseClass::toJSValue(rt); } - ~RetainingSerializable() { + ~RetainingSerializable() override { cleanupIfRuntimeExists(secondaryRuntime_, secondaryValue_); } }; diff --git a/packages/react-native-worklets/Common/cpp/worklets/Tools/WorkletsJSIUtils.h b/packages/react-native-worklets/Common/cpp/worklets/Tools/WorkletsJSIUtils.h index 975819a7e13d..c713bb7a72c3 100644 --- a/packages/react-native-worklets/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +++ b/packages/react-native-worklets/Common/cpp/worklets/Tools/WorkletsJSIUtils.h @@ -84,7 +84,7 @@ getArgsForFunction(std::function, jsi::Runtime &rt, const jsi::Val // passing `rt` as the first argument template std::tuple getArgsForFunction( - std::function, + const std::function &, jsi::Runtime &rt, const jsi::Value *args, const size_t count) { @@ -116,7 +116,7 @@ inline jsi::Value apply(std::function function, std::tuple -jsi::HostFunctionType createHostFunction(Fun function) { +jsi::HostFunctionType createHostFunction(const Fun &function) { return [function](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, const size_t count) { auto argz = getArgsForFunction(function, rt, args, count); return apply(function, std::move(argz)); @@ -150,7 +150,7 @@ struct takes_runtime { // and installs it as a global function named `name` // in the `rt` JS runtime template -void installJsiFunction(jsi::Runtime &rt, std::string_view name, std::function function) { +void installJsiFunction(jsi::Runtime &rt, std::string_view name, const std::function &function) { auto clb = createHostFunction(function); auto argsCount = sizeof...(Args) - takes_runtime::value; jsi::Value jsiFunction = diff --git a/packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp b/packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp index 2337198d7de2..f47905bc98e6 100644 --- a/packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp +++ b/packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp @@ -8,12 +8,13 @@ namespace worklets { void UIRuntimeDecorator::decorate( facebook::jsi::Runtime &uiRuntime, - std::function &&requestAnimationFrame) { + const std::function + &requestAnimationFrame) { uiRuntime.global().setProperty(uiRuntime, runtimeKindBindingName, static_cast(RuntimeKind::UI)); uiRuntime.global().setProperty(uiRuntime, "_UI", true); - jsi_utils::installJsiFunction(uiRuntime, "requestAnimationFrame", std::move(requestAnimationFrame)); + jsi_utils::installJsiFunction(uiRuntime, "requestAnimationFrame", requestAnimationFrame); } } // namespace worklets diff --git a/packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h b/packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h index 717d6c9af892..55064b5f8c43 100644 --- a/packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h +++ b/packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h @@ -8,7 +8,8 @@ class UIRuntimeDecorator { public: static void decorate( facebook::jsi::Runtime &uiRuntime, - std::function &&requestAnimationFrame); + const std::function + &requestAnimationFrame); }; } // namespace worklets diff --git a/packages/react-native-worklets/package.json b/packages/react-native-worklets/package.json index 8a969933ea98..d5b6f71d5298 100644 --- a/packages/react-native-worklets/package.json +++ b/packages/react-native-worklets/package.json @@ -27,7 +27,7 @@ "lint:apple": "../../scripts/validate-apple.sh && yarn format:apple --dry-run -Werror", "lint:common": "../../scripts/validate-common.sh && ../../scripts/cpplint.sh Common && yarn format:common --dry-run -Werror", "lint:cmake": "find ./android -type d \\( -name build -o -name .cxx \\) -prune -o -type f -name 'CMakeLists.txt' -print | xargs ../../scripts/lint-cmake.sh", - "lint:clang-tidy": "find Common -iname \"*.h\" -o -iname \"*.cpp\" | xargs ../../scripts/clang-tidy-lint.sh", + "lint:clang-tidy": "../../scripts/clang-tidy-lint.sh \"Common\"", "lint:js": "eslint src && yarn prettier --check src", "lint:plugin": "yarn workspace babel-plugin-worklets lint", "test": "jest", diff --git a/scripts/clang-tidy-lint.sh b/scripts/clang-tidy-lint.sh index de37686f7ae9..5449aaf4f3f6 100755 --- a/scripts/clang-tidy-lint.sh +++ b/scripts/clang-tidy-lint.sh @@ -1,12 +1,12 @@ #!/bin/bash -if ! which clang-tidy >/dev/null; then - echo "error: clang-tidy not installed, download \ +if ! which run-clang-tidy >/dev/null; then + echo "error: run-clang-tidy not installed, download \ from https://clang.llvm.org/extra/clang-tidy/" 1>&2 exit 1 fi -if [ ! -f "../../compile_commands.json" ]; then +if [ ! -f "compile_commands.json" ]; then echo "info: missing compile_commands.json, generating one" ( cd ../../apps/fabric-example || exit 1 @@ -15,4 +15,4 @@ if [ ! -f "../../compile_commands.json" ]; then ) fi -clang-tidy --quiet "$@" +run-clang-tidy -quiet -p . -header-filter="^.*/$1/.*\.h$" "$1"