This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 additions and 0 deletions

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <React/RCTBridge.h>
#import <React/RCTJSInvokerModule.h>
/**
* RCTEventEmitter is an abstract base class to be used for modules that emit
* events to be observed by JS.
*/
@interface RCTEventEmitter : NSObject <RCTBridgeModule, RCTJSInvokerModule>
@property (nonatomic, weak) RCTBridge *bridge;
@property (nonatomic, copy, nonnull) void (^invokeJS)(NSString *module, NSString *method, NSArray *args);
/**
* Override this method to return an array of supported event names. Attempting
* to observe or send an event that isn't included in this list will result in
* an error.
*/
- (NSArray<NSString *> *)supportedEvents;
/**
* Send an event that does not relate to a specific view, e.g. a navigation
* or data update notification.
*/
- (void)sendEventWithName:(NSString *)name body:(id)body;
/**
* These methods will be called when the first observer is added and when the
* last observer is removed (or when dealloc is called), respectively. These
* should be overridden in your subclass in order to start/stop sending events.
*/
- (void)startObserving;
- (void)stopObserving;
- (void)addListener:(NSString *)eventName;
- (void)removeListeners:(double)count;
@end

View File

@ -0,0 +1,115 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTEventEmitter.h"
#import "RCTAssert.h"
#import "RCTLog.h"
#import "RCTUtils.h"
@implementation RCTEventEmitter {
NSInteger _listenerCount;
}
@synthesize invokeJS = _invokeJS;
+ (NSString *)moduleName
{
return @"";
}
+ (void)initialize
{
[super initialize];
if (self != [RCTEventEmitter class]) {
RCTAssert(
RCTClassOverridesInstanceMethod(self, @selector(supportedEvents)),
@"You must override the `supportedEvents` method of %@",
self);
}
}
- (NSArray<NSString *> *)supportedEvents
{
return nil;
}
- (void)sendEventWithName:(NSString *)eventName body:(id)body
{
RCTAssert(
_bridge != nil || _invokeJS != nil,
@"Error when sending event: %@ with body: %@. "
"Bridge is not set. This is probably because you've "
"explicitly synthesized the bridge in %@, even though it's inherited "
"from RCTEventEmitter.",
eventName,
body,
[self class]);
if (RCT_DEBUG && ![[self supportedEvents] containsObject:eventName]) {
RCTLogError(
@"`%@` is not a supported event type for %@. Supported events are: `%@`",
eventName,
[self class],
[[self supportedEvents] componentsJoinedByString:@"`, `"]);
}
if (_listenerCount > 0 && _bridge) {
[_bridge enqueueJSCall:@"RCTDeviceEventEmitter"
method:@"emit"
args:body ? @[ eventName, body ] : @[ eventName ]
completion:NULL];
} else if (_listenerCount > 0 && _invokeJS) {
_invokeJS(@"RCTDeviceEventEmitter", @"emit", body ? @[ eventName, body ] : @[ eventName ]);
} else {
RCTLogWarn(@"Sending `%@` with no listeners registered.", eventName);
}
}
- (void)startObserving
{
// Does nothing
}
- (void)stopObserving
{
// Does nothing
}
- (void)dealloc
{
if (_listenerCount > 0) {
[self stopObserving];
}
}
RCT_EXPORT_METHOD(addListener : (NSString *)eventName)
{
if (RCT_DEBUG && ![[self supportedEvents] containsObject:eventName]) {
RCTLogError(
@"`%@` is not a supported event type for %@. Supported events are: `%@`",
eventName,
[self class],
[[self supportedEvents] componentsJoinedByString:@"`, `"]);
}
_listenerCount++;
if (_listenerCount == 1) {
[self startObserving];
}
}
RCT_EXPORT_METHOD(removeListeners : (double)count)
{
int currentCount = (int)count;
if (RCT_DEBUG && currentCount > _listenerCount) {
RCTLogError(@"Attempted to remove more %@ listeners than added", [self class]);
}
_listenerCount = MAX(_listenerCount - currentCount, 0);
if (_listenerCount == 0) {
[self stopObserving];
}
}
@end

28
node_modules/react-native/React/Modules/RCTI18nUtil.h generated vendored Normal file
View File

@ -0,0 +1,28 @@
/*
* Copyright (c) Facebook, Inc. and its 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>
/**
* @experimental
* This is a experimental module for to expose constance IsRTL to js about the RTL status.
* And it allows js to force RLT status for development propose.
* This will also provide other i18n related utilities in the future.
*/
@interface RCTI18nUtil : NSObject
+ (instancetype)sharedInstance;
- (BOOL)isRTL;
- (BOOL)isRTLAllowed;
- (void)allowRTL:(BOOL)value;
- (BOOL)isRTLForced;
- (void)forceRTL:(BOOL)value;
- (BOOL)doLeftAndRightSwapInRTL;
- (void)swapLeftAndRightInRTL:(BOOL)value;
@end

105
node_modules/react-native/React/Modules/RCTI18nUtil.m generated vendored Normal file
View File

