diff --git a/.clang-format b/.clang-format index 58f9bc65a8e2..823ad543d17a 100644 --- a/.clang-format +++ b/.clang-format @@ -18,18 +18,6 @@ AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: true BinPackArguments: false BinPackParameters: false -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false BreakBeforeBinaryOperators: None BreakBeforeBraces: Attach BreakBeforeTernaryOperators: true diff --git a/.clang-tidy b/.clang-tidy index dfa17fd762cb..c4050ea6ea03 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -34,7 +34,7 @@ Checks: # - misc-* # - modernize-* # - objc-* - # - performance-* + - performance-* # - portability-* # - readability-* WarningsAsErrors: '*' diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp index 02588bd67474..0d30561a45e1 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp @@ -32,7 +32,7 @@ jsi::Value AnimatedSensorModule::registerSensor( "[Reanimated] Sensor event handler must be a worklet."); int sensorId = platformRegisterSensorFunction_( - sensorType, + static_cast(sensorType), interval.asNumber(), iosReferenceFrame.asNumber(), [sensorType, diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h b/packages/react-native-reanimated/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h index f813079bfccc..5b3758231692 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h @@ -15,7 +15,7 @@ namespace reanimated { using namespace facebook; using namespace worklets; -enum SensorType { +enum class SensorType : std::uint8_t { ACCELEROMETER = 1, GYROSCOPE = 2, GRAVITY = 3, diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/transforms/TransformOp.h b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/transforms/TransformOp.h index 846b32ed7b83..da78da2f4937 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/transforms/TransformOp.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/transforms/TransformOp.h @@ -4,7 +4,7 @@ namespace reanimated::css { -enum class TransformOp { +enum class TransformOp : std::uint8_t { Perspective, Rotate, RotateX, diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/values/CSSColor.h b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/values/CSSColor.h index 6f5a08e8875d..39a7e42a95d9 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/values/CSSColor.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/values/CSSColor.h @@ -7,7 +7,7 @@ namespace reanimated::css { -enum class ColorType { +enum class ColorType : std::uint8_t { Rgba, Transparent, CurrentColor, // for SVG diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/values/CSSValue.h b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/values/CSSValue.h index 7f39c938d5a3..b90e474856ca 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/values/CSSValue.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/values/CSSValue.h @@ -10,7 +10,7 @@ namespace reanimated::css { using namespace facebook; -enum class RelativeTo { +enum class RelativeTo : std::uint8_t { Parent, Self, }; diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.cpp index c9a7bfedcb27..d84a2c4520cb 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.cpp @@ -124,7 +124,8 @@ template std::unordered_map parseHelper( jsi::Runtime &rt, const jsi::Object &settingsObj, - std::function parseFunction) { + const std::function + &parseFunction) { std::unordered_map result; const auto animationIndices = settingsObj.getPropertyNames(rt); @@ -173,14 +174,13 @@ CSSAnimationUpdates parseCSSAnimationUpdates( CSSAnimationUpdates result; if (configObj.hasProperty(rt, "animationNames")) { - const auto animationNames = + result.animationNames = parseAnimationNames(rt, configObj.getProperty(rt, "animationNames")); - result.animationNames = std::move(animationNames); if (configObj.hasProperty(rt, "newAnimationSettings")) { result.newAnimationSettings = parseNewAnimationSettings( rt, - animationNames, + result.animationNames.value(), configObj.getProperty(rt, "newAnimationSettings")); } } diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.h b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.h index 1defb7b8cf82..6a0c160f1818 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.h @@ -11,9 +11,14 @@ namespace reanimated::css { -enum class AnimationDirection { Normal, Reverse, Alternate, AlternateReverse }; -enum class AnimationFillMode { None, Forwards, Backwards, Both }; -enum class AnimationPlayState { Running, Paused }; +enum class AnimationDirection : std::uint8_t { + Normal, + Reverse, + Alternate, + AlternateReverse +}; +enum class AnimationFillMode : std::uint8_t { None, Forwards, Backwards, Both }; +enum class AnimationPlayState : std::uint8_t { Running, Paused }; struct CSSAnimationSettings { double duration; diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/interpolation/transforms/operations/matrix.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/interpolation/transforms/operations/matrix.cpp index 97f2cb1c63c8..d8335bd9ba3d 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/interpolation/transforms/operations/matrix.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/interpolation/transforms/operations/matrix.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include @@ -143,7 +142,7 @@ MatrixOperation::MatrixOperation(TransformOperations operations) // Simplify operations to reduce the number of matrix // multiplications during matrix keyframe interpolation : TransformOperation(TransformOp::Matrix), value([&]() { - const auto &[value, is3D] = simplifyOperations(std::move(operations)); + const auto &[value, is3D] = simplifyOperations(operations); is3D_ = is3D; return value; }()) {} diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/progress/AnimationProgressProvider.h b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/progress/AnimationProgressProvider.h index 74f22579ae97..84432d7c0232 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/progress/AnimationProgressProvider.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/progress/AnimationProgressProvider.h @@ -10,7 +10,7 @@ namespace reanimated::css { -enum class AnimationProgressState { +enum class AnimationProgressState : std::uint8_t { Pending, // When the animation is waiting for the delay to pass Running, Paused, diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/progress/TransitionProgressProvider.h b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/progress/TransitionProgressProvider.h index 696605b3129a..602a4e5cd209 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/progress/TransitionProgressProvider.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/progress/TransitionProgressProvider.h @@ -12,7 +12,11 @@ namespace reanimated::css { -enum class TransitionProgressState { Pending, Running, Finished }; +enum class TransitionProgressState : std::uint8_t { + Pending, + Running, + Finished +}; class TransitionPropertyProgressProvider final : public KeyframeProgressProvider, diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.cpp index 70406e6993db..dd0b5eb2e822 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.cpp @@ -20,7 +20,7 @@ void CSSAnimationsRegistry::apply( const CSSAnimationsMap &newAnimations, const CSSAnimationSettingsUpdatesMap &settingsUpdates, double timestamp) { - const auto animationsVector = + auto animationsVector = buildAnimationsVector(rt, shadowNode, animationNames, newAnimations); const auto viewTag = shadowNode->getTag(); @@ -29,12 +29,6 @@ void CSSAnimationsRegistry::apply( return; } - registry_.erase(viewTag); - registry_.emplace( - viewTag, - RegistryEntry{ - std::move(animationsVector), - buildAnimationToIndexMap(animationsVector)}); runningAnimationIndicesMap_[viewTag].clear(); std::vector updatedIndices; @@ -49,6 +43,14 @@ void CSSAnimationsRegistry::apply( for (size_t i = 0; i < animationsVector.size(); ++i) { scheduleOrActivateAnimation(i, animationsVector[i], timestamp); } + + auto animationToIndexMap = buildAnimationToIndexMap(animationsVector); + registry_.erase(viewTag); + registry_.emplace( + viewTag, + RegistryEntry{ + std::move(animationsVector), std::move(animationToIndexMap)}); + updateViewAnimations(viewTag, updatedIndices, timestamp, false); applyViewAnimationsStyle(viewTag, timestamp); } @@ -93,7 +95,7 @@ CSSAnimationsVector CSSAnimationsRegistry::buildAnimationsVector( // the registry if (!animationNames.has_value()) { if (registryIt != registry_.end()) { - return std::move(registryIt->second.animationsVector); + return registryIt->second.animationsVector; } } 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 fbb9dba1ea64..2a36e9a71063 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 @@ -3,8 +3,8 @@ namespace reanimated::css { template -DelayedItem::DelayedItem(const double timestamp, const TValue value) - : timestamp(timestamp), value(value) {} +DelayedItem::DelayedItem(double timestamp, TValue value) + : timestamp(timestamp), value(std::move(value)) {} template bool DelayedItemComparator::operator()( diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h index 6c36ae057a0a..8462001137b4 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h @@ -1,6 +1,8 @@ #pragma once -typedef enum LayoutAnimationType { +#include + +typedef enum class LayoutAnimationType : std::uint8_t { ENTERING = 1, EXITING = 2, LAYOUT = 3, diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp index 63ccbd7e5da8..8ea8d217acfc 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp @@ -9,9 +9,9 @@ namespace reanimated { void LayoutAnimationsManager::configureAnimationBatch( const std::vector &layoutAnimationsBatch) { auto lock = std::unique_lock(animationsMutex_); - for (auto layoutAnimationConfig : layoutAnimationsBatch) { + for (const auto &layoutAnimationConfig : layoutAnimationsBatch) { const auto &[tag, type, config] = layoutAnimationConfig; - if (type == ENTERING) { + if (type == LayoutAnimationType::ENTERING) { enteringAnimationsForNativeID_[tag] = config; continue; } @@ -110,11 +110,11 @@ void LayoutAnimationsManager::transferConfigFromNativeID( std::unordered_map> & LayoutAnimationsManager::getConfigsForType(const LayoutAnimationType type) { switch (type) { - case ENTERING: + case LayoutAnimationType::ENTERING: return enteringAnimations_; - case EXITING: + case LayoutAnimationType::EXITING: return exitingAnimations_; - case LAYOUT: + case LayoutAnimationType::LAYOUT: return layoutAnimations_; default: throw std::invalid_argument("[Reanimated] Unknown layout animation type"); diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp index 45cbd8580fb8..87e5911eefd9 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp @@ -131,7 +131,7 @@ std::optional LayoutAnimationsProxy::endLayoutAnimation( auto node = nodeForTag_[tag]; auto mutationNode = std::static_pointer_cast(node); - mutationNode->state = DEAD; + mutationNode->state = ExitingState::DEAD; deadNodes.insert(mutationNode); return surfaceId; @@ -182,7 +182,7 @@ void LayoutAnimationsProxy::parseRemoveMutations( } } if (!deletedViews.contains(mutation.oldChildShadowView.tag)) { - mutationNode->state = MOVED; + mutationNode->state = ExitingState::MOVED; movedViews.insert_or_assign(mutation.oldChildShadowView.tag, -1); } nodeForTag_[tag] = mutationNode; @@ -256,12 +256,13 @@ void LayoutAnimationsProxy::handleRemovals( node, true, true, false, filteredMutations)) { filteredMutations.push_back(node->mutation); node->unflattenedParent->removeChildFromUnflattenedTree(node); //??? - if (node->state != MOVED) { + if (node->state != ExitingState::MOVED) { maybeCancelAnimation(node->tag); - filteredMutations.push_back(ShadowViewMutation::DeleteMutation( - node->mutation.oldChildShadowView)); + filteredMutations.push_back( + ShadowViewMutation::DeleteMutation( + node->mutation.oldChildShadowView)); nodeForTag_.erase(node->tag); - node->state = DELETED; + node->state = ExitingState::DELETED; #ifdef LAYOUT_ANIMATIONS_LOGS LOG(INFO) << "delete " << node->tag << std::endl; #endif @@ -269,8 +270,8 @@ void LayoutAnimationsProxy::handleRemovals( } } - for (auto node : deadNodes) { - if (node->state != DELETED) { + for (const auto &node : deadNodes) { + if (node->state != ExitingState::DELETED) { endAnimationsRecursively(node, filteredMutations); maybeDropAncestors(node->unflattenedParent, node, filteredMutations); } @@ -311,10 +312,11 @@ void LayoutAnimationsProxy::handleUpdatesAndEnterings( auto layoutAnimationIt = layoutAnimations_.find(tag); if (layoutAnimationIt == layoutAnimations_.end()) { if (oldShadowViewsForReparentings.contains(tag)) { - filteredMutations.push_back(ShadowViewMutation::InsertMutation( - mutationParent, - oldShadowViewsForReparentings[tag], - mutation.index)); + filteredMutations.push_back( + ShadowViewMutation::InsertMutation( + mutationParent, + oldShadowViewsForReparentings[tag], + mutation.index)); } else { filteredMutations.push_back(mutation); } @@ -322,8 +324,9 @@ void LayoutAnimationsProxy::handleUpdatesAndEnterings( } auto oldView = *layoutAnimationIt->second.currentView; - filteredMutations.push_back(ShadowViewMutation::InsertMutation( - mutationParent, oldView, mutation.index)); + filteredMutations.push_back( + ShadowViewMutation::InsertMutation( + mutationParent, oldView, mutation.index)); if (movedViews.contains(tag)) { layoutAnimationIt->second.parentTag = movedViews.at(tag); } @@ -333,7 +336,8 @@ void LayoutAnimationsProxy::handleUpdatesAndEnterings( transferConfigFromNativeID( mutation.newChildShadowView.props->nativeId, mutation.newChildShadowView.tag); - if (!layoutAnimationsManager_->hasLayoutAnimation(tag, ENTERING)) { + if (!layoutAnimationsManager_->hasLayoutAnimation( + tag, LayoutAnimationType::ENTERING)) { filteredMutations.push_back(mutation); continue; } @@ -345,14 +349,16 @@ void LayoutAnimationsProxy::handleUpdatesAndEnterings( std::shared_ptr newView = cloneViewWithoutOpacity(mutation, propsParserContext); - filteredMutations.push_back(ShadowViewMutation::UpdateMutation( - mutation.newChildShadowView, *newView, mutationParent)); + filteredMutations.push_back( + ShadowViewMutation::UpdateMutation( + mutation.newChildShadowView, *newView, mutationParent)); break; } case ShadowViewMutation::Type::Update: { auto shouldAnimate = hasLayoutChanged(mutation); - if (!layoutAnimationsManager_->hasLayoutAnimation(tag, LAYOUT) || + if (!layoutAnimationsManager_->hasLayoutAnimation( + tag, LayoutAnimationType::LAYOUT) || (!shouldAnimate && !layoutAnimations_.contains(tag))) { // We should cancel any ongoing animation here to ensure that the // proper final state is reached for this view However, due to how @@ -397,6 +403,8 @@ void LayoutAnimationsProxy::addOngoingAnimations( auto &updateMap = surfaceManager.getUpdateMap(surfaceId); #ifdef ANDROID std::vector tagsToUpdate; + tagsToUpdate.reserve(updateMap.size()); + for (auto &[tag, updateValues] : updateMap) { tagsToUpdate.push_back(tag); } @@ -437,25 +445,26 @@ void LayoutAnimationsProxy::addOngoingAnimations( newView->props = updateValues.newProps; updateLayoutMetrics(newView->layoutMetrics, updateValues.frame); - mutations.push_back(ShadowViewMutation::UpdateMutation( - *layoutAnimation.currentView, *newView, layoutAnimation.parentTag)); + mutations.push_back( + ShadowViewMutation::UpdateMutation( + *layoutAnimation.currentView, *newView, layoutAnimation.parentTag)); layoutAnimation.currentView = newView; } updateMap.clear(); } void LayoutAnimationsProxy::endAnimationsRecursively( - std::shared_ptr node, + const std::shared_ptr &node, ShadowViewMutationList &mutations) const { maybeCancelAnimation(node->tag); - node->state = DELETED; + node->state = ExitingState::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::DELETED) { endAnimationsRecursively(subNode, mutations); } } @@ -469,8 +478,8 @@ void LayoutAnimationsProxy::endAnimationsRecursively( } void LayoutAnimationsProxy::maybeDropAncestors( - std::shared_ptr parent, - std::shared_ptr child, + const std::shared_ptr &parent, + const std::shared_ptr &child, ShadowViewMutationList &cleanupMutations) const { parent->removeChildFromUnflattenedTree(child); if (!parent->isMutationMode()) { @@ -479,11 +488,11 @@ void LayoutAnimationsProxy::maybeDropAncestors( auto node = std::static_pointer_cast(parent); - if (node->children.size() == 0 && node->state != ANIMATING) { + if (node->children.size() == 0 && node->state != ExitingState::ANIMATING) { nodeForTag_.erase(node->tag); cleanupMutations.push_back(node->mutation); maybeCancelAnimation(node->tag); - node->state = DELETED; + node->state = ExitingState::DELETED; #ifdef LAYOUT_ANIMATIONS_LOGS LOG(INFO) << "delete " << node->tag << std::endl; #endif @@ -500,7 +509,7 @@ LayoutAnimationsProxy::getComponentDescriptorForShadowView( } bool LayoutAnimationsProxy::startAnimationsRecursively( - std::shared_ptr node, + const std::shared_ptr &node, bool shouldRemoveSubviewsWithoutAnimations, bool shouldAnimate, bool isScreenPop, @@ -519,7 +528,7 @@ bool LayoutAnimationsProxy::startAnimationsRecursively( shouldRemoveSubviewsWithoutAnimations = shouldRemoveSubviewsWithoutAnimations && - (!hasExitAnimation || node->state == MOVED); + (!hasExitAnimation || node->state == ExitingState::MOVED); std::vector> toBeRemoved; // iterate from the end, so that children @@ -533,8 +542,9 @@ bool LayoutAnimationsProxy::startAnimationsRecursively( << " " << shouldAnimate << " " << shouldRemoveSubviewsWithoutAnimations << std::endl; #endif - if (subNode->state != UNDEFINED && subNode->state != MOVED) { - if (shouldAnimate && subNode->state != DEAD) { + if (subNode->state != ExitingState::UNDEFINED && + subNode->state != ExitingState::MOVED) { + if (shouldAnimate && subNode->state != ExitingState::DEAD) { hasAnimatedChildren = true; } else { endAnimationsRecursively(subNode, mutations); @@ -551,22 +561,23 @@ bool LayoutAnimationsProxy::startAnimationsRecursively( << " start animations returned true " << std::endl; #endif hasAnimatedChildren = true; - } else if (subNode->state == MOVED) { + } else if (subNode->state == ExitingState::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::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)); + mutations.push_back( + ShadowViewMutation::DeleteMutation( + subNode->mutation.oldChildShadowView)); } else { - subNode->state = WAITING; + subNode->state = ExitingState::WAITING; } } @@ -574,12 +585,12 @@ bool LayoutAnimationsProxy::startAnimationsRecursively( node->removeChildFromUnflattenedTree(subNode); } - if (node->state == MOVED) { + if (node->state == ExitingState::MOVED) { auto replacement = std::make_shared(*node); - for (auto subNode : node->children) { + for (const auto &subNode : node->children) { subNode->parent = replacement; } - for (auto subNode : node->unflattenedChildren) { + for (const auto &subNode : node->unflattenedChildren) { subNode->unflattenedParent = replacement; } nodeForTag_[replacement->tag] = replacement; @@ -589,7 +600,7 @@ bool LayoutAnimationsProxy::startAnimationsRecursively( bool wantAnimateExit = hasExitAnimation || hasAnimatedChildren; if (hasExitAnimation) { - node->state = ANIMATING; + node->state = ExitingState::ANIMATING; startExitingAnimation(node->tag, node->mutation); } else { layoutAnimationsManager_->clearLayoutAnimationConfig(node->tag); @@ -829,7 +840,7 @@ void LayoutAnimationsProxy::maybeCancelAnimation(const int tag) const { } void LayoutAnimationsProxy::transferConfigFromNativeID( - const std::string nativeIdString, + const std::string &nativeIdString, const int tag) const { if (nativeIdString.empty()) { return; diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h index 846e7cdac789..d8ea1e5102b7 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h @@ -16,6 +16,7 @@ #include #include #include +#include #include namespace reanimated { @@ -33,9 +34,8 @@ struct LayoutAnimation { LayoutAnimation &operator=(const LayoutAnimation &other) = default; }; -struct LayoutAnimationsProxy - : public MountingOverrideDelegate, - public std::enable_shared_from_this { +struct LayoutAnimationsProxy : public MountingOverrideDelegate, + public std::enable_shared_from_this { mutable std::unordered_map> nodeForTag_; mutable std::unordered_map layoutAnimations_; mutable std::recursive_mutex mutex; @@ -59,7 +59,7 @@ struct LayoutAnimationsProxy SharedComponentDescriptorRegistry componentDescriptorRegistry, std::shared_ptr contextContainer, jsi::Runtime &uiRuntime, - const std::shared_ptr uiScheduler + const std::shared_ptr &uiScheduler #ifdef ANDROID , PreserveMountedTagsFunction filterUnmountedTagsFunction, @@ -67,31 +67,26 @@ struct LayoutAnimationsProxy std::shared_ptr jsInvoker #endif ) - : layoutAnimationsManager_(layoutAnimationsManager), - contextContainer_(contextContainer), - componentDescriptorRegistry_(componentDescriptorRegistry), + : layoutAnimationsManager_(std::move(layoutAnimationsManager)), + contextContainer_(std::move(contextContainer)), + componentDescriptorRegistry_(std::move(componentDescriptorRegistry)), uiRuntime_(uiRuntime), uiScheduler_(uiScheduler) #ifdef ANDROID , - preserveMountedTags_(filterUnmountedTagsFunction), - uiManager_(uiManager), - jsInvoker_(jsInvoker) + preserveMountedTags_(std::move(filterUnmountedTagsFunction)), + uiManager_(std::move(uiManager)), + jsInvoker_(std::move(jsInvoker)) #endif // ANDROID { } - void startEnteringAnimation(const int tag, ShadowViewMutation &mutation) - const; + void startEnteringAnimation(const int tag, ShadowViewMutation &mutation) const; void startExitingAnimation(const int tag, ShadowViewMutation &mutation) const; - void startLayoutAnimation(const int tag, const ShadowViewMutation &mutation) - const; + void startLayoutAnimation(const int tag, const ShadowViewMutation &mutation) const; - void transferConfigFromNativeID(const std::string nativeId, const int tag) - const; - std::optional progressLayoutAnimation( - int tag, - const jsi::Object &newStyle); + void transferConfigFromNativeID(const std::string &nativeId, const int tag) const; + std::optional progressLayoutAnimation(int tag, const jsi::Object &newStyle); std::optional endLayoutAnimation(int tag, bool shouldRemove); void maybeCancelAnimation(const int tag) const; @@ -99,9 +94,8 @@ struct LayoutAnimationsProxy std::unordered_map &movedViews, ShadowViewMutationList &mutations, std::vector> &roots) const; - void handleRemovals( - ShadowViewMutationList &filteredMutations, - std::vector> &roots) const; + void handleRemovals(ShadowViewMutationList &filteredMutations, std::vector> &roots) + const; void handleUpdatesAndEnterings( ShadowViewMutationList &filteredMutations, @@ -109,21 +103,13 @@ struct LayoutAnimationsProxy ShadowViewMutationList &mutations, const PropsParserContext &propsParserContext, SurfaceId surfaceId) const; - void addOngoingAnimations( - SurfaceId surfaceId, - ShadowViewMutationList &mutations) const; - void updateOngoingAnimationTarget( - const int tag, - const ShadowViewMutation &mutation) const; + void addOngoingAnimations(SurfaceId surfaceId, ShadowViewMutationList &mutations) const; + void updateOngoingAnimationTarget(const int tag, const ShadowViewMutation &mutation) const; std::shared_ptr cloneViewWithoutOpacity( facebook::react::ShadowViewMutation &mutation, const PropsParserContext &propsParserContext) const; - void maybeRestoreOpacity( - LayoutAnimation &layoutAnimation, - const jsi::Object &newStyle) const; - void maybeUpdateWindowDimensions( - facebook::react::ShadowViewMutation &mutation, - SurfaceId surfaceId) const; + void maybeRestoreOpacity(LayoutAnimation &layoutAnimation, const jsi::Object &newStyle) const; + void maybeUpdateWindowDimensions(facebook::react::ShadowViewMutation &mutation, SurfaceId surfaceId) const; void createLayoutAnimation( const ShadowViewMutation &mutation, ShadowView &oldView, @@ -132,29 +118,23 @@ struct LayoutAnimationsProxy void updateIndexForMutation(ShadowViewMutation &mutation) const; - void removeRecursively( - std::shared_ptr node, - ShadowViewMutationList &mutations) const; + void removeRecursively(std::shared_ptr node, ShadowViewMutationList &mutations) const; bool startAnimationsRecursively( - std::shared_ptr node, + const std::shared_ptr &node, const bool shouldRemoveSubviewsWithoutAnimations, const bool shouldAnimate, const bool isScreenPop, ShadowViewMutationList &mutations) const; - void endAnimationsRecursively( - std::shared_ptr node, - ShadowViewMutationList &mutations) const; + void endAnimationsRecursively(const std::shared_ptr &node, ShadowViewMutationList &mutations) const; void maybeDropAncestors( - std::shared_ptr node, - std::shared_ptr child, + const std::shared_ptr &node, + const std::shared_ptr &child, ShadowViewMutationList &cleanupMutations) const; - const ComponentDescriptor &getComponentDescriptorForShadowView( - const ShadowView &shadowView) const; + const ComponentDescriptor &getComponentDescriptorForShadowView(const ShadowView &shadowView) const; #ifdef ANDROID void restoreOpacityInCaseOfFlakyEnteringAnimation(SurfaceId surfaceId) const; - const ShadowNode *findInShadowTreeByTag(const ShadowNode &node, Tag tag) - const; + const ShadowNode *findInShadowTreeByTag(const ShadowNode &node, Tag tag) const; #endif // ANDROID // MountingOverrideDelegate diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp index 3333653ddbeb..4b72c6225b15 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp @@ -29,7 +29,7 @@ Rect SurfaceManager::getWindow(SurfaceId surfaceId) { return Rect{0, 0}; } -void Node::applyMutationToIndices(ShadowViewMutation mutation) { +void Node::applyMutationToIndices(const ShadowViewMutation &mutation) { const auto parentTag = mutation.parentTag; if (tag != parentTag) { return; @@ -45,7 +45,8 @@ void Node::applyMutationToIndices(ShadowViewMutation mutation) { } // Should only be called on unflattened parents -void Node::removeChildFromUnflattenedTree(std::shared_ptr child) { +void Node::removeChildFromUnflattenedTree( + const std::shared_ptr &child) { for (int i = unflattenedChildren.size() - 1; i >= 0; i--) { if (unflattenedChildren[i]->tag == child->tag) { unflattenedChildren.erase(unflattenedChildren.begin() + i); 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 8cf936a4ad25..962d0e195c7d 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h @@ -53,7 +53,7 @@ struct Snapshot { } }; -typedef enum ExitingState { +typedef enum class ExitingState : std::uint8_t { UNDEFINED = 1, WAITING = 2, ANIMATING = 4, @@ -72,14 +72,15 @@ struct Node { std::vector> children, unflattenedChildren; std::shared_ptr parent, unflattenedParent; Tag tag; - void removeChildFromUnflattenedTree(std::shared_ptr child); - void applyMutationToIndices(ShadowViewMutation mutation); + void removeChildFromUnflattenedTree( + const std::shared_ptr &child); + void applyMutationToIndices(const ShadowViewMutation &mutation); void insertChildren(std::vector> &newChildren); void insertUnflattenedChildren( std::vector> &newChildren); virtual bool isMutationMode(); explicit Node(const Tag tag) : tag(tag) {} - Node(Node &&node) + Node(Node &&node) noexcept : children(std::move(node.children)), unflattenedChildren(std::move(node.unflattenedChildren)), tag(node.tag) {} @@ -95,7 +96,7 @@ struct Node { */ struct MutationNode : public Node { ShadowViewMutation mutation; - ExitingState state = UNDEFINED; + ExitingState state = ExitingState::UNDEFINED; explicit MutationNode(ShadowViewMutation &mutation) : Node(mutation.oldChildShadowView.tag), mutation(mutation) {} MutationNode(ShadowViewMutation &mutation, Node &&node) @@ -134,7 +135,7 @@ static inline void updateLayoutMetrics( } } -static inline bool isRNSScreen(std::shared_ptr node) { +static inline bool isRNSScreen(const std::shared_ptr &node) { const auto &componentName = node->mutation.oldChildShadowView.componentName; return !std::strcmp(componentName, "RNSScreenStack") || !std::strcmp(componentName, "RNSScreen") || diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp index 218e5362a703..af6d12e42588 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp @@ -242,8 +242,7 @@ jsi::Value ReanimatedModuleProxy::registerEventHandler( eventNameStr, emitterReactTagInt, handlerSerializable); - strongThis->eventHandlerRegistry_->registerEventHandler( - std::move(handler)); + strongThis->eventHandlerRegistry_->registerEventHandler(handler); }); return jsi::Value(static_cast(newRegistrationId)); @@ -498,7 +497,7 @@ void ReanimatedModuleProxy::applyCSSAnimations( rt, shadowNode, updates.animationNames, - std::move(newAnimations), + newAnimations, updates.settingsUpdates, timestamp); } @@ -595,7 +594,7 @@ bool ReanimatedModuleProxy::handleRawEvent( const auto &eventPayload = rawEvent.eventPayload; jsi::Value payload = eventPayload->asJSIValue(rt); - auto res = handleEvent(eventType, tag, std::move(payload), currentTime); + auto res = handleEvent(eventType, tag, payload, currentTime); // TODO: we should call performOperations conditionally if event is handled // (res == true), but for now handleEvent always returns false. Thankfully, // performOperations does not trigger a lot of code if there is nothing to @@ -1221,7 +1220,7 @@ void ReanimatedModuleProxy::commitUpdates( SurfaceId surfaceId = shadowNode->getSurfaceId(); auto family = &shadowNode->getFamily(); react_native_assert(family->getSurfaceId() == surfaceId); - propsMapBySurface[surfaceId][family].emplace_back(std::move(props)); + propsMapBySurface[surfaceId][family].emplace_back(props); } } 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 8ffb2d71bde9..c6475bbb2d4f 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp @@ -1,34 +1,39 @@ #include #include +#include + namespace reanimated { using namespace worklets; void UIRuntimeDecorator::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) { - jsi_utils::installJsiFunction(uiRuntime, "_updateProps", updateProps); - jsi_utils::installJsiFunction(uiRuntime, "_dispatchCommand", dispatchCommand); - jsi_utils::installJsiFunction(uiRuntime, "_measure", measure); + 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", getAnimationTimestamp); + uiRuntime, "_getAnimationTimestamp", std::move(getAnimationTimestamp)); jsi_utils::installJsiFunction( - uiRuntime, "_notifyAboutProgress", progressLayoutAnimation); + uiRuntime, "_notifyAboutProgress", std::move(progressLayoutAnimation)); jsi_utils::installJsiFunction( - uiRuntime, "_notifyAboutEnd", endLayoutAnimation); + uiRuntime, "_notifyAboutEnd", std::move(endLayoutAnimation)); - jsi_utils::installJsiFunction(uiRuntime, "_setGestureState", setGestureState); + jsi_utils::installJsiFunction( + uiRuntime, "_setGestureState", std::move(setGestureState)); const auto microtaskQueueFinalizers = uiRuntime.global() @@ -44,9 +49,11 @@ void UIRuntimeDecorator::decorate( uiRuntime, jsi::PropNameID::forAscii(uiRuntime, "_maybeFlushUIUpdatesQueue"), 0, - jsi_utils::createHostFunction(maybeFlushUIUpdatesQueue))); + jsi_utils::createHostFunction( + std::move(maybeFlushUIUpdatesQueue)))); - jsi_utils::installJsiFunction(uiRuntime, "_obtainProp", obtainPropFunction); + jsi_utils::installJsiFunction( + uiRuntime, "_obtainProp", std::move(obtainPropFunction)); } } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h b/packages/react-native-reanimated/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h index 9bb8f02b7782..7fa3b69b5d0c 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h @@ -13,7 +13,6 @@ using namespace facebook; using namespace react; namespace reanimated { - using UpdatePropsFunction = std::function; using ObtainPropFunction = std::function - explicit ReanimatedSystraceSection( - const char *name, - ConvertsToStringPiece &&...args) { + explicit ReanimatedSystraceSection(const char *name, ConvertsToStringPiece &&...args) + { ATrace_beginSection(name); } - ~ReanimatedSystraceSection() { + ~ReanimatedSystraceSection() + { ATrace_endSection(); } }; @@ -42,12 +42,12 @@ struct ReanimatedSystraceSection { // The apple part is copied from React Native // from // https://github.com/facebook/react-native/blob/5697d923a05119314b4cfcd556cb243986637764/packages/react-native/ReactCommon/cxxreact/SystraceSection.h -#elif defined(__APPLE__) && OS_LOG_TARGET_HAS_10_15_FEATURES && \ - defined(REANIMATED_PROFILING) +#elif defined(__APPLE__) && OS_LOG_TARGET_HAS_10_15_FEATURES && defined(REANIMATED_PROFILING) template struct renderer { - static std::string render(const T &t) { + static std::string render(const T &t) + { std::ostringstream oss; oss << t; return oss.str(); @@ -55,17 +55,17 @@ struct renderer { }; template -static auto render(const T &t) - -> decltype(renderer::render(std::declval())) { +static auto render(const T &t) -> decltype(renderer::render(std::declval())) +{ return renderer::render(t); } inline os_log_t instrumentsLogHandle = nullptr; -static inline os_log_t getOrCreateInstrumentsLogHandle() { +static inline os_log_t getOrCreateInstrumentsLogHandle() +{ if (!instrumentsLogHandle) { - instrumentsLogHandle = os_log_create( - "dev.reanimated.instruments", OS_LOG_CATEGORY_POINTS_OF_INTEREST); + instrumentsLogHandle = os_log_create("dev.reanimated.instruments", OS_LOG_CATEGORY_POINTS_OF_INTEREST); } return instrumentsLogHandle; } @@ -73,11 +73,9 @@ static inline os_log_t getOrCreateInstrumentsLogHandle() { struct ReanimatedSystraceSection { public: template - explicit ReanimatedSystraceSection( - const char *name, - ConvertsToStringPiece &&...args) { - os_log_t instrumentsLogHandle = - reanimated::getOrCreateInstrumentsLogHandle(); + explicit ReanimatedSystraceSection(const char *name, ConvertsToStringPiece &&...args) + { + os_log_t instrumentsLogHandle = reanimated::getOrCreateInstrumentsLogHandle(); // If the log isn't enabled, we don't want the performance overhead of the // rest of the code below. @@ -87,8 +85,7 @@ struct ReanimatedSystraceSection { name_ = name; - const auto argsVector = - std::vector{reanimated::render(args)...}; + const auto argsVector = std::vector{reanimated::render(args)...}; std::string argsString = ""; for (size_t i = 0; i < argsVector.size(); i += 2) { argsString += argsVector[i] + "=" + argsVector[i + 1] + ";"; @@ -97,21 +94,12 @@ struct ReanimatedSystraceSection { signpostID_ = os_signpost_id_make_with_pointer(instrumentsLogHandle, this); os_signpost_interval_begin( - instrumentsLogHandle, - signpostID_, - "Reanimated", - "%s begin: %s", - name, - argsString.c_str()); + instrumentsLogHandle, signpostID_, "Reanimated", "%s begin: %s", name, argsString.c_str()); } - ~ReanimatedSystraceSection() { - os_signpost_interval_end( - reanimated::instrumentsLogHandle, - signpostID_, - "Reanimated", - "%s end", - name_.data()); + ~ReanimatedSystraceSection() + { + os_signpost_interval_end(reanimated::instrumentsLogHandle, signpostID_, "Reanimated", "%s end", name_.data()); } private: @@ -124,9 +112,9 @@ struct ReanimatedSystraceSection { struct ReanimatedSystraceSection { public: template - explicit ReanimatedSystraceSection( - const char *name, - ConvertsToStringPiece &&...args) {} + explicit ReanimatedSystraceSection(const char *name, ConvertsToStringPiece &&...args) + { + } }; #endif // defined(__APPLE__) && OS_LOG_TARGET_HAS_10_15_FEATURES &&