Skip to content

Commit

Permalink
Use real propsParserContext in LayoutAnimation
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D31053819

fbshipit-source-id: 8ec21012500f3bfc7e8aea018b5ca72323da2d9e
  • Loading branch information
javache authored and facebook-github-bot committed Sep 21, 2021
1 parent f4fdf4b commit 6025611
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 27 deletions.
4 changes: 2 additions & 2 deletions React/Fabric/RCTScheduler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ - (instancetype)initWithToolbox:(SchedulerToolbox)toolbox

if (reactNativeConfig->getBool("react_fabric:enabled_layout_animations_ios")) {
_layoutAnimationDelegateProxy = std::make_shared<LayoutAnimationDelegateProxy>((__bridge void *)self);
_animationDriver =
std::make_shared<LayoutAnimationDriver>(toolbox.runtimeExecutor, _layoutAnimationDelegateProxy.get());
_animationDriver = std::make_shared<LayoutAnimationDriver>(
toolbox.runtimeExecutor, toolbox.contextContainer, _layoutAnimationDelegateProxy.get());
if (reactNativeConfig->getBool("react_fabric:enabled_skip_invalidated_key_frames_ios")) {
_animationDriver->enableSkipInvalidatedKeyFrames();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ void Binding::installFabricUIManager(
toolbox.backgroundExecutor = backgroundExecutor_->get();
}

animationDriver_ =
std::make_shared<LayoutAnimationDriver>(runtimeExecutor, this);
animationDriver_ = std::make_shared<LayoutAnimationDriver>(
runtimeExecutor, contextContainer, this);
scheduler_ = std::make_shared<Scheduler>(
toolbox, (animationDriver_ ? animationDriver_.get() : nullptr), this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ class LayoutAnimationDriver : public LayoutAnimationKeyFrameManager {
public:
LayoutAnimationDriver(
RuntimeExecutor runtimeExecutor,
ContextContainer::Shared &contextContainer,
LayoutAnimationStatusDelegate *delegate)
: LayoutAnimationKeyFrameManager(runtimeExecutor, delegate) {}
: LayoutAnimationKeyFrameManager(
runtimeExecutor,
contextContainer,
delegate) {}

protected:
virtual void animationMutationsForFrame(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ interpolateFloats(float coefficient, float oldValue, float newValue) {

LayoutAnimationKeyFrameManager::LayoutAnimationKeyFrameManager(
RuntimeExecutor runtimeExecutor,
ContextContainer::Shared &contextContainer,
LayoutAnimationStatusDelegate *delegate)
: runtimeExecutor_(runtimeExecutor),
contextContainer_(contextContainer),
layoutAnimationStatusDelegate_(delegate),
now_([]() {
return std::chrono::duration_cast<std::chrono::milliseconds>(
Expand Down Expand Up @@ -228,14 +230,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
LOG(ERROR) << "BEGINNING DONE DISPLAYING ONGOING inflightAnimations_!";
#endif

// Stub PropsParserContext used for cloneProps.
// This is/should be safe because cloning doesn't actually need to
// parse props, and just copies them; therefore there should be no
// need to actually use anything in the PropsParserContext.
// If this ever changes, the LayoutAnimations API will need to change
// to pass in a real PropsParserContext.
ContextContainer contextContainer{};
PropsParserContext propsParserContext{surfaceId, contextContainer};
PropsParserContext propsParserContext{surfaceId, *contextContainer_};

// What to do if we detect a conflict? Get current value and make
// that the baseline of the next animation. Scale the remaining time
Expand Down Expand Up @@ -1131,15 +1126,6 @@ ShadowView LayoutAnimationKeyFrameManager::createInterpolatedShadowView(
return finalView;
}

// Stub PropsParserContext used for interpolateProps.
// This is/should be safe because interpolating doesn't actually need to
// parse props, and just copies them; therefore there should be no
// need to actually use anything in the PropsParserContext.
// If this ever changes, the LayoutAnimations API will need to change
// to pass in a real PropsParserContext.
ContextContainer contextContainer{};
PropsParserContext propsParserContext{-1, contextContainer};

ComponentDescriptor const &componentDescriptor =
getComponentDescriptorForShadowView(startingView);

Expand All @@ -1160,6 +1146,8 @@ ShadowView LayoutAnimationKeyFrameManager::createInterpolatedShadowView(
}

// Animate opacity or scale/transform
PropsParserContext propsParserContext{
finalView.surfaceId, *contextContainer_};
mutatedShadowView.props = componentDescriptor.interpolateProps(
propsParserContext, progress, startingView.props, finalView.props);
react_native_assert(mutatedShadowView.props != nullptr);
Expand Down Expand Up @@ -1202,7 +1190,7 @@ void LayoutAnimationKeyFrameManager::queueFinalMutationsForCompletedKeyFrame(
AnimationKeyFrame const &keyframe,
ShadowViewMutation::List &mutationsList,
bool interrupted,
std::string logPrefix) const {
const std::string &logPrefix) const {
if (skipInvalidatedKeyFrames_ && keyframe.invalidated) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,
public:
LayoutAnimationKeyFrameManager(
RuntimeExecutor runtimeExecutor,
ContextContainer::Shared &contextContainer,
LayoutAnimationStatusDelegate *delegate);

#pragma mark - UIManagerAnimationDelegate methods
Expand Down Expand Up @@ -138,10 +139,12 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,
AnimationKeyFrame const &keyframe,
ShadowViewMutation::List &mutationsList,
bool interrupted,
std::string logPrefix) const;
const std::string &logPrefix) const;

private:
RuntimeExecutor runtimeExecutor_;
ContextContainer::Shared contextContainer_;

mutable std::mutex layoutAnimationStatusDelegateMutex_;
mutable LayoutAnimationStatusDelegate *layoutAnimationStatusDelegate_{};
mutable std::mutex surfaceIdsToStopMutex_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void testShadowNodeTreeLifeCycleLayoutAnimations(
auto entropy = seed == 0 ? Entropy() : Entropy(seed);

auto eventDispatcher = EventDispatcher::Shared{};
auto contextContainer = std::make_shared<ContextContainer>();
auto contextContainer = std::make_shared<ContextContainer const>();
auto componentDescriptorParameters =
ComponentDescriptorParameters{eventDispatcher, contextContainer, nullptr};
auto viewComponentDescriptor =
Expand All @@ -77,8 +77,8 @@ static void testShadowNodeTreeLifeCycleLayoutAnimations(
concreteComponentDescriptorProvider<ViewComponentDescriptor>());

// Create Animation Driver
auto animationDriver =
std::make_shared<LayoutAnimationDriver>(runtimeExecutor, nullptr);
auto animationDriver = std::make_shared<LayoutAnimationDriver>(
runtimeExecutor, contextContainer, nullptr);
animationDriver->setComponentDescriptorRegistry(componentDescriptorRegistry);

// Mock animation timers
Expand Down

0 comments on commit 6025611

Please sign in to comment.