@ -0,0 +1,105 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTI18nUtil.h"
#import <UIKit/UIKit.h>
@implementation RCTI18nUtil
+ (instancetype)sharedInstance
{
static RCTI18nUtil *sharedInstance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [self new];
[sharedInstance swapLeftAndRightInRTL:true];
});
return sharedInstance;
}
/**
* Check if the app is currently running on an RTL locale.
* This only happens when the app:
* - is forcing RTL layout, regardless of the active language (for development purpose)
* - allows RTL layout when using RTL locale
*/
- (BOOL)isRTL
{
if ([self isRTLForced]) {
return YES;
}
if ([self isRTLAllowed] && [self isApplicationPreferredLanguageRTL]) {
return YES;
}
return NO;
}
/**
* Should be used very early during app start up
* Before the bridge is initialized
* @return whether the app allows RTL layout, default is true
*/
- (BOOL)isRTLAllowed
{
NSNumber *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"RCTI18nUtil_allowRTL"];
if (value == nil) {
return YES;
}
return [value boolValue];
}
- (void)allowRTL:(BOOL)rtlStatus
{
[[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_allowRTL"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
/**
* Could be used to test RTL layout with English
* Used for development and testing purpose
*/
- (BOOL)isRTLForced
{
BOOL rtlStatus = [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_forceRTL"];
return rtlStatus;
}
- (void)forceRTL:(BOOL)rtlStatus
{
[[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_forceRTL"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (BOOL)doLeftAndRightSwapInRTL
{
return [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"];
}
- (void)swapLeftAndRightInRTL:(BOOL)value
{
[[NSUserDefaults standardUserDefaults] setBool:value forKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
// Check if the current device language is RTL
- (BOOL)isDevicePreferredLanguageRTL
{
NSLocaleLanguageDirection direction =
[NSLocale characterDirectionForLanguage:[[NSLocale preferredLanguages] objectAtIndex:0]];
return direction == NSLocaleLanguageDirectionRightToLeft;
}
// Check if the current application language is RTL
- (BOOL)isApplicationPreferredLanguageRTL
{
NSWritingDirection direction = [NSParagraphStyle defaultWritingDirectionForLanguage:nil];
return direction == NSWritingDirectionRightToLeft;
}
@end

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) Facebook, Inc. and its 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>
#import <React/RCTAnimationType.h>
@interface RCTLayoutAnimation : NSObject
@property (nonatomic, readonly) NSTimeInterval duration;
@property (nonatomic, readonly) NSTimeInterval delay;
@property (nonatomic, readonly, copy) NSString *property ;
@property (nonatomic, readonly) CGFloat springDamping;
@property (nonatomic, readonly) CGFloat initialVelocity;
@property (nonatomic, readonly) RCTAnimationType animationType;
+ (void)initializeStatics;
- (instancetype)initWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
property:(NSString *)property
springDamping:(CGFloat)springDamping
initialVelocity:(CGFloat)initialVelocity
animationType:(RCTAnimationType)animationType;
- (instancetype)initWithDuration:(NSTimeInterval)duration config:(NSDictionary *)config;
- (void)performAnimations:(void (^)(void))animations withCompletionBlock:(void (^)(BOOL completed))completionBlock;
@end

View File

@ -0,0 +1,156 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTLayoutAnimation.h"
#import "RCTConvert.h"
@implementation RCTLayoutAnimation
static UIViewAnimationCurve _currentKeyboardAnimationCurve;
static UIViewAnimationOptions UIViewAnimationOptionsFromRCTAnimationType(RCTAnimationType type)
{
switch (type) {
case RCTAnimationTypeLinear:
return UIViewAnimationOptionCurveLinear;
case RCTAnimationTypeEaseIn:
return UIViewAnimationOptionCurveEaseIn;
case RCTAnimationTypeEaseOut:
return UIViewAnimationOptionCurveEaseOut;
case RCTAnimationTypeEaseInEaseOut:
return UIViewAnimationOptionCurveEaseInOut;
case RCTAnimationTypeKeyboard:
// http://stackoverflow.com/questions/18870447/how-to-use-the-default-ios7-uianimation-curve
return (UIViewAnimationOptions)(_currentKeyboardAnimationCurve << 16);
default:
RCTLogError(@"Unsupported animation type %lld", (long long)type);
return UIViewAnimationOptionCurveEaseInOut;
}
}
// Use a custom initialization function rather than implementing `+initialize` so that we can control
// when the initialization code runs. `+initialize` runs immediately before the first message is sent
// to the class which may be too late for us. By this time, we may have missed some
// `UIKeyboardWillChangeFrameNotification`s.
+ (void)initializeStatics
{
#if !TARGET_OS_TV
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillChangeFrame:)
name:UIKeyboardWillChangeFrameNotification
object:nil];
});
#endif
}
+ (void)keyboardWillChangeFrame:(NSNotification *)notification
{
#if !TARGET_OS_TV
NSDictionary *userInfo = notification.userInfo;
_currentKeyboardAnimationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
#endif
}
- (instancetype)initWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
property:(NSString *)property
springDamping:(CGFloat)springDamping
initialVelocity:(CGFloat)initialVelocity
animationType:(RCTAnimationType)animationType
{
if (self = [super init]) {
_duration = duration;
_delay = delay;
_property = property;
_springDamping = springDamping;
_initialVelocity = initialVelocity;
_animationType = animationType;
}
return self;
}
- (instancetype)initWithDuration:(NSTimeInterval)duration config:(NSDictionary *)config
{
if (!config) {
return nil;
}
if (self = [super init]) {
_property = [RCTConvert NSString:config[@"property"]];
_duration = [RCTConvert NSTimeInterval:config[@"duration"]] ?: duration;
if (_duration > 0.0 && _duration < 0.01) {
RCTLogError(@"RCTLayoutAnimationGroup expects timings to be in ms, not seconds.");
_duration = _duration * 1000.0;
}
_delay = [RCTConvert NSTimeInterval:config[@"delay"]];
if (_delay > 0.0 && _delay < 0.01) {
RCTLogError(@"RCTLayoutAnimationGroup expects timings to be in ms, not seconds.");
_delay = _delay * 1000.0;
}
_animationType = [RCTConvert RCTAnimationType:config[@"type"]];
if (_animationType == RCTAnimationTypeSpring) {
_springDamping = [RCTConvert CGFloat:config[@"springDamping"]];
_initialVelocity = [RCTConvert CGFloat:config[@"initialVelocity"]];
}
}
return self;
}
- (void)performAnimations:(void (^)(void))animations withCompletionBlock:(void (^)(BOOL completed))completionBlock
{
if (_animationType == RCTAnimationTypeSpring) {
[UIView animateWithDuration:_duration
delay:_delay
usingSpringWithDamping:_springDamping
initialSpringVelocity:_initialVelocity
options:UIViewAnimationOptionBeginFromCurrentState
animations:animations
completion:completionBlock];
} else {
UIViewAnimationOptions options =
UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionsFromRCTAnimationType(_animationType);
[UIView animateWithDuration:_duration
delay:_delay
options:options
animations:animations
completion:completionBlock];
}
}
- (BOOL)isEqual:(RCTLayoutAnimation *)animation
{
return _duration == animation.duration && _delay == animation.delay &&
(_property == animation.property || [_property isEqualToString:animation.property]) &&
_springDamping == animation.springDamping && _initialVelocity == animation.initialVelocity &&
_animationType == animation.animationType;
}
- (NSString *)description
{
return [NSString
stringWithFormat:
@"<%@: %p; duration: %f; delay: %f; property: %@; springDamping: %f; initialVelocity: %f; animationType: %li;>",
NSStringFromClass([self class]),
self,
_duration,
_delay,
_property,
_springDamping,
_initialVelocity,
(long)_animationType];
}
@end

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) Facebook, Inc. and its 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>
#import <React/RCTBridgeModule.h>
@class RCTLayoutAnimation;
@interface RCTLayoutAnimationGroup : NSObject
@property (nonatomic, readonly) RCTLayoutAnimation *creatingLayoutAnimation;
@property (nonatomic, readonly) RCTLayoutAnimation *updatingLayoutAnimation;
@property (nonatomic, readonly) RCTLayoutAnimation *deletingLayoutAnimation;
@property (nonatomic, copy) RCTResponseSenderBlock callback;
- (instancetype)initWithCreatingLayoutAnimation:(RCTLayoutAnimation *)creatingLayoutAnimation
updatingLayoutAnimation:(RCTLayoutAnimation *)updatingLayoutAnimation
deletingLayoutAnimation:(RCTLayoutAnimation *)deletingLayoutAnimation
callback:(RCTResponseSenderBlock)callback;
- (instancetype)initWithConfig:(NSDictionary *)config callback:(RCTResponseSenderBlock)callback;
@end

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTLayoutAnimationGroup.h"
#import "RCTConvert.h"
#import "RCTLayoutAnimation.h"
@implementation RCTLayoutAnimationGroup
- (instancetype)initWithCreatingLayoutAnimation:(RCTLayoutAnimation *)creatingLayoutAnimation
updatingLayoutAnimation:(RCTLayoutAnimation *)updatingLayoutAnimation
deletingLayoutAnimation:(RCTLayoutAnimation *)deletingLayoutAnimation
callback:(RCTResponseSenderBlock)callback
{
if (self = [super init]) {
_creatingLayoutAnimation = creatingLayoutAnimation;
_updatingLayoutAnimation = updatingLayoutAnimation;
_deletingLayoutAnimation = deletingLayoutAnimation;
_callback = callback;
}
return self;
}
- (instancetype)initWithConfig:(NSDictionary *)config callback:(RCTResponseSenderBlock)callback
{
if (!config) {
return nil;
}
if (self = [super init]) {
NSTimeInterval duration = [RCTConvert NSTimeInterval:config[@"duration"]];
if (duration > 0.0 && duration < 0.01) {
RCTLogError(@"RCTLayoutAnimationGroup expects timings to be in ms, not seconds.");
duration = duration * 1000.0;
}
_creatingLayoutAnimation = [[RCTLayoutAnimation alloc] initWithDuration:duration config:config[@"create"]];
_updatingLayoutAnimation = [[RCTLayoutAnimation alloc] initWithDuration:duration config:config[@"update"]];
_deletingLayoutAnimation = [[RCTLayoutAnimation alloc] initWithDuration:duration config:config[@"delete"]];
_callback = callback;
}
return self;
}
- (BOOL)isEqual:(RCTLayoutAnimationGroup *)layoutAnimation
{
RCTLayoutAnimation *creatingLayoutAnimation = layoutAnimation.creatingLayoutAnimation;
RCTLayoutAnimation *updatingLayoutAnimation = layoutAnimation.updatingLayoutAnimation;
RCTLayoutAnimation *deletingLayoutAnimation = layoutAnimation.deletingLayoutAnimation;
return (_creatingLayoutAnimation == creatingLayoutAnimation ||
[_creatingLayoutAnimation isEqual:creatingLayoutAnimation]) &&
(_updatingLayoutAnimation == updatingLayoutAnimation ||
[_updatingLayoutAnimation isEqual:updatingLayoutAnimation]) &&
(_deletingLayoutAnimation == deletingLayoutAnimation ||
[_deletingLayoutAnimation isEqual:deletingLayoutAnimation]);
}
- (NSString *)description
{
return
[NSString stringWithFormat:
@"<%@: %p; creatingLayoutAnimation: %@; updatingLayoutAnimation: %@; deletingLayoutAnimation: %@>",
NSStringFromClass([self class]),
self,
[_creatingLayoutAnimation description],
[_updatingLayoutAnimation description],
[_deletingLayoutAnimation description]];
}
@end

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) Facebook, Inc. and its 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>
@protocol RCTRedBoxExtraDataActionDelegate <NSObject>
- (void)reload;
@end
@interface RCTRedBoxExtraDataViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, weak) id<RCTRedBoxExtraDataActionDelegate> actionDelegate;
- (void)addExtraData:(NSDictionary *)data forIdentifier:(NSString *)identifier;
@end

View File

@ -0,0 +1,253 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTRedBoxExtraDataViewController.h"
@interface RCTRedBoxExtraDataCell : UITableViewCell
@property (nonatomic, strong) UILabel *keyLabel;
@property (nonatomic, strong) UILabel *valueLabel;
@end
@implementation RCTRedBoxExtraDataCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.backgroundColor = [UIColor colorWithRed:0.8 green:0 blue:0 alpha:1];
UILayoutGuide *contentLayout = self.contentView.layoutMarginsGuide;
self.keyLabel = [UILabel new];
[self.contentView addSubview:self.keyLabel];
self.keyLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.keyLabel.leadingAnchor constraintEqualToAnchor:contentLayout.leadingAnchor].active = YES;
[self.keyLabel.topAnchor constraintEqualToAnchor:contentLayout.topAnchor].active = YES;
[self.keyLabel.bottomAnchor constraintEqualToAnchor:contentLayout.bottomAnchor].active = YES;
[self.keyLabel.widthAnchor constraintEqualToAnchor:contentLayout.widthAnchor multiplier:0.3].active = YES;
self.keyLabel.textColor = [UIColor whiteColor];
self.keyLabel.numberOfLines = 0;
#if !TARGET_OS_TV
self.keyLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.keyLabel.font = [UIFont fontWithName:@"Menlo-Regular" size:12.0f];
#endif
self.valueLabel = [UILabel new];
[self.contentView addSubview:self.valueLabel];
self.valueLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.valueLabel.leadingAnchor constraintEqualToAnchor:self.keyLabel.trailingAnchor constant:10.f].active = YES;
[self.valueLabel.trailingAnchor constraintEqualToAnchor:contentLayout.trailingAnchor].active = YES;
[self.valueLabel.topAnchor constraintEqualToAnchor:contentLayout.topAnchor].active = YES;
[self.valueLabel.bottomAnchor constraintEqualToAnchor:contentLayout.bottomAnchor].active = YES;
self.valueLabel.textColor = [UIColor whiteColor];
self.valueLabel.numberOfLines = 0;
#if !TARGET_OS_TV
self.valueLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.valueLabel.font = [UIFont fontWithName:@"Menlo-Regular" size:12.0f];
#endif
}
return self;
}
@end
@interface RCTRedBoxExtraDataViewController ()
@end
@implementation RCTRedBoxExtraDataViewController {
UITableView *_tableView;
NSMutableArray *_extraDataTitle;
NSMutableArray *_extraData;
}
@synthesize actionDelegate = _actionDelegate;
- (instancetype)init
{
if (self = [super init]) {
_extraData = [NSMutableArray new];
_extraDataTitle = [NSMutableArray new];
self.view.backgroundColor = [UIColor colorWithRed:0.8 green:0 blue:0 alpha:1];
_tableView = [UITableView new];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.estimatedRowHeight = 200;
#if !TARGET_OS_TV
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
#endif
_tableView.rowHeight = UITableViewAutomaticDimension;
_tableView.allowsSelection = NO;
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
NSString *reloadText = @"Reload JS (\u2318R)";
NSString *dismissText = @"Dismiss (ESC)";
#else
NSString *reloadText = @"Reload JS";
NSString *dismissText = @"Dismiss";
#endif
UIButton *dismissButton = [UIButton buttonWithType:UIButtonTypeCustom];
dismissButton.translatesAutoresizingMaskIntoConstraints = NO;
dismissButton.accessibilityIdentifier = @"redbox-extra-data-dismiss";
dismissButton.titleLabel.font = [UIFont systemFontOfSize:13];
[dismissButton setTitle:dismissText forState:UIControlStateNormal];
[dismissButton setTitleColor:[UIColor colorWithWhite:1 alpha:0.5] forState:UIControlStateNormal];
[dismissButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[dismissButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
UIButton *reloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
reloadButton.accessibilityIdentifier = @"redbox-reload";
reloadButton.titleLabel.font = [UIFont systemFontOfSize:13];
[reloadButton setTitle:reloadText forState:UIControlStateNormal];
[reloadButton setTitleColor:[UIColor colorWithWhite:1 alpha:0.5] forState:UIControlStateNormal];
[reloadButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[reloadButton addTarget:self action:@selector(reload) forControlEvents:UIControlEventTouchUpInside];
UIStackView *buttonStackView = [UIStackView new];
buttonStackView.axis = UILayoutConstraintAxisHorizontal;
buttonStackView.distribution = UIStackViewDistributionEqualSpacing;
buttonStackView.alignment = UIStackViewAlignmentFill;
buttonStackView.spacing = 20;
[buttonStackView addArrangedSubview:dismissButton];
[buttonStackView addArrangedSubview:reloadButton];
buttonStackView.translatesAutoresizingMaskIntoConstraints = NO;
UIStackView *mainStackView = [UIStackView new];
mainStackView.axis = UILayoutConstraintAxisVertical;
mainStackView.backgroundColor = [UIColor colorWithRed:0.8 green:0 blue:0 alpha:1];
[mainStackView addArrangedSubview:_tableView];
[mainStackView addArrangedSubview:buttonStackView];
mainStackView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:mainStackView];
CGFloat tableHeight = self.view.bounds.size.height - 60.f;
[_tableView.heightAnchor constraintEqualToConstant:tableHeight].active = YES;
[_tableView.widthAnchor constraintEqualToAnchor:self.view.widthAnchor].active = YES;
CGFloat buttonWidth = self.view.bounds.size.width / 4;
[dismissButton.heightAnchor constraintEqualToConstant:60].active = YES;
[dismissButton.widthAnchor constraintEqualToConstant:buttonWidth].active = YES;
[reloadButton.heightAnchor constraintEqualToConstant:60].active = YES;
[reloadButton.widthAnchor constraintEqualToConstant:buttonWidth].active = YES;
}
return self;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[_tableView reloadData];
}
- (NSInteger)tableView:(__unused UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[_extraData objectAtIndex:section] count];
}
- (CGFloat)tableView:(__unused UITableView *)tableView heightForHeaderInSection:(__unused NSInteger)section
{
return 40;
}
- (UIView *)tableView:(__unused UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [UIView new];
view.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
UILabel *header = [UILabel new];
[view addSubview:header];
header.translatesAutoresizingMaskIntoConstraints = NO;
[header.leadingAnchor constraintEqualToAnchor:view.leadingAnchor constant:5].active = YES;
[header.trailingAnchor constraintEqualToAnchor:view.trailingAnchor].active = YES;
[header.topAnchor constraintEqualToAnchor:view.topAnchor].active = YES;
[header.bottomAnchor constraintEqualToAnchor:view.bottomAnchor].active = YES;
header.textColor = [UIColor whiteColor];
header.font = [UIFont fontWithName:@"Menlo-Bold" size:14.0f];
header.text = [_extraDataTitle[section] uppercaseString];
return view;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuseIdentifier = @"RedBoxExtraData";
RCTRedBoxExtraDataCell *cell =
(RCTRedBoxExtraDataCell *)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (cell == nil) {
cell = [[RCTRedBoxExtraDataCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
}
NSArray *dataKVPair = _extraData[indexPath.section][indexPath.row];
cell.keyLabel.text = dataKVPair[0];
cell.valueLabel.text = dataKVPair[1];
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(__unused UITableView *)tableView
{
return _extraDataTitle.count;
}
- (void)addExtraData:(NSDictionary *)data forIdentifier:(NSString *)identifier
{
dispatch_async(dispatch_get_main_queue(), ^{
NSMutableArray *newData = [NSMutableArray new];
for (id key in data) {
[newData addObject:@[
[NSString stringWithFormat:@"%@", key],
[NSString stringWithFormat:@"%@", [data objectForKey:key]]
]];
}
NSInteger idx = [self->_extraDataTitle indexOfObject:identifier];
if (idx == NSNotFound) {
[self->_extraDataTitle addObject:identifier];
[self->_extraData addObject:newData];
} else {
[self->_extraData replaceObjectAtIndex:idx withObject:newData];
}
[self->_tableView reloadData];
});
}
- (void)dismiss
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)reload
{
[_actionDelegate reload];
}
#pragma mark - Key commands
- (NSArray<UIKeyCommand *> *)keyCommands
{
return @[
// Dismiss
[UIKeyCommand keyCommandWithInput:UIKeyInputEscape modifierFlags:0 action:@selector(dismiss)],
// Reload
[UIKeyCommand keyCommandWithInput:@"r" modifierFlags:UIKeyModifierCommand action:@selector(reload)]
];
}
@end

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <objc/runtime.h>
#import <React/RCTBridge.h>
NS_ASSUME_NONNULL_BEGIN
// TODO: Eventually this should go away and files should just include RCTSurfacePresenter.h, but
// that pulls in all of fabric which doesn't compile in open source yet, so we mirror the protocol
// and duplicate the category here for now.
@protocol RCTSurfacePresenterObserver <NSObject>
@optional
- (void)willMountComponentsWithRootTag:(NSInteger)rootTag;
- (void)didMountComponentsWithRootTag:(NSInteger)rootTag;
@end
@protocol RCTSurfacePresenterStub <NSObject>
- (BOOL)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictionary *)props;
- (void)addObserver:(id<RCTSurfacePresenterObserver>)observer;
- (void)removeObserver:(id<RCTSurfacePresenterObserver>)observer;
@end
@interface RCTBridge (RCTSurfacePresenterStub)
- (id<RCTSurfacePresenterStub>)surfacePresenter;
- (void)setSurfacePresenter:(id<RCTSurfacePresenterStub>)presenter;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,22 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTSurfacePresenterStub.h"
@implementation RCTBridge (RCTSurfacePresenterStub)
- (id<RCTSurfacePresenterStub>)surfacePresenter
{
return objc_getAssociatedObject(self, @selector(surfacePresenter));
}
- (void)setSurfacePresenter:(id<RCTSurfacePresenterStub>)surfacePresenter
{
objc_setAssociatedObject(self, @selector(surfacePresenter), surfacePresenter, OBJC_ASSOCIATION_RETAIN);
}
@end

174
node_modules/react-native/React/Modules/RCTUIManager.h generated vendored Normal file
View File

@ -0,0 +1,174 @@
/*
* Copyright (c) Facebook, Inc. and its 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>
#import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTInvalidating.h>
#import <React/RCTRootView.h>
#import <React/RCTViewManager.h>
/**
* Posted right before re-render happens. This is a chance for views to invalidate their state so
* next render cycle will pick up updated views and layout appropriately.
*/
RCT_EXTERN NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification;
@class RCTLayoutAnimationGroup;
@class RCTUIManagerObserverCoordinator;
/**
* The RCTUIManager is the module responsible for updating the view hierarchy.
*/
@interface RCTUIManager : NSObject <RCTBridgeModule, RCTInvalidating>
/**
* Register a root view tag and creates corresponding `rootView` and
* `rootShadowView`.
*/
- (void)registerRootViewTag:(NSNumber *)rootTag;
/**
* Register a root view with the RCTUIManager.
*/
- (void)registerRootView:(UIView *)rootView;
/**
* Gets the view name associated with a reactTag.
*/
- (NSString *)viewNameForReactTag:(NSNumber *)reactTag;
/**
* Gets the view associated with a reactTag.
*/
- (UIView *)viewForReactTag:(NSNumber *)reactTag;
/**
* Gets the shadow view associated with a reactTag.
*/
- (RCTShadowView *)shadowViewForReactTag:(NSNumber *)reactTag;
/**
* Set the available size (`availableSize` property) for a root view.
* This might be used in response to changes in external layout constraints.
* This value will be directly trasmitted to layout engine and defines how big viewport is;
* this value does not affect root node size style properties.
* Can be considered as something similar to `setSize:forView:` but applicable only for root view.
*/
- (void)setAvailableSize:(CGSize)availableSize forRootView:(UIView *)rootView;
/**
* Sets local data for a shadow view corresponded with given view.
* In some cases we need a way to specify some environmental data to shadow view
* to improve layout (or do something similar), so `localData` serves these needs.
* For example, any stateful embedded native views may benefit from this.
* Have in mind that this data is not supposed to interfere with the state of
* the shadow view.
* Please respect one-directional data flow of React.
*/
- (void)setLocalData:(NSObject *)localData forView:(UIView *)view;
/**
* Set the size of a view. This might be in response to a screen rotation
* or some other layout event outside of the React-managed view hierarchy.
*/
- (void)setSize:(CGSize)size forView:(UIView *)view;
/**
* Set the natural size of a view, which is used when no explicit size is set.
* Use `UIViewNoIntrinsicMetric` to ignore a dimension.
* The `size` must NOT include padding and border.
*/
- (void)setIntrinsicContentSize:(CGSize)intrinsicContentSize forView:(UIView *)view;
/**
* Sets up layout animation which will perform on next layout pass.
* The animation will affect only one next layout pass.
* Must be called on the main queue.
*/
- (void)setNextLayoutAnimationGroup:(RCTLayoutAnimationGroup *)layoutAnimationGroup;
/**
* Schedule a block to be executed on the UI thread. Useful if you need to execute
* view logic after all currently queued view updates have completed.
*/
- (void)addUIBlock:(RCTViewManagerUIBlock)block;
/**
* Schedule a block to be executed on the UI thread. Useful if you need to execute
* view logic before all currently queued view updates have completed.
*/
- (void)prependUIBlock:(RCTViewManagerUIBlock)block;
/**
* Used by native animated module to bypass the process of updating the values through the shadow
* view hierarchy. This method will directly update native views, which means that updates for
* layout-related propertied won't be handled properly.
* Make sure you know what you're doing before calling this method :)
*/
- (void)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag
viewName:(NSString *)viewName
props:(NSDictionary *)props;
/**
* Given a reactTag from a component, find its root view, if possible.
* Otherwise, this will give back nil.
*
* @param reactTag the component tag
* @param completion the completion block that will hand over the rootView, if any.
*
*/
- (void)rootViewForReactTag:(NSNumber *)reactTag withCompletion:(void (^)(UIView *view))completion;
/**
* Finds a view that is tagged with nativeID as its nativeID prop
* with the associated rootTag root tag view hierarchy. Returns the
* view if found, nil otherwise.
*
* @param nativeID the id reference to native component relative to root view.
* @param rootTag the react tag of root view hierarchy from which to find the view.
*/
- (UIView *)viewForNativeID:(NSString *)nativeID withRootTag:(NSNumber *)rootTag;
/**
* Register a view that is tagged with nativeID as its nativeID prop
*
* @param nativeID the id reference to native component relative to root view.
* @param view the view that is tagged with nativeID as its nativeID prop.
*/
- (void)setNativeID:(NSString *)nativeID forView:(UIView *)view;
/**
* The view that is currently first responder, according to the JS context.
*/
+ (UIView *)JSResponder;
/**
* In some cases we might want to trigger layout from native side.
* React won't be aware of this, so we need to make sure it happens.
*/
- (void)setNeedsLayout;
/**
* Dedicated object for subscribing for UIManager events.
* See `RCTUIManagerObserver` protocol for more details.
*/
@property (atomic, retain, readonly) RCTUIManagerObserverCoordinator *observerCoordinator;
@end
/**
* This category makes the current RCTUIManager instance available via the
* RCTBridge, which is useful for RCTBridgeModules or RCTViewManagers that
* need to access the RCTUIManager.
*/
@interface RCTBridge (RCTUIManager)
@property (nonatomic, readonly) RCTUIManager *uiManager;
@end

1636
node_modules/react-native/React/Modules/RCTUIManager.m generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) Facebook, Inc. and its 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>
#import <React/RCTViewManager.h>
typedef dispatch_block_t RCTUIManagerMountingBlock;
/**
* Allows hooking into UIManager internals. This can be used to execute code at
* specific points during the view updating process.
* New observers must not be added inside observer handlers.
* The particular order of handler invocation is not guaranteed.
* All observer handlers are called on UIManager queue.
*/
@protocol RCTUIManagerObserver <NSObject>
@optional
/**
* Called just before the UIManager layout views.
* It allows performing some operation for components which contain custom
* layout logic right before regular Yoga based layout. So, for instance,
* some components which have own React-independent state can compute and cache
* own intrinsic content size (which will be used by Yoga) at this point.
*/
- (void)uiManagerWillPerformLayout:(RCTUIManager *)manager;
/**
* Called just after the UIManager layout views.
* It allows performing custom layout logic right after regular Yoga based layout.
* So, for instance, this can be used for computing final layout for a component,
* since it has its final frame set by Yoga at this point.
*/
- (void)uiManagerDidPerformLayout:(RCTUIManager *)manager;
/**
* Called before flushing UI blocks at the end of a batch.
* This is called from the UIManager queue. Can be used to add UI operations in that batch.
*/
- (void)uiManagerWillPerformMounting:(RCTUIManager *)manager;
/**
* Called right before flushing UI blocks and allows to intercept the mounting process.
* Return `YES` to cancel default execution of the `block` (and perform the
* execution later).
*/
- (BOOL)uiManager:(RCTUIManager *)manager performMountingWithBlock:(RCTUIManagerMountingBlock)block;
/**
* Called just after flushing UI blocks.
* This is called from the UIManager queue.
*/
- (void)uiManagerDidPerformMounting:(RCTUIManager *)manager;
@end
/**
* Simple helper which take care of RCTUIManager's observers.
*/
@interface RCTUIManagerObserverCoordinator : NSObject <RCTUIManagerObserver>
/**
* Add a UIManagerObserver. See the `RCTUIManagerObserver` protocol for more info.
* References to observers are held weakly.
* This method can be called safely from any queue.
*/
- (void)addObserver:(id<RCTUIManagerObserver>)observer;
/**
* Remove a `UIManagerObserver`.
* This method can be called safely from any queue.
*/
- (void)removeObserver:(id<RCTUIManagerObserver>)observer;
@end

View File

@ -0,0 +1,100 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTUIManagerObserverCoordinator.h"
#import <mutex>
#import "RCTUIManager.h"
@implementation RCTUIManagerObserverCoordinator {
NSHashTable<id<RCTUIManagerObserver>> *_observers;
std::mutex _mutex;
}
- (instancetype)init
{
if (self = [super init]) {
_observers = [[NSHashTable alloc] initWithOptions:NSHashTableWeakMemory capacity:0];
}
return self;
}
- (void)addObserver:(id<RCTUIManagerObserver>)observer
{
std::lock_guard<std::mutex> lock(_mutex);
[self->_observers addObject:observer];
}
- (void)removeObserver:(id<RCTUIManagerObserver>)observer
{
std::lock_guard<std::mutex> lock(_mutex);
[self->_observers removeObject:observer];
}
#pragma mark - RCTUIManagerObserver
- (void)uiManagerWillPerformLayout:(RCTUIManager *)manager
{
std::lock_guard<std::mutex> lock(_mutex);
for (id<RCTUIManagerObserver> observer in _observers) {
if ([observer respondsToSelector:@selector(uiManagerWillPerformLayout:)]) {
[observer uiManagerWillPerformLayout:manager];
}
}
}
- (void)uiManagerDidPerformLayout:(RCTUIManager *)manager
{
std::lock_guard<std::mutex> lock(_mutex);
for (id<RCTUIManagerObserver> observer in _observers) {
if ([observer respondsToSelector:@selector(uiManagerDidPerformLayout:)]) {
[observer uiManagerDidPerformLayout:manager];
}
}
}
- (void)uiManagerWillPerformMounting:(RCTUIManager *)manager
{
std::lock_guard<std::mutex> lock(_mutex);
for (id<RCTUIManagerObserver> observer in _observers) {
if ([observer respondsToSelector:@selector(uiManagerWillPerformMounting:)]) {
[observer uiManagerWillPerformMounting:manager];
}
}
}
- (BOOL)uiManager:(RCTUIManager *)manager performMountingWithBlock:(RCTUIManagerMountingBlock)block
{
std::lock_guard<std::mutex> lock(_mutex);
for (id<RCTUIManagerObserver> observer in _observers) {
if ([observer respondsToSelector:@selector(uiManager:performMountingWithBlock:)]) {
if ([observer uiManager:manager performMountingWithBlock:block]) {
return YES;
}
}
}
return NO;
}
- (void)uiManagerDidPerformMounting:(RCTUIManager *)manager
{
std::lock_guard<std::mutex> lock(_mutex);
for (id<RCTUIManagerObserver> observer in _observers) {
if ([observer respondsToSelector:@selector(uiManagerDidPerformMounting:)]) {
[observer uiManagerDidPerformMounting:manager];
}
}
}
@end

View File

@ -0,0 +1,105 @@
/*
* Copyright (c) Facebook, Inc. and its 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>
#import <React/RCTAssert.h>
#import <React/RCTDefines.h>
/**
* Queues Problem Intro:
* UIManager queue is a special queue because it has a special relationship with
* the Main queue.
*
* This particular relationship comes from two key factors:
* 1. UIManager initiates execution of many blocks on the Main queue;
* 2. In some cases, we want to initiate (and wait for) some UIManager's work *synchronously* from
* the Main queue.
*
* So, how can we meet these criteria?
* "Pseudo UIManager queue" comes to rescue!
*
* "Pseudo UIManager queue" means the safe execution of typical UIManager's work
* on the Main queue while the UIManager queue is explicitly blocked for preventing
* simultaneous/concurrent memory access.
*
* So, how can we technically do this?
* 1. `RCTAssertUIManagerQueue` is okay with execution on both actual UIManager and
* Pseudo UIManager queues.
* 2. Both `RCTExecuteOnUIManagerQueue` and `RCTUnsafeExecuteOnUIManagerQueueSync`
* execute given block *synchronously* if they were called on actual UIManager
* or Pseudo UIManager queues.
* 3. `RCTExecuteOnMainQueue` executes given block *synchronously* if we already on
* the Main queue.
* 4. `RCTUnsafeExecuteOnUIManagerQueueSync` is smart enough to do the trick:
* It detects calling on the Main queue and in this case, instead of doing
* trivial *synchronous* dispatch, it does:
* - Block the Main queue;
* - Dispatch the special block on UIManager queue to block the queue and
* concurrent memory access;
* - Execute the given block on the Main queue;
* - Unblock the UIManager queue.
*
* Imagine the analogy: We have two queues: the Main one and UIManager one.
* And these queues are two lanes of railway that go in parallel. Then,
* at some point, we merge UIManager lane with the Main lane, and all cars use
* the unified the Main lane.
* And then we split lanes again.
*
* This solution assumes that the code running on UIManager queue will never
* *explicitly* block the Main queue via calling `RCTUnsafeExecuteOnMainQueueSync`.
* Otherwise, it can cause a deadlock.
*/
/**
* Returns UIManager queue.
*/
RCT_EXTERN dispatch_queue_t RCTGetUIManagerQueue(void);
/**
* Default name for the UIManager queue.
*/
RCT_EXTERN char *const RCTUIManagerQueueName;
/**
* Check if we are currently on UIManager queue.
* Please do not use this unless you really know what you're doing.
*/
RCT_EXTERN BOOL RCTIsUIManagerQueue(void);
/**
* Check if we are currently on Pseudo UIManager queue.
* Please do not use this unless you really know what you're doing.
*/
RCT_EXTERN BOOL RCTIsPseudoUIManagerQueue(void);
/**
* *Asynchronously* executes the specified block on the UIManager queue.
* Unlike `dispatch_async()` this will execute the block immediately
* if we're already on the UIManager queue.
*/
RCT_EXTERN void RCTExecuteOnUIManagerQueue(dispatch_block_t block);
/**
* *Synchronously* executes the specified block on the UIManager queue.
* Unlike `dispatch_sync()` this will execute the block immediately
* if we're already on the UIManager queue.
* Please do not use this unless you really know what you're doing.
*/
RCT_EXTERN void RCTUnsafeExecuteOnUIManagerQueueSync(dispatch_block_t block);
/**
* Convenience macro for asserting that we're running on UIManager queue.
*/
#define RCTAssertUIManagerQueue() \
RCTAssert( \
RCTIsUIManagerQueue() || RCTIsPseudoUIManagerQueue(), @"This function must be called on the UIManager queue")
/**
* Returns new unique root view tag.
*/
RCT_EXTERN NSNumber *RCTAllocateRootViewTag(void);

View File

@ -0,0 +1,103 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTUIManagerUtils.h"
#import <libkern/OSAtomic.h>
#import "RCTAssert.h"
char *const RCTUIManagerQueueName = "com.facebook.react.ShadowQueue";
static BOOL pseudoUIManagerQueueFlag = NO;
dispatch_queue_t RCTGetUIManagerQueue(void)
{
static dispatch_queue_t shadowQueue;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if ([NSOperation instancesRespondToSelector:@selector(qualityOfService)]) {
dispatch_queue_attr_t attr =
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INTERACTIVE, 0);
shadowQueue = dispatch_queue_create(RCTUIManagerQueueName, attr);
} else {
shadowQueue = dispatch_queue_create(RCTUIManagerQueueName, DISPATCH_QUEUE_SERIAL);
dispatch_set_target_queue(shadowQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0));
}
});
return shadowQueue;
}
BOOL RCTIsUIManagerQueue()
{
static void *queueKey = &queueKey;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
dispatch_queue_set_specific(RCTGetUIManagerQueue(), queueKey, queueKey, NULL);
});
return dispatch_get_specific(queueKey) == queueKey;
}
BOOL RCTIsPseudoUIManagerQueue()
{
if (RCTIsMainQueue()) {
return pseudoUIManagerQueueFlag;
}
return NO;
}
void RCTExecuteOnUIManagerQueue(dispatch_block_t block)
{
if (RCTIsUIManagerQueue() || RCTIsPseudoUIManagerQueue()) {
block();
} else {
dispatch_async(RCTGetUIManagerQueue(), ^{
block();
});
}
}
void RCTUnsafeExecuteOnUIManagerQueueSync(dispatch_block_t block)
{
if (RCTIsUIManagerQueue() || RCTIsPseudoUIManagerQueue()) {
block();
} else {
if (RCTIsMainQueue()) {
dispatch_semaphore_t mainQueueBlockingSemaphore = dispatch_semaphore_create(0);
dispatch_semaphore_t uiManagerQueueBlockingSemaphore = dispatch_semaphore_create(0);
// Dispatching block which blocks UI Manager queue.
dispatch_async(RCTGetUIManagerQueue(), ^{
// Initiating `block` execution on main queue.
dispatch_semaphore_signal(mainQueueBlockingSemaphore);
// Waiting for finishing `block`.
dispatch_semaphore_wait(uiManagerQueueBlockingSemaphore, DISPATCH_TIME_FOREVER);
});
// Waiting for block on UIManager queue.
dispatch_semaphore_wait(mainQueueBlockingSemaphore, DISPATCH_TIME_FOREVER);
pseudoUIManagerQueueFlag = YES;
// `block` execution while UIManager queue is blocked by semaphore.
block();
pseudoUIManagerQueueFlag = NO;
// Signalling UIManager block.
dispatch_semaphore_signal(uiManagerQueueBlockingSemaphore);
} else {
dispatch_sync(RCTGetUIManagerQueue(), ^{
block();
});
}
}
}
NSNumber *RCTAllocateRootViewTag()
{
// Numbering of these tags goes from 1, 11, 21, 31, ..., 100501, ...
static int64_t rootViewTagCounter = -1;
return @(OSAtomicIncrement64(&rootViewTagCounter) * 10 + 1);
}