diff --git a/packages/react-native/React/CoreModules/RCTTiming.mm b/packages/react-native/React/CoreModules/RCTTiming.mm index 5158741724194b..0b3630741c807b 100644 --- a/packages/react-native/React/CoreModules/RCTTiming.mm +++ b/packages/react-native/React/CoreModules/RCTTiming.mm @@ -129,7 +129,9 @@ - (void)setup _timers = [NSMutableDictionary new]; _inBackground = NO; RCTExecuteOnMainQueue(^{ - if (!self->_inBackground && [RCTSharedApplication() applicationState] == UIApplicationStateBackground) { + if (!self->_inBackground && + ([RCTSharedApplication() applicationState] == UIApplicationStateBackground || + [UIDevice currentDevice].proximityState)) { [self appDidMoveToBackground]; } }); @@ -151,6 +153,11 @@ - (void)setup name:name object:nil]; } + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(proximityChanged) + name:UIDeviceProximityStateDidChangeNotification + object:nil]; } - (void)dealloc @@ -187,6 +194,16 @@ - (void)appDidMoveToForeground [self startTimers]; } +- (void)proximityChanged +{ + BOOL isClose = [UIDevice currentDevice].proximityState; + if (isClose) { + [self appDidMoveToBackground]; + } else { + [self appDidMoveToForeground]; + } +} + - (void)stopTimers { if (_inBackground) {