Ported TabBarIOS to OSS and unified implementation

This commit is contained in:
Nick Lockwood
2015-03-05 16:36:41 -08:00
parent ab2537816f
commit fb2f063ef5
51 changed files with 1148 additions and 478 deletions

View File

@@ -1,11 +0,0 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, RCTAnimationType) {
RCTAnimationTypeSpring = 0,
RCTAnimationTypeLinear,
RCTAnimationTypeEaseIn,
RCTAnimationTypeEaseOut,
RCTAnimationTypeEaseInEaseOut,
};

View File

@@ -1,13 +0,0 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#import <UIKit/UIKit.h>
/**
* Defines a View that wants to support auto insets adjustment
*/
@protocol RCTAutoInsetsProtocol
@property (nonatomic, assign, readwrite) UIEdgeInsets contentInset;
@property (nonatomic, assign, readwrite) BOOL automaticallyAdjustContentInsets;
@end

View File

@@ -3,9 +3,9 @@
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>
#import "Layout.h"
#import "RCTPointerEvents.h"
#import "RCTAnimationType.h"
#import "../Layout/Layout.h"
#import "../Views/RCTAnimationType.h"
#import "../Views/RCTPointerEvents.h"
/**
* This class provides a collection of conversion functions for mapping
@@ -47,7 +47,6 @@
+ (UIColor *)UIColor:(id)json;
+ (CGColorRef)CGColor:(id)json;
+ (CAKeyframeAnimation *)GIF:(id)json;
+ (UIImage *)UIImage:(id)json;
+ (CGImageRef)CGImage:(id)json;
@@ -68,6 +67,10 @@
@end
#ifdef __cplusplus
extern "C" {
#endif
/**
* This function will attempt to set a property using a json value by first
* inferring the correct type from all available information, and then
@@ -82,3 +85,7 @@ BOOL RCTSetProperty(id target, NSString *keypath, id json);
* be set, it will do nothing and return NO.
*/
BOOL RCTCopyProperty(id target, id source, NSString *keypath);
#ifdef __cplusplus
}
#endif

View File

