Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ AnimationMutations NativeAnimatedNodesManager::pullAnimationMutations(
mutations =
onAnimationFrameForBackend(propsBuilder, timestamp, stepAnimations);

if (mutations.batch.empty()) {
if (mutations.batch.empty() && isEventAnimationInProgress_) {
// The last animation tick didn't result in any changes to the UI.
// It is safe to assume any event animation that was in progress has
// completed.
Expand Down Expand Up @@ -1220,7 +1220,7 @@ void NativeAnimatedNodesManager::onRender() {
auto timestamp = static_cast<double>(microseconds) / 1000.0;
auto containsChange = onAnimationFrame(timestamp);

if (!containsChange) {
if (!containsChange && isEventAnimationInProgress_) {
// The last animation tick didn't result in any changes to the UI.
// It is safe to assume any event animation that was in progress has
// completed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,58 @@ TEST_F(EventAnimationDriverTests, sharedBackendEventDoesNotEndDecayAnimation) {
EXPECT_GT(animatedValue(), valueAfterEvent);
}

TEST_F(
EventAnimationDriverTests,
animationThatChangesNoViewDoesNotRecommitEventDrivenProps) {
initNodesManager();
nodesManager_->onRender();

const folly::dynamic valueNodeConfig =
folly::dynamic::object("type", "value")("value", 0)("offset", 0);
nodesManager_->createAnimatedNode(scrollValueTag_, valueNodeConfig);
nodesManager_->addAnimatedEventToView(
viewTag_,
"scroll",
folly::dynamic::object("animatedValueTag", scrollValueTag_)(
"nativeEventPath", folly::dynamic::array("contentOffset", "y")));
const auto styleNodeTag = ++tag_;
nodesManager_->createAnimatedNode(
styleNodeTag,
folly::dynamic::object("type", "style")(
"style", folly::dynamic::object("opacity", scrollValueTag_)));
nodesManager_->connectAnimatedNodes(scrollValueTag_, styleNodeTag);
const auto propsNodeTag = ++tag_;
nodesManager_->createAnimatedNode(
propsNodeTag,
folly::dynamic::object("type", "props")(
"props", folly::dynamic::object("style", styleNodeTag)));
nodesManager_->connectAnimatedNodes(styleNodeTag, propsNodeTag);
nodesManager_->connectAnimatedNodeToView(propsNodeTag, viewTag_);

// A running animation on a value that is connected to no view.
nodesManager_->createAnimatedNode(animatedValueTag_, valueNodeConfig);
nodesManager_->startAnimatingNode(
1,
animatedValueTag_,
folly::dynamic::object("type", "frames")(
"frames", folly::dynamic::array(0.0, 0.25, 0.5, 0.75, 1.0))(
"toValue", 100)("iterations", -1),
std::nullopt);

nodesManager_->onRender();
lastCommittedProps = folly::dynamic::object();
nodesManager_->onRender();
nodesManager_->onRender();
EXPECT_TRUE(lastCommittedProps.empty());

// The event-driven props are still committed once after a scroll ends.
dispatchScrollAt(kStartTime, 1);
lastCommittedProps = folly::dynamic::object();
nodesManager_->onRender();
EXPECT_EQ(lastCommittedProps["opacity"], 1);
lastCommittedProps = folly::dynamic::object();
nodesManager_->onRender();
EXPECT_TRUE(lastCommittedProps.empty());
}

} // namespace facebook::react
Loading