Skip to content
Closed
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
@@ -0,0 +1,20 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#import <RCTAnimatedModuleProvider/RCTAnimatedModuleProvider.h>

@interface RCTAnimatedModuleProvider (Private)

/**
* When true, animated frames are skipped while the application is inactive (between
* `UIApplicationWillEnterForeground` -> `UIApplicationDidBecomeActive`), default is false.
*/
- (instancetype)initWithSkipFramesDuringForegroundTransition:(BOOL)skipFramesDuringForegroundTransition;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

#import "RCTAnimatedModuleProvider.h"

#import "RCTAnimatedModuleProvider+Private.h"

#import <functional>

#if TARGET_OS_OSX
#import <React/RCTPlatformDisplayLink.h>
#else
#import <QuartzCore/CADisplayLink.h>
#import <UIKit/UIKit.h>
#endif

#import <react/featureflags/ReactNativeFeatureFlags.h>
Expand All @@ -28,6 +31,21 @@ @implementation RCTAnimatedModuleProvider {
std::function<void()> _onRender;

std::weak_ptr<facebook::react::NativeAnimatedNodesManagerProvider> _nativeAnimatedNodesManagerProvider;

BOOL _skipFramesDuringForegroundTransition;
}

- (instancetype)init
{
return [self initWithSkipFramesDuringForegroundTransition:NO];
}

- (instancetype)initWithSkipFramesDuringForegroundTransition:(BOOL)skipFramesDuringForegroundTransition
{
if (self = [super init]) {
_skipFramesDuringForegroundTransition = skipFramesDuringForegroundTransition;
}
return self;
}

- (void)dealloc
Expand Down Expand Up @@ -61,6 +79,15 @@ - (void)_onDisplayLinkTick
// use-after-free during hot reload. The provider must remain alive for the
// entire duration of _onRender() since it holds references to the animation
// nodes manager and related data structures.
#if !TARGET_OS_OSX
// See initWithSkipFramesDuringForegroundTransition: the frame is skipped,
// never the clock.
if (_skipFramesDuringForegroundTransition &&
UIApplication.sharedApplication.applicationState == UIApplicationStateInactive) {
return;
}
#endif

auto strongProvider = _nativeAnimatedNodesManagerProvider.lock();
if (strongProvider != nullptr && _displayLink != nullptr && _onRender != nullptr) {
_onRender();
Expand Down
Loading