@@ -4,9 +4,6 @@
#import <objc/message.h>
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "RCTLog.h"
CGFloat const RCTDefaultFontSize = 14;
@@ -431,88 +428,11 @@ RCT_STRUCT_CONVERTER(CGAffineTransform, (@[@"a", @"b", @"c", @"d", @"tx", @"ty"]
return [self UIColor:json].CGColor;
}
+ (CAKeyframeAnimation *)GIF:(id)json
{
CGImageSourceRef imageSource = NULL;
if ([json isKindOfClass:[NSString class]]) {
NSString *path = json;
if (path.length == 0) {
return nil;
}
NSURL *fileURL = [path isAbsolutePath] ? [NSURL fileURLWithPath:path] : [[NSBundle mainBundle] URLForResource:path withExtension:nil];
imageSource = CGImageSourceCreateWithURL((CFURLRef)fileURL, NULL);
} else if ([json isKindOfClass:[NSData class]]) {
NSData *data = json;
if (data.length == 0) {
return nil;
}
imageSource = CGImageSourceCreateWithData((CFDataRef)data, NULL);
} else {
RCTLogMustFix(@"Expected NSString or NSData for GIF, received %@: %@", [json class], json);
return nil;
}
if (!UTTypeConformsTo(CGImageSourceGetType(imageSource), kUTTypeGIF)) {
CFRelease(imageSource);
return nil;
}
NSDictionary *properties = (__bridge_transfer NSDictionary *)CGImageSourceCopyProperties(imageSource, NULL);
NSUInteger loopCount = [properties[(id)kCGImagePropertyGIFDictionary][(id)kCGImagePropertyGIFLoopCount] unsignedIntegerValue];
size_t imageCount = CGImageSourceGetCount(imageSource);
NSTimeInterval duration = 0;
NSMutableArray *delays = [NSMutableArray arrayWithCapacity:imageCount];
NSMutableArray *images = [NSMutableArray arrayWithCapacity:imageCount];
for (size_t i = 0; i < imageCount; i++) {
CGImageRef image = CGImageSourceCreateImageAtIndex(imageSource, i, NULL);
NSDictionary *frameProperties = (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(imageSource, i, NULL);
NSDictionary *frameGIFProperties = frameProperties[(id)kCGImagePropertyGIFDictionary];
const NSTimeInterval kDelayTimeIntervalDefault = 0.1;
NSNumber *delayTime = frameGIFProperties[(id)kCGImagePropertyGIFUnclampedDelayTime] ?: frameGIFProperties[(id)kCGImagePropertyGIFDelayTime];
if (delayTime == nil) {
if (i == 0) {
delayTime = @(kDelayTimeIntervalDefault);
} else {
delayTime = delays[i - 1];
}
}
const NSTimeInterval kDelayTimeIntervalMinimum = 0.02;
if (delayTime.floatValue < (float)kDelayTimeIntervalMinimum - FLT_EPSILON) {
delayTime = @(kDelayTimeIntervalDefault);
}
duration += delayTime.doubleValue;
delays[i] = delayTime;
images[i] = (__bridge_transfer id)image;
}
CFRelease(imageSource);
NSMutableArray *keyTimes = [NSMutableArray arrayWithCapacity:delays.count];
NSTimeInterval runningDuration = 0;
for (NSNumber *delayNumber in delays) {
[keyTimes addObject:@(runningDuration / duration)];
runningDuration += delayNumber.doubleValue;
}
[keyTimes addObject:@1.0];
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
animation.calculationMode = kCAAnimationDiscrete;
animation.repeatCount = loopCount == 0 ? HUGE_VALF : loopCount;
animation.keyTimes = keyTimes;
animation.values = images;
animation.duration = duration;
return animation;
}
+ (UIImage *)UIImage:(id)json
{
// TODO: we might as well cache the result of these checks (and possibly the
// image itself) so as to reduce overhead on subsequent checks of the same input
if (![json isKindOfClass:[NSString class]]) {
RCTLogError(@"Expected NSString for UIImage, received %@: %@", [json class], json);
return nil;
@@ -532,9 +452,8 @@ RCT_STRUCT_CONVERTER(CGAffineTransform, (@[@"a", @"b", @"c", @"d", @"tx", @"ty"]
image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:path ofType:nil]];
}
}
if (!image) {
RCTLogWarn(@"No image was found at path %@", json);
}
// NOTE: we don't warn about nil images because there are legitimate
// case where we find out if a string is an image by using this method
return image;
}

View File

@@ -1,10 +0,0 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, RCTPointerEvents) {
RCTPointerEventsUnspecified = 0, // Default
RCTPointerEventsNone,
RCTPointerEventsBoxNone,
RCTPointerEventsBoxOnly,
};

View File

@@ -1,18 +0,0 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#import <UIKit/UIKit.h>
/**
* Contains any methods related to scrolling. Any `RCTView` that has scrolling
* features should implement these methods.
*/
@protocol RCTScrollableProtocol
@property (nonatomic, readwrite, weak) NSObject<UIScrollViewDelegate> *nativeMainScrollDelegate;
@property (nonatomic, readonly) CGSize contentSize;
- (void)scrollToOffset:(CGPoint)offset;
- (void)scrollToOffset:(CGPoint)offset animated:(BOOL)animated;
- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated;
@end

View File

@@ -1,28 +0,0 @@
// Copyright 2004-present Facebook. All Rights Reserved.
/**
* Logical node in a tree of application components. Both `ShadowView`s and
* `UIView+ReactKit`s conform to this. Allows us to write utilities that
* reason about trees generally.
*/
@protocol RCTViewNodeProtocol <NSObject>
@property (nonatomic, copy) NSNumber *reactTag;
- (void)insertReactSubview:(id<RCTViewNodeProtocol>)subview atIndex:(NSInteger)atIndex;
- (void)removeReactSubview:(id<RCTViewNodeProtocol>)subview;
- (NSMutableArray *)reactSubviews;
- (NSNumber *)reactTagAtPoint:(CGPoint)point;
// View is an RCTRootView
- (BOOL)isReactRootView;
@optional
// TODO: Deprecate this
// This method is called after layout has been performed for all views known
// to the RCTViewManager. It is only called on UIViews, not shadow views.
- (void)reactBridgeDidFinishTransaction;
@end