mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Revert uikit proxies
Summary: We will use main queue setup of native modules to solve this problem instead. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D71341038 fbshipit-source-id: 77e2064c732a5572d063a240f769fa7a79530f1b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
061174c150
commit
ed8749ce59
@@ -15,7 +15,6 @@
|
||||
#if RCT_ENABLE_INSPECTOR
|
||||
#import "RCTInspectorDevServerHelper.h"
|
||||
#endif
|
||||
#import <React/RCTInitializeUIKitProxies.h>
|
||||
#import <jsinspector-modern/InspectorFlags.h>
|
||||
#import <jsinspector-modern/InspectorInterfaces.h>
|
||||
#import <jsinspector-modern/ReactCdp.h>
|
||||
@@ -512,7 +511,6 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init)
|
||||
_bundleURL = [RCTConvert NSURL:_bundleURL.absoluteString];
|
||||
|
||||
RCTExecuteOnMainQueue(^{
|
||||
RCTInitializeUIKitProxies();
|
||||
RCTRegisterReloadCommandListener(self);
|
||||
RCTReloadCommandSetBundleURL(self->_bundleURL);
|
||||
});
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface RCTInitialAccessibilityValuesProxy : NSObject
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
|
||||
@property (readonly, nonatomic) BOOL isBoldTextEnabled;
|
||||
@property (readonly, nonatomic) BOOL isGrayscaleEnabled;
|
||||
@property (readonly, nonatomic) BOOL isInvertColorsEnabled;
|
||||
@property (readonly, nonatomic) BOOL isReduceMotionEnabled;
|
||||
@property (readonly, nonatomic) BOOL isDarkerSystemColorsEnabled;
|
||||
@property (readonly, nonatomic) BOOL prefersCrossFadeTransitions;
|
||||
@property (readonly, nonatomic) BOOL isReduceTransparencyEnabled;
|
||||
@property (readonly, nonatomic) BOOL isVoiceOverEnabled;
|
||||
@property (readonly, nonatomic) UIContentSizeCategory preferredContentSizeCategory;
|
||||
|
||||
- (void)recordAccessibilityValues;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,185 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "RCTInitialAccessibilityValuesProxy.h"
|
||||
#import <React/RCTUtils.h>
|
||||
#import <mutex>
|
||||
|
||||
@implementation RCTInitialAccessibilityValuesProxy {
|
||||
BOOL _hasRecordedInitialAccessibilityValues;
|
||||
BOOL _isBoldTextEnabled;
|
||||
BOOL _isGrayscaleEnabled;
|
||||
BOOL _isInvertColorsEnabled;
|
||||
BOOL _isReduceMotionEnabled;
|
||||
BOOL _isDarkerSystemColorsEnabled;
|
||||
BOOL _isReduceTransparencyEnabled;
|
||||
BOOL _isVoiceOverEnabled;
|
||||
UIContentSizeCategory _preferredContentSizeCategory;
|
||||
std::mutex _mutex;
|
||||
}
|
||||
|
||||
+ (instancetype)sharedInstance
|
||||
{
|
||||
static RCTInitialAccessibilityValuesProxy *sharedInstance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [RCTInitialAccessibilityValuesProxy new];
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (BOOL)isBoldTextEnabled
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_hasRecordedInitialAccessibilityValues) {
|
||||
return _isBoldTextEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
__block BOOL isBoldTextEnabled;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
isBoldTextEnabled = UIAccessibilityIsBoldTextEnabled();
|
||||
});
|
||||
|
||||
return isBoldTextEnabled;
|
||||
}
|
||||
|
||||
- (BOOL)isGrayscaleEnabled
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_hasRecordedInitialAccessibilityValues) {
|
||||
return _isGrayscaleEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
__block BOOL isGrayscaleEnabled;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
isGrayscaleEnabled = UIAccessibilityIsGrayscaleEnabled();
|
||||
});
|
||||
|
||||
return isGrayscaleEnabled;
|
||||
}
|
||||
|
||||
- (BOOL)isInvertColorsEnabled
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_hasRecordedInitialAccessibilityValues) {
|
||||
return _isInvertColorsEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
__block BOOL isInvertColorsEnabled;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
isInvertColorsEnabled = UIAccessibilityIsInvertColorsEnabled();
|
||||
});
|
||||
|
||||
return isInvertColorsEnabled;
|
||||
}
|
||||
|
||||
- (BOOL)isReduceMotionEnabled
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_hasRecordedInitialAccessibilityValues) {
|
||||
return _isReduceMotionEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
__block BOOL isReduceMotionEnabled;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
isReduceMotionEnabled = UIAccessibilityIsReduceMotionEnabled();
|
||||
});
|
||||
|
||||
return isReduceMotionEnabled;
|
||||
}
|
||||
|
||||
- (BOOL)isDarkerSystemColorsEnabled
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_hasRecordedInitialAccessibilityValues) {
|
||||
return _isDarkerSystemColorsEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
__block BOOL isDarkerSystemColorsEnabled;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
isDarkerSystemColorsEnabled = UIAccessibilityDarkerSystemColorsEnabled();
|
||||
});
|
||||
|
||||
return isDarkerSystemColorsEnabled;
|
||||
}
|
||||
|
||||
- (BOOL)isReduceTransparencyEnabled
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_hasRecordedInitialAccessibilityValues) {
|
||||
return _isReduceTransparencyEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
__block BOOL isReduceTransparencyEnabled;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
isReduceTransparencyEnabled = UIAccessibilityIsReduceTransparencyEnabled();
|
||||
});
|
||||
|
||||
return isReduceTransparencyEnabled;
|
||||
}
|
||||
|
||||
- (BOOL)isVoiceOverEnabled
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_hasRecordedInitialAccessibilityValues) {
|
||||
return _isVoiceOverEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
__block BOOL isVoiceOverEnabled;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
isVoiceOverEnabled = UIAccessibilityIsVoiceOverRunning();
|
||||
});
|
||||
|
||||
return isVoiceOverEnabled;
|
||||
}
|
||||
|
||||
- (UIContentSizeCategory)preferredContentSizeCategory
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_hasRecordedInitialAccessibilityValues) {
|
||||
return _preferredContentSizeCategory;
|
||||
}
|
||||
}
|
||||
|
||||
__block UIContentSizeCategory preferredContentSizeCategory;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
preferredContentSizeCategory = RCTSharedApplication().preferredContentSizeCategory;
|
||||
});
|
||||
|
||||
return preferredContentSizeCategory;
|
||||
}
|
||||
|
||||
- (void)recordAccessibilityValues
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
_hasRecordedInitialAccessibilityValues = YES;
|
||||
_isBoldTextEnabled = UIAccessibilityIsBoldTextEnabled();
|
||||
_isGrayscaleEnabled = UIAccessibilityIsGrayscaleEnabled();
|
||||
_isInvertColorsEnabled = UIAccessibilityIsInvertColorsEnabled();
|
||||
_isReduceMotionEnabled = UIAccessibilityIsReduceMotionEnabled();
|
||||
_isDarkerSystemColorsEnabled = UIAccessibilityDarkerSystemColorsEnabled();
|
||||
_isReduceTransparencyEnabled = UIAccessibilityIsReduceTransparencyEnabled();
|
||||
_isVoiceOverEnabled = UIAccessibilityIsVoiceOverRunning();
|
||||
_preferredContentSizeCategory = RCTSharedApplication().preferredContentSizeCategory;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,10 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
void RCTInitializeUIKitProxies(void);
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "RCTInitializeUIKitProxies.h"
|
||||
#import <React/RCTUtils.h>
|
||||
#import "RCTInitialAccessibilityValuesProxy.h"
|
||||
#import "RCTKeyWindowValuesProxy.h"
|
||||
#import "RCTTraitCollectionProxy.h"
|
||||
#import "RCTWindowSafeAreaProxy.h"
|
||||
|
||||
void RCTInitializeUIKitProxies(void)
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
[[RCTWindowSafeAreaProxy sharedInstance] startObservingSafeArea];
|
||||
[[RCTTraitCollectionProxy sharedInstance] startObservingTraitCollection];
|
||||
[[RCTInitialAccessibilityValuesProxy sharedInstance] recordAccessibilityValues];
|
||||
[[RCTKeyWindowValuesProxy sharedInstance] startObservingWindowSizeIfNecessary];
|
||||
// Early cache size of screen to avoid main thread contention
|
||||
RCTScreenSize();
|
||||
});
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface RCTKeyWindowValuesProxy : NSObject
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
|
||||
@property (assign, readonly) CGSize windowSize;
|
||||
@property (assign, readonly) UIInterfaceOrientation currentInterfaceOrientation;
|
||||
|
||||
- (void)startObservingWindowSizeIfNecessary;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "RCTKeyWindowValuesProxy.h"
|
||||
#import <React/RCTAssert.h>
|
||||
#import <React/RCTUtils.h>
|
||||
#import <mutex>
|
||||
|
||||
#import <React/RCTConstants.h>
|
||||
|
||||
static NSString *const kFrameKeyPath = @"frame";
|
||||
|
||||
@implementation RCTKeyWindowValuesProxy {
|
||||
BOOL _isObserving;
|
||||
std::mutex _mutex;
|
||||
CGSize _currentWindowSize;
|
||||
UIInterfaceOrientation _currentInterfaceOrientation;
|
||||
}
|
||||
|
||||
+ (instancetype)sharedInstance
|
||||
{
|
||||
static RCTKeyWindowValuesProxy *sharedInstance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [RCTKeyWindowValuesProxy new];
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_isObserving = NO;
|
||||
UIView *mainWindow = RCTKeyWindow();
|
||||
_currentWindowSize = mainWindow ? mainWindow.bounds.size : UIScreen.mainScreen.bounds.size;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)startObservingWindowSizeIfNecessary
|
||||
{
|
||||
// Accesing _isObserving must be done under the lock to avoid a race condition.
|
||||
// We can't hold the lock while calling RCTUnsafeExecuteOnMainQueueSync.
|
||||
// Therefore, reading/writing _isObserving is kept separate from calling RCTUnsafeExecuteOnMainQueueSync.
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_isObserving) {
|
||||
return;
|
||||
}
|
||||
_isObserving = YES;
|
||||
}
|
||||
|
||||
// For backwards compatibility, we register for notifications from the main thread only.
|
||||
// On the new architecture, we are already on the main thread and RCTUnsafeExecuteOnMainQueueSync will simply call
|
||||
// the block.
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
[RCTKeyWindow() addObserver:self forKeyPath:kFrameKeyPath options:NSKeyValueObservingOptionNew context:nil];
|
||||
});
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_interfaceOrientationDidChange)
|
||||
name:UIApplicationDidBecomeActiveNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath
|
||||
ofObject:(id)object
|
||||
change:(NSDictionary *)change
|
||||
context:(void *)context
|
||||
{
|
||||
if ([keyPath isEqualToString:kFrameKeyPath]) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTWindowFrameDidChangeNotification object:self];
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
_currentWindowSize = RCTKeyWindow().bounds.size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (CGSize)windowSize
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_isObserving) {
|
||||
return _currentWindowSize;
|
||||
}
|
||||
}
|
||||
|
||||
__block CGSize size;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
size = RCTKeyWindow().bounds.size;
|
||||
});
|
||||
return size;
|
||||
}
|
||||
|
||||
- (UIInterfaceOrientation)currentInterfaceOrientation
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_isObserving) {
|
||||
return _currentInterfaceOrientation;
|
||||
}
|
||||
}
|
||||
|
||||
__block UIInterfaceOrientation interfaceOrientation;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
interfaceOrientation = RCTKeyWindow().windowScene.interfaceOrientation;
|
||||
});
|
||||
return interfaceOrientation;
|
||||
}
|
||||
|
||||
- (void)_interfaceOrientationDidChange
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
_currentInterfaceOrientation = RCTKeyWindow().windowScene.interfaceOrientation;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface RCTTraitCollectionProxy : NSObject
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
|
||||
/*
|
||||
* Property to access the current trait collection.
|
||||
* Thread safe.
|
||||
*/
|
||||
@property (nonatomic, readonly) UITraitCollection *currentTraitCollection;
|
||||
|
||||
- (void)startObservingTraitCollection;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "RCTTraitCollectionProxy.h"
|
||||
#import <React/RCTUtils.h>
|
||||
#import <mutex>
|
||||
|
||||
#import <React/RCTConstants.h>
|
||||
|
||||
@implementation RCTTraitCollectionProxy {
|
||||
BOOL _isObserving;
|
||||
std::mutex _mutex;
|
||||
UITraitCollection *_currentTraitCollection;
|
||||
}
|
||||
|
||||
+ (instancetype)sharedInstance
|
||||
{
|
||||
static RCTTraitCollectionProxy *sharedInstance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [RCTTraitCollectionProxy new];
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_isObserving = NO;
|
||||
_currentTraitCollection = [RCTKeyWindow().traitCollection copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)startObservingTraitCollection
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (!_isObserving) {
|
||||
_isObserving = YES;
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_appearanceDidChange:)
|
||||
name:RCTUserInterfaceStyleDidChangeNotification
|
||||
object:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (UITraitCollection *)currentTraitCollection
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_isObserving) {
|
||||
return _currentTraitCollection;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback in case [RCTTraitCollectionProxy startObservingTraitCollection] was not called.
|
||||
__block UITraitCollection *traitCollection = nil;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
traitCollection = [RCTKeyWindow().traitCollection copy];
|
||||
});
|
||||
return traitCollection;
|
||||
}
|
||||
|
||||
- (void)_appearanceDidChange:(NSNotification *)notification
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
|
||||
NSDictionary *userInfo = [notification userInfo];
|
||||
if (userInfo) {
|
||||
_currentTraitCollection = userInfo[RCTUserInterfaceStyleDidChangeNotificationTraitCollectionKey];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface RCTWindowSafeAreaProxy : NSObject
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
|
||||
/*
|
||||
* Property to access the current safe area insets of the window, read-only.
|
||||
* Thread safe.
|
||||
*/
|
||||
@property (nonatomic, readonly) UIEdgeInsets currentSafeAreaInsets;
|
||||
|
||||
- (void)startObservingSafeArea;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "RCTWindowSafeAreaProxy.h"
|
||||
#import <React/RCTAssert.h>
|
||||
#import <React/RCTUtils.h>
|
||||
#import <mutex>
|
||||
|
||||
#import <React/RCTConstants.h>
|
||||
|
||||
@implementation RCTWindowSafeAreaProxy {
|
||||
BOOL _isObserving;
|
||||
std::mutex _mutex;
|
||||
UIEdgeInsets _currentSafeAreaInsets;
|
||||
}
|
||||
|
||||
+ (instancetype)sharedInstance
|
||||
{
|
||||
static RCTWindowSafeAreaProxy *sharedInstance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [RCTWindowSafeAreaProxy new];
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (void)startObservingSafeArea
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (!_isObserving) {
|
||||
_isObserving = YES;
|
||||
_currentSafeAreaInsets = RCTKeyWindow().safeAreaInsets;
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_interfaceFrameDidChange)
|
||||
name:RCTUserInterfaceStyleDidChangeNotification
|
||||
object:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (UIEdgeInsets)currentSafeAreaInsets
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (_isObserving) {
|
||||
return _currentSafeAreaInsets;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback in case [startObservingSafeArea startObservingSafeArea] was not called.
|
||||
__block UIEdgeInsets insets;
|
||||
#if !TARGET_OS_MACCATALYST
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
insets = [UIApplication sharedApplication].delegate.window.safeAreaInsets;
|
||||
});
|
||||
#endif
|
||||
return insets;
|
||||
}
|
||||
|
||||
- (void)_interfaceFrameDidChange
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
_currentSafeAreaInsets = RCTKeyWindow().safeAreaInsets;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -12,7 +12,6 @@
|
||||
#import <React/RCTBridge.h>
|
||||
#import <React/RCTConvert.h>
|
||||
#import <React/RCTEventDispatcherProtocol.h>
|
||||
#import <React/RCTInitialAccessibilityValuesProxy.h>
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTUIManager.h>
|
||||
|
||||
@@ -38,7 +37,7 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
+ (BOOL)requiresMainQueueSetup
|
||||
{
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
@@ -92,15 +91,14 @@ RCT_EXPORT_MODULE()
|
||||
name:UIAccessibilityVoiceOverStatusDidChangeNotification
|
||||
object:nil];
|
||||
|
||||
RCTInitialAccessibilityValuesProxy *initialValuesProxy = [RCTInitialAccessibilityValuesProxy sharedInstance];
|
||||
self.contentSizeCategory = initialValuesProxy.preferredContentSizeCategory;
|
||||
_isBoldTextEnabled = initialValuesProxy.isBoldTextEnabled;
|
||||
_isGrayscaleEnabled = initialValuesProxy.isGrayscaleEnabled;
|
||||
_isInvertColorsEnabled = initialValuesProxy.isInvertColorsEnabled;
|
||||
_isReduceMotionEnabled = initialValuesProxy.isReduceMotionEnabled;
|
||||
_isDarkerSystemColorsEnabled = initialValuesProxy.isDarkerSystemColorsEnabled;
|
||||
_isReduceTransparencyEnabled = initialValuesProxy.isReduceTransparencyEnabled;
|
||||
_isVoiceOverEnabled = initialValuesProxy.isVoiceOverEnabled;
|
||||
self.contentSizeCategory = RCTSharedApplication().preferredContentSizeCategory;
|
||||
_isBoldTextEnabled = UIAccessibilityIsBoldTextEnabled();
|
||||
_isGrayscaleEnabled = UIAccessibilityIsGrayscaleEnabled();
|
||||
_isInvertColorsEnabled = UIAccessibilityIsInvertColorsEnabled();
|
||||
_isReduceMotionEnabled = UIAccessibilityIsReduceMotionEnabled();
|
||||
_isDarkerSystemColorsEnabled = UIAccessibilityDarkerSystemColorsEnabled();
|
||||
_isReduceTransparencyEnabled = UIAccessibilityIsReduceTransparencyEnabled();
|
||||
_isVoiceOverEnabled = UIAccessibilityIsVoiceOverRunning();
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
||||
#import <React/RCTConstants.h>
|
||||
#import <React/RCTEventEmitter.h>
|
||||
#import <React/RCTTraitCollectionProxy.h>
|
||||
|
||||
#import "CoreModulesPlugins.h"
|
||||
|
||||
@@ -90,7 +89,7 @@ NSString *RCTColorSchemePreference(UITraitCollection *traitCollection)
|
||||
- (instancetype)init
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
UITraitCollection *traitCollection = [RCTTraitCollectionProxy sharedInstance].currentTraitCollection;
|
||||
UITraitCollection *traitCollection = RCTKeyWindow().traitCollection;
|
||||
_currentColorScheme = RCTColorSchemePreference(traitCollection);
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(appearanceChanged:)
|
||||
@@ -104,7 +103,7 @@ RCT_EXPORT_MODULE(Appearance)
|
||||
|
||||
+ (BOOL)requiresMainQueueSetup
|
||||
{
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (dispatch_queue_t)methodQueue
|
||||
@@ -133,7 +132,10 @@ RCT_EXPORT_METHOD(setColorScheme : (NSString *)style)
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, getColorScheme)
|
||||
{
|
||||
if (!sIsAppearancePreferenceSet) {
|
||||
UITraitCollection *traitCollection = [RCTTraitCollectionProxy sharedInstance].currentTraitCollection;
|
||||
__block UITraitCollection *traitCollection = nil;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
traitCollection = RCTKeyWindow().traitCollection;
|
||||
});
|
||||
_currentColorScheme = RCTColorSchemePreference(traitCollection);
|
||||
}
|
||||
return _currentColorScheme;
|
||||
|
||||
@@ -14,9 +14,7 @@
|
||||
#import <React/RCTEventDispatcherProtocol.h>
|
||||
#import <React/RCTInitializing.h>
|
||||
#import <React/RCTInvalidating.h>
|
||||
#import <React/RCTKeyWindowValuesProxy.h>
|
||||
#import <React/RCTUtils.h>
|
||||
#import <React/RCTWindowSafeAreaProxy.h>
|
||||
#import <atomic>
|
||||
|
||||
#import "CoreModulesPlugins.h"
|
||||
@@ -33,6 +31,8 @@ using namespace facebook::react;
|
||||
std::atomic<BOOL> _invalidated;
|
||||
}
|
||||
|
||||
static NSString *const kFrameKeyPath = @"frame";
|
||||
|
||||
@synthesize moduleRegistry = _moduleRegistry;
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
@@ -40,14 +40,25 @@ RCT_EXPORT_MODULE()
|
||||
- (instancetype)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
[[RCTKeyWindowValuesProxy sharedInstance] startObservingWindowSizeIfNecessary];
|
||||
[RCTKeyWindow() addObserver:self forKeyPath:kFrameKeyPath options:NSKeyValueObservingOptionNew context:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath
|
||||
ofObject:(id)object
|
||||
change:(NSDictionary *)change
|
||||
context:(void *)context
|
||||
{
|
||||
if ([keyPath isEqualToString:kFrameKeyPath]) {
|
||||
[self interfaceFrameDidChange];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTWindowFrameDidChangeNotification object:self];
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)requiresMainQueueSetup
|
||||
{
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (dispatch_queue_t)methodQueue
|
||||
@@ -81,7 +92,7 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
|
||||
_currentInterfaceOrientation = [RCTKeyWindowValuesProxy sharedInstance].currentInterfaceOrientation;
|
||||
_currentInterfaceOrientation = RCTKeyWindow().windowScene.interfaceOrientation;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(interfaceFrameDidChange)
|
||||
@@ -120,6 +131,8 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTBridgeWillInvalidateModulesNotification object:nil];
|
||||
|
||||
[RCTKeyWindow() removeObserver:self forKeyPath:kFrameKeyPath];
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
|
||||
#endif
|
||||
@@ -132,8 +145,13 @@ static BOOL RCTIsIPhoneNotched()
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
dispatch_once(&onceToken, ^{
|
||||
RCTAssertMainQueue();
|
||||
|
||||
// 20pt is the top safeArea value in non-notched devices
|
||||
isIPhoneNotched = [RCTWindowSafeAreaProxy sharedInstance].currentSafeAreaInsets.top > 20;
|
||||
UIWindow *keyWindow = RCTKeyWindow();
|
||||
if (keyWindow) {
|
||||
isIPhoneNotched = keyWindow.safeAreaInsets.top > 20;
|
||||
}
|
||||
});
|
||||
#endif
|
||||
|
||||
@@ -142,11 +160,13 @@ static BOOL RCTIsIPhoneNotched()
|
||||
|
||||
static NSDictionary *RCTExportedDimensions(CGFloat fontScale)
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
UIScreen *mainScreen = UIScreen.mainScreen;
|
||||
CGSize screenSize = mainScreen.bounds.size;
|
||||
UIView *mainWindow = RCTKeyWindow();
|
||||
|
||||
// We fallback to screen size if a key window is not found.
|
||||
CGSize windowSize = [RCTKeyWindowValuesProxy sharedInstance].windowSize;
|
||||
CGSize windowSize = mainWindow ? mainWindow.bounds.size : screenSize;
|
||||
|
||||
NSDictionary<NSString *, NSNumber *> *dimsWindow = @{
|
||||
@"width" : @(windowSize.width),
|
||||
@@ -182,14 +202,20 @@ static NSDictionary *RCTExportedDimensions(CGFloat fontScale)
|
||||
|
||||
- (NSDictionary<NSString *, id> *)getConstants
|
||||
{
|
||||
return @{
|
||||
@"Dimensions" : [self _exportedDimensions],
|
||||
// Note:
|
||||
// This prop is deprecated and will be removed in a future release.
|
||||
// Please use this only for a quick and temporary solution.
|
||||
// Use <SafeAreaView> instead.
|
||||
@"isIPhoneX_deprecated" : @(RCTIsIPhoneNotched()),
|
||||
};
|
||||
__block NSDictionary<NSString *, id> *constants;
|
||||
__weak __typeof(self) weakSelf = self;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
constants = @{
|
||||
@"Dimensions" : [weakSelf _exportedDimensions],
|
||||
// Note:
|
||||
// This prop is deprecated and will be removed in a future release.
|
||||
// Please use this only for a quick and temporary solution.
|
||||
// Use <SafeAreaView> instead.
|
||||
@"isIPhoneX_deprecated" : @(RCTIsIPhoneNotched()),
|
||||
};
|
||||
});
|
||||
|
||||
return constants;
|
||||
}
|
||||
|
||||
- (void)didReceiveNewContentSizeMultiplier
|
||||
@@ -209,10 +235,11 @@ static NSDictionary *RCTExportedDimensions(CGFloat fontScale)
|
||||
- (void)interfaceOrientationDidChange
|
||||
{
|
||||
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
|
||||
UIWindow *keyWindow = RCTKeyWindow();
|
||||
UIInterfaceOrientation nextOrientation = keyWindow.windowScene.interfaceOrientation;
|
||||
UIApplication *application = RCTSharedApplication();
|
||||
UIInterfaceOrientation nextOrientation = RCTKeyWindow().windowScene.interfaceOrientation;
|
||||
|
||||
BOOL isRunningInFullScreen = CGRectEqualToRect(keyWindow.frame, keyWindow.screen.bounds);
|
||||
BOOL isRunningInFullScreen =
|
||||
CGRectEqualToRect(application.delegate.window.frame, application.delegate.window.screen.bounds);
|
||||
// We are catching here two situations for multitasking view:
|
||||
// a) The app is in Split View and the container gets resized -> !isRunningInFullScreen
|
||||
// b) The app changes to/from fullscreen example: App runs in slide over mode and goes into fullscreen->
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
||||
#import <React/RCTTraitCollectionProxy.h>
|
||||
#import <React/RCTUtils.h>
|
||||
#import <React/RCTVersion.h>
|
||||
|
||||
@@ -49,7 +48,7 @@ RCT_EXPORT_MODULE(PlatformConstants)
|
||||
|
||||
+ (BOOL)requiresMainQueueSetup
|
||||
{
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (dispatch_queue_t)methodQueue
|
||||
@@ -65,27 +64,30 @@ RCT_EXPORT_MODULE(PlatformConstants)
|
||||
|
||||
- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)getConstants
|
||||
{
|
||||
UIDevice *device = [UIDevice currentDevice];
|
||||
bool isForceTouchAvailable = [RCTTraitCollectionProxy sharedInstance].currentTraitCollection.forceTouchCapability ==
|
||||
UIForceTouchCapabilityAvailable;
|
||||
auto versions = RCTGetReactNativeVersion();
|
||||
return typedConstants<JS::NativePlatformConstantsIOS::Constants>({
|
||||
.forceTouchAvailable = isForceTouchAvailable,
|
||||
.osVersion = [device systemVersion],
|
||||
.systemName = [device systemName],
|
||||
.interfaceIdiom = interfaceIdiom([device userInterfaceIdiom]),
|
||||
.isTesting = RCTRunningInTestEnvironment() ? true : false,
|
||||
.reactNativeVersion = JS::NativePlatformConstantsIOS::ConstantsReactNativeVersion::Builder(
|
||||
{.minor = [versions[@"minor"] doubleValue],
|
||||
.major = [versions[@"major"] doubleValue],
|
||||
.patch = [versions[@"patch"] doubleValue],
|
||||
.prerelease = [versions[@"prerelease"] isKindOfClass:[NSNull class]] ? nullptr : versions[@"prerelease"]}),
|
||||
__block ModuleConstants<JS::NativePlatformConstantsIOS::Constants> constants;
|
||||
RCTUnsafeExecuteOnMainQueueSync(^{
|
||||
UIDevice *device = [UIDevice currentDevice];
|
||||
auto versions = RCTGetReactNativeVersion();
|
||||
constants = typedConstants<JS::NativePlatformConstantsIOS::Constants>({
|
||||
.forceTouchAvailable = RCTForceTouchAvailable() ? true : false,
|
||||
.osVersion = [device systemVersion],
|
||||
.systemName = [device systemName],
|
||||
.interfaceIdiom = interfaceIdiom([device userInterfaceIdiom]),
|
||||
.isTesting = RCTRunningInTestEnvironment() ? true : false,
|
||||
.reactNativeVersion = JS::NativePlatformConstantsIOS::ConstantsReactNativeVersion::Builder(
|
||||
{.minor = [versions[@"minor"] doubleValue],
|
||||
.major = [versions[@"major"] doubleValue],
|
||||
.patch = [versions[@"patch"] doubleValue],
|
||||
.prerelease = [versions[@"prerelease"] isKindOfClass:[NSNull class]] ? nullptr : versions[@"prerelease"]}),
|
||||
#if TARGET_OS_MACCATALYST
|
||||
.isMacCatalyst = true,
|
||||
.isMacCatalyst = true,
|
||||
#else
|
||||
.isMacCatalyst = false,
|
||||
.isMacCatalyst = false,
|
||||
#endif
|
||||
});
|
||||
});
|
||||
|
||||
return constants;
|
||||
}
|
||||
|
||||
- (std::shared_ptr<TurboModule>)getTurboModule:(const ObjCTurboModule::InitParams &)params
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTConvert.h>
|
||||
#import <React/RCTFabricSurface.h>
|
||||
#import <React/RCTInitializeUIKitProxies.h>
|
||||
#import <React/RCTInspectorDevServerHelper.h>
|
||||
#import <React/RCTInspectorNetworkHelper.h>
|
||||
#import <React/RCTInspectorUtils.h>
|
||||
@@ -194,7 +193,6 @@ class RCTHostHostTargetDelegate : public facebook::react::jsinspector_modern::Ho
|
||||
RCTExecuteOnMainQueue(^{
|
||||
// Listen to reload commands
|
||||
RCTRegisterReloadCommandListener(self);
|
||||
RCTInitializeUIKitProxies();
|
||||
});
|
||||
|
||||
_inspectorHostDelegate = std::make_unique<RCTHostHostTargetDelegate>(self);
|
||||
|
||||
Reference in New Issue
Block a user