File tree Expand file tree Collapse file tree
packages/react-native/ReactCxxPlatform/react/renderer/animated Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3535
3636namespace facebook ::react {
3737
38+ // Global function pointer for getting current time. Current time
39+ // can be injected for testing purposes.
40+ static TimePointFunction g_now = &std::chrono::steady_clock::now;
41+ void g_setNativeAnimatedNowTimestampFunction (TimePointFunction nowFunction) {
42+ g_now = nowFunction;
43+ }
44+
3845namespace {
3946
4047struct NodesQueueItem {
@@ -719,7 +726,7 @@ void NativeAnimatedNodesManager::onRender() {
719726 // Step through the animation loop
720727 if (isAnimationUpdateNeeded ()) {
721728 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
722- std::chrono::steady_clock::now ().time_since_epoch ())
729+ g_now ().time_since_epoch ())
723730 .count ();
724731
725732 auto containsChange =
Original file line number Diff line number Diff line change 1414#include < react/renderer/animated/EventEmitterListener.h>
1515#include < react/renderer/animated/event_drivers/EventAnimationDriver.h>
1616#include < react/renderer/core/ReactPrimitives.h>
17+ #include < chrono>
1718#include < memory>
1819#include < mutex>
1920#include < optional>
2324
2425namespace facebook ::react {
2526
27+ using TimePointFunction = std::chrono::steady_clock::time_point (*)();
28+ // A way to inject a custom time function for testing purposes.
29+ // Default is `std::chrono::steady_clock::now`.
30+ void g_setNativeAnimatedNowTimestampFunction (TimePointFunction nowFunction);
31+
2632class AnimatedNode ;
2733class AnimationDriver ;
2834class Scheduler ;
@@ -52,7 +58,7 @@ class NativeAnimatedNodesManager {
5258
5359 explicit NativeAnimatedNodesManager (
5460 DirectManipulationCallback&& directManipulationCallback,
55- FabricCommitCallback&& fabricCommitCallback = nullptr ,
61+ FabricCommitCallback&& fabricCommitCallback,
5662 StartOnRenderCallback&& startOnRenderCallback = nullptr ,
5763 StopOnRenderCallback&& stopOnRenderCallback = nullptr ) noexcept ;
5864
You can’t perform that action at this time.
0 commit comments