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 @@ -49,15 +49,33 @@ void FrameAnimationDriver::onConfigChanged() {
frames_.push_back(frameValue);
}
toValue_ = config_["toValue"].asDouble();
deferredStart_ = true;
}

bool FrameAnimationDriver::update(double timeDeltaMs, bool /*restarting*/) {
bool FrameAnimationDriver::update(double timeDeltaMs, bool restarting) {
if (auto node =
manager_->getAnimatedNode<ValueAnimatedNode>(animatedValueTag_)) {
if (!startValue_) {
startValue_ = node->getRawValue();
}

if (deferredStart_ && restarting) {
// On the very first update after start: output the starting value
// (frame 0) and defer the time anchor. The base class will re-anchor
// startFrameTimeMs_ on the next call, so elapsed time is measured
// from the first frame that has actually been rendered — not from
// when startAnimatingNode was dispatched.
//
// This prevents skipping initial frames when the UI thread is busy
// with layout/mount work between animation start and first composite.
node->setRawValue(
startValue_.value() + frames_[0] * (toValue_ - startValue_.value()));
markNodeUpdated(node->tag());
startFrameTimeMs_ = -1;
deferredStart_ = false;
return false;
}

const auto startIndex =
static_cast<size_t>(std::round(timeDeltaMs / SingleFrameIntervalMs));
assert(startIndex >= 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class FrameAnimationDriver : public AnimationDriver {
std::vector<double> frames_{};
double toValue_{0};
std::optional<double> startValue_{};
bool deferredStart_{true};
};

} // namespace facebook::react
Loading