mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-24 05:34:37 +08:00
Remove compatible system code for iOS8 and before (#23656)
Summary: We already only support `iOS9+`, so we can remove all compatible codes now. [iOS] [Fixed] - Remove compatible system code for iOS8 and before Pull Request resolved: https://github.com/facebook/react-native/pull/23656 Differential Revision: D14224986 Pulled By: hramos fbshipit-source-id: cac9ffe6788dd3eaf4f4f5f2b219f325ba78e85f
This commit is contained in:
committed by
Facebook Github Bot
parent
58c956768a
commit
06c6c7c673
@@ -222,37 +222,12 @@ static UIColor *defaultPlaceholderColor()
|
||||
- (CGSize)sizeThatFits:(CGSize)size
|
||||
{
|
||||
// Returned fitting size depends on text size and placeholder size.
|
||||
CGSize textSize = [self fixedSizeThatFits:size];
|
||||
CGSize textSize = [super sizeThatFits:size];
|
||||
CGSize placeholderSize = self.placeholderSize;
|
||||
// Returning size DOES contain `textContainerInset` (aka `padding`).
|
||||
return CGSizeMake(MAX(textSize.width, placeholderSize.width), MAX(textSize.height, placeholderSize.height));
|
||||
}
|
||||
|
||||
- (CGSize)fixedSizeThatFits:(CGSize)size
|
||||
{
|
||||
// UITextView on iOS 8 has a bug that automatically scrolls to the top
|
||||
// when calling `sizeThatFits:`. Use a copy so that self is not screwed up.
|
||||
static BOOL useCustomImplementation = NO;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
useCustomImplementation = ![[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){9,0,0}];
|
||||
});
|
||||
|
||||
if (!useCustomImplementation) {
|
||||
return [super sizeThatFits:size];
|
||||
}
|
||||
|
||||
if (!_detachedTextView) {
|
||||
_detachedTextView = [UITextView new];
|
||||
}
|
||||
|
||||
_detachedTextView.attributedText = self.attributedText;
|
||||
_detachedTextView.font = self.font;
|
||||
_detachedTextView.textContainerInset = self.textContainerInset;
|
||||
|
||||
return [_detachedTextView sizeThatFits:size];
|
||||
}
|
||||
|
||||
#pragma mark - Context Menu
|
||||
|
||||
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
|
||||
|
||||
@@ -14,11 +14,6 @@
|
||||
|
||||
#if RCT_DEV
|
||||
|
||||
static BOOL RCTIsIOS8OrEarlier()
|
||||
{
|
||||
return [UIDevice currentDevice].systemVersion.floatValue < 9;
|
||||
}
|
||||
|
||||
@interface RCTKeyCommand : NSObject <NSCopying>
|
||||
|
||||
@property (nonatomic, strong) UIKeyCommand *keyCommand;
|
||||
@@ -119,7 +114,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
// NOTE: throttle the key handler because on iOS 9 the handleKeyCommand:
|
||||
// method gets called repeatedly if the command key is held down.
|
||||
static NSTimeInterval lastCommand = 0;
|
||||
if (RCTIsIOS8OrEarlier() || CACurrentMediaTime() - lastCommand > 0.5) {
|
||||
if (CACurrentMediaTime() - lastCommand > 0.5) {
|
||||
for (RCTKeyCommand *command in [RCTKeyCommands sharedInstance].commands) {
|
||||
if ([command.keyCommand.input isEqualToString:key.input] &&
|
||||
command.keyCommand.modifierFlags == key.modifierFlags) {
|
||||
@@ -171,7 +166,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
|
||||
// NOTE: throttle the key handler because on iOS 9 the handleKeyCommand:
|
||||
// method gets called repeatedly if the command key is held down.
|
||||
if (RCTIsIOS8OrEarlier() || CACurrentMediaTime() - lastDoubleCommand > 0.5) {
|
||||
if (CACurrentMediaTime() - lastDoubleCommand > 0.5) {
|
||||
command.block(key);
|
||||
lastDoubleCommand = CACurrentMediaTime();
|
||||
}
|
||||
@@ -189,44 +184,14 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
|
||||
@end
|
||||
|
||||
@implementation UIApplication (RCTKeyCommands)
|
||||
|
||||
// Required for iOS 8.x
|
||||
- (BOOL)RCT_sendAction:(SEL)action to:(id)target from:(id)sender forEvent:(UIEvent *)event
|
||||
{
|
||||
if (action == @selector(RCT_handleKeyCommand:)) {
|
||||
[self RCT_handleKeyCommand:sender];
|
||||
return YES;
|
||||
} else if (action == @selector(RCT_handleDoublePressKeyCommand:)) {
|
||||
[self RCT_handleDoublePressKeyCommand:sender];
|
||||
return YES;
|
||||
}
|
||||
return [self RCT_sendAction:action to:target from:sender forEvent:event];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTKeyCommands
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
if (RCTIsIOS8OrEarlier()) {
|
||||
|
||||
// swizzle UIApplication
|
||||
RCTSwapInstanceMethods([UIApplication class],
|
||||
@selector(keyCommands),
|
||||
@selector(RCT_keyCommands));
|
||||
|
||||
RCTSwapInstanceMethods([UIApplication class],
|
||||
@selector(sendAction:to:from:forEvent:),
|
||||
@selector(RCT_sendAction:to:from:forEvent:));
|
||||
} else {
|
||||
|
||||
// swizzle UIResponder
|
||||
RCTSwapInstanceMethods([UIResponder class],
|
||||
@selector(keyCommands),
|
||||
@selector(RCT_keyCommands));
|
||||
}
|
||||
// swizzle UIResponder
|
||||
RCTSwapInstanceMethods([UIResponder class],
|
||||
@selector(keyCommands),
|
||||
@selector(RCT_keyCommands));
|
||||
}
|
||||
|
||||
+ (instancetype)sharedInstance
|
||||
@@ -254,17 +219,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
|
||||
if (input.length && flags && RCTIsIOS8OrEarlier()) {
|
||||
|
||||
// Workaround around the first cmd not working: http://openradar.appspot.com/19613391
|
||||
// You can register just the cmd key and do nothing. This ensures that
|
||||
// command-key modified commands will work first time. Fixed in iOS 9.
|
||||
|
||||
[self registerKeyCommandWithInput:@""
|
||||
modifierFlags:flags
|
||||
action:nil];
|
||||
}
|
||||
|
||||
UIKeyCommand *command = [UIKeyCommand keyCommandWithInput:input
|
||||
modifierFlags:flags
|
||||
action:@selector(RCT_handleKeyCommand:)];
|
||||
@@ -306,17 +260,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
|
||||
if (input.length && flags && RCTIsIOS8OrEarlier()) {
|
||||
|
||||
// Workaround around the first cmd not working: http://openradar.appspot.com/19613391
|
||||
// You can register just the cmd key and do nothing. This ensures that
|
||||
// command-key modified commands will work first time. Fixed in iOS 9.
|
||||
|
||||
[self registerDoublePressKeyCommandWithInput:@""
|
||||
modifierFlags:flags
|
||||
action:nil];
|
||||
}
|
||||
|
||||
UIKeyCommand *command = [UIKeyCommand keyCommandWithInput:input
|
||||
modifierFlags:flags
|
||||
action:@selector(RCT_handleDoublePressKeyCommand:)];
|
||||
|
||||
@@ -11,20 +11,6 @@
|
||||
|
||||
@end
|
||||
|
||||
// We need this ugly runtime check because [streamTask captureStreams] below fails on iOS version
|
||||
// earlier than 9.0. Unfortunately none of the proper ways of checking worked:
|
||||
//
|
||||
// - NSURLSessionStreamTask class is available and is not Null on iOS 8
|
||||
// - [[NSURLSessionStreamTask new] respondsToSelector:@selector(captureStreams)] is always NO
|
||||
// - The instance we get in URLSession:dataTask:didBecomeStreamTask: is of __NSCFURLLocalStreamTaskFromDataTask
|
||||
// and it responds to captureStreams on iOS 9+ but doesn't on iOS 8. Which means we can't get direct access
|
||||
// to the streams on iOS 8 and at that point it's too late to change the behavior back to dataTask
|
||||
// - The compile-time #ifdef's can't be used because an app compiled for iOS8 can still run on iOS9
|
||||
|
||||
static BOOL isStreamTaskSupported() {
|
||||
return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){9,0,0}];
|
||||
}
|
||||
|
||||
@implementation RCTMultipartDataTask {
|
||||
NSURL *_url;
|
||||
RCTMultipartDataTaskCallback _partHandler;
|
||||
@@ -52,9 +38,7 @@ static BOOL isStreamTaskSupported() {
|
||||
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]
|
||||
delegate:self delegateQueue:nil];
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:_url];
|
||||
if (isStreamTaskSupported()) {
|
||||
[request addValue:@"multipart/mixed" forHTTPHeaderField:@"Accept"];
|
||||
}
|
||||
[request addValue:@"multipart/mixed" forHTTPHeaderField:@"Accept"];
|
||||
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request];
|
||||
[dataTask resume];
|
||||
[session finishTasksAndInvalidate];
|
||||
|
||||
@@ -142,19 +142,8 @@ static UIFont *cachedSystemFont(CGFloat size, RCTFontWeight weight)
|
||||
if (defaultFontHandler) {
|
||||
NSString *fontWeightDescription = FontWeightDescriptionFromUIFontWeight(weight);
|
||||
font = defaultFontHandler(size, fontWeightDescription);
|
||||
} else if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
|
||||
// Only supported on iOS8.2 and above
|
||||
font = [UIFont systemFontOfSize:size weight:weight];
|
||||
} else {
|
||||
if (weight >= UIFontWeightBold) {
|
||||
font = [UIFont boldSystemFontOfSize:size];
|
||||
} else if (weight >= UIFontWeightMedium) {
|
||||
font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:size];
|
||||
} else if (weight <= UIFontWeightLight) {
|
||||
font = [UIFont fontWithName:@"HelveticaNeue-Light" size:size];
|
||||
} else {
|
||||
font = [UIFont systemFontOfSize:size];
|
||||
}
|
||||
font = [UIFont systemFontOfSize:size weight:weight];
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user