More updates

This commit is contained in:
Alex Kotliarskyi 2015-07-27 12:24:01 -07:00
commit 9649e7cc8d
6 changed files with 54 additions and 42 deletions

View File

@ -109,17 +109,28 @@ var getPhotosReturnChecker = createStrictShapeTypeChecker({
}).isRequired, }).isRequired,
}); });
/**
* `CameraRoll` provides access to the local camera roll / gallery.
*/
class CameraRoll { class CameraRoll {
static GroupTypesOptions: Array<string>; static GroupTypesOptions: Array<string>;
static AssetTypeOptions: Array<string>; static AssetTypeOptions: Array<string>;
/** /**
* Saves the image with tag `tag` to the camera roll. * Saves the image to the camera roll / gallery.
* *
* @param {string} tag - Can be any of the three kinds of tags we accept: * @param {string} tag On Android, this is a local URI, such
* 1. URL * as `"file:///sdcard/img.png"`.
* 2. assets-library tag *
* 3. tag returned from storing an image in memory * On iOS, the tag can be one of the following:
*
* - local URI
* - assets-library tag
* - a tag not maching any of the above, which means the image data will
* be stored in memory (and consume memory as long as the process is alive)
*
* @param successCallback Invoked with the value of `tag` on success.
* @param errorCallback Invoked with error message on error.
*/ */
static saveImageWithTag(tag, successCallback, errorCallback) { static saveImageWithTag(tag, successCallback, errorCallback) {
invariant( invariant(
@ -140,10 +151,10 @@ class CameraRoll {
* Invokes `callback` with photo identifier objects from the local camera * Invokes `callback` with photo identifier objects from the local camera
* roll of the device matching shape defined by `getPhotosReturnChecker`. * roll of the device matching shape defined by `getPhotosReturnChecker`.
* *
* @param {object} params - See `getPhotosParamChecker`. * @param {object} params See `getPhotosParamChecker`.
* @param {function} callback - Invoked with arg of shape defined by * @param {function} callback Invoked with arg of shape defined by
* `getPhotosReturnChecker` on success. * `getPhotosReturnChecker` on success.
* @param {function} errorCallback - Invoked with error message on error. * @param {function} errorCallback Invoked with error message on error.
*/ */
static getPhotos(params, callback, errorCallback) { static getPhotos(params, callback, errorCallback) {
var metaCallback = callback; var metaCallback = callback;

View File

@ -24,6 +24,7 @@ var ImageStylePropTypes = {
borderColor: ReactPropTypes.string, borderColor: ReactPropTypes.string,
borderWidth: ReactPropTypes.number, borderWidth: ReactPropTypes.number,
borderRadius: ReactPropTypes.number, borderRadius: ReactPropTypes.number,
overflow: ReactPropTypes.oneOf(['visible', 'hidden']),
// iOS-Specific style to "tint" an image. // iOS-Specific style to "tint" an image.
// It changes the color of all the non-transparent pixels to the tintColor // It changes the color of all the non-transparent pixels to the tintColor

View File

@ -12,36 +12,33 @@
#import <objc/runtime.h> #import <objc/runtime.h>
static void *const RCTDownloadTaskWrapperCompletionBlockKey = (void *)&RCTDownloadTaskWrapperCompletionBlockKey; @interface NSObject (RCTDownloadTaskWrapper)
static void *const RCTDownloadTaskWrapperProgressBlockKey = (void *)&RCTDownloadTaskWrapperProgressBlockKey;
@interface NSURLSessionTask (RCTDownloadTaskWrapper) @property (nonatomic, copy) RCTDataCompletionBlock reactCompletionBlock;
@property (nonatomic, copy) RCTDataProgressBlock reactProgressBlock;
@property (nonatomic, copy, setter=rct_setCompletionBlock:) RCTDataCompletionBlock rct_completionBlock;
@property (nonatomic, copy, setter=rct_setProgressBlock:) RCTDataProgressBlock rct_progressBlock;
@end @end
@implementation NSURLSessionTask (RCTDownloadTaskWrapper) @implementation NSObject (RCTDownloadTaskWrapper)
- (RCTDataCompletionBlock)rct_completionBlock - (RCTDataCompletionBlock)reactCompletionBlock
{ {
return objc_getAssociatedObject(self, RCTDownloadTaskWrapperCompletionBlockKey); return objc_getAssociatedObject(self, _cmd);
} }
- (void)rct_setCompletionBlock:(RCTDataCompletionBlock)completionBlock - (void)setReactCompletionBlock:(RCTDataCompletionBlock)completionBlock
{ {
objc_setAssociatedObject(self, RCTDownloadTaskWrapperCompletionBlockKey, completionBlock, OBJC_ASSOCIATION_COPY_NONATOMIC); objc_setAssociatedObject(self, @selector(reactCompletionBlock), completionBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
} }
- (RCTDataProgressBlock)rct_progressBlock - (RCTDataProgressBlock)reactProgressBlock
{ {
return objc_getAssociatedObject(self, RCTDownloadTaskWrapperProgressBlockKey); return objc_getAssociatedObject(self, _cmd);
} }
- (void)rct_setProgressBlock:(RCTDataProgressBlock)progressBlock - (void)setReactProgressBlock:(RCTDataProgressBlock)progressBlock
{ {
objc_setAssociatedObject(self, RCTDownloadTaskWrapperProgressBlockKey, progressBlock, OBJC_ASSOCIATION_COPY_NONATOMIC); objc_setAssociatedObject(self, @selector(reactProgressBlock), progressBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
} }
@end @end
@ -63,9 +60,8 @@ static void *const RCTDownloadTaskWrapperProgressBlockKey = (void *)&RCTDownload
- (NSURLSessionDownloadTask *)downloadData:(NSURL *)url progressBlock:(RCTDataProgressBlock)progressBlock completionBlock:(RCTDataCompletionBlock)completionBlock - (NSURLSessionDownloadTask *)downloadData:(NSURL *)url progressBlock:(RCTDataProgressBlock)progressBlock completionBlock:(RCTDataCompletionBlock)completionBlock
{ {
NSURLSessionDownloadTask *task = [_URLSession downloadTaskWithURL:url]; NSURLSessionDownloadTask *task = [_URLSession downloadTaskWithURL:url];
task.rct_completionBlock = completionBlock; task.reactCompletionBlock = completionBlock;
task.rct_progressBlock = progressBlock; task.reactProgressBlock = progressBlock;
return task; return task;
} }
@ -73,28 +69,28 @@ static void *const RCTDownloadTaskWrapperProgressBlockKey = (void *)&RCTDownload
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
{ {
if (downloadTask.rct_completionBlock) { if (downloadTask.reactCompletionBlock) {
NSData *data = [NSData dataWithContentsOfURL:location]; NSData *data = [NSData dataWithContentsOfURL:location];
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
downloadTask.rct_completionBlock(downloadTask.response, data, nil); downloadTask.reactCompletionBlock(downloadTask.response, data, nil);
}); });
} }
} }
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)didWriteData totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite; - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)didWriteData totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite;
{ {
if (downloadTask.rct_progressBlock) { if (downloadTask.reactProgressBlock) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
downloadTask.rct_progressBlock(totalBytesWritten, totalBytesExpectedToWrite); downloadTask.reactProgressBlock(totalBytesWritten, totalBytesExpectedToWrite);
}); });
} }
} }
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
{ {
if (error && task.rct_completionBlock) { if (error && task.reactCompletionBlock) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
task.rct_completionBlock(nil, nil, error); task.reactCompletionBlock(nil, nil, error);
}); });
} }
} }

View File

@ -51,11 +51,6 @@ class StyleSheetValidation {
static addValidStylePropTypes(stylePropTypes) { static addValidStylePropTypes(stylePropTypes) {
for (var key in stylePropTypes) { for (var key in stylePropTypes) {
invariant(
allStylePropTypes[key] === undefined ||
allStylePropTypes[key] === stylePropTypes[key],
'Attemped to redefine existing style prop type "' + key + '".'
);
allStylePropTypes[key] = stylePropTypes[key]; allStylePropTypes[key] = stylePropTypes[key];
} }
} }

View File

@ -20,9 +20,11 @@ var Dimensions = require('Dimensions');
* *
* ### Displaying a line that's as thin as the device permits * ### Displaying a line that's as thin as the device permits
* *
* A width of 1 is actually pretty thick on an iPhone 4+, we can do one that's * A width of 1 is actually pretty thick on devices with high pixel density
* thinner using a width of `1 / PixelRatio.get()`. It's a technique that works * (such as iPhone 4+ and many Android devices), we can make one that's
* on all the devices independent of their pixel density. * thinner using a width of `1 / PixelRatio.get()`.
* It's a technique that works on all the devices independent of their
* pixel density.
* *
* ``` * ```
* style={{ borderWidth: 1 / PixelRatio.get() }} * style={{ borderWidth: 1 / PixelRatio.get() }}
@ -46,12 +48,18 @@ class PixelRatio {
/** /**
* Returns the device pixel density. Some examples: * Returns the device pixel density. Some examples:
* *
* - PixelRatio.get() === 1
* - mdpi Android devices (160 dpi)
* - PixelRatio.get() === 1.5
* - hdpi Android devices (240 dpi)
* - PixelRatio.get() === 2 * - PixelRatio.get() === 2
* - iPhone 4, 4S * - iPhone 4, 4S
* - iPhone 5, 5c, 5s * - iPhone 5, 5c, 5s
* - iPhone 6 * - iPhone 6
* - xhdpi Android devices (320 dpi)
* - PixelRatio.get() === 3 * - PixelRatio.get() === 3
* - iPhone 6 plus * - iPhone 6 plus
* - xxhdpi Android devices (480 dpi)
* - PixelRatio.get() === 3.5 * - PixelRatio.get() === 3.5
* - Nexus 6 * - Nexus 6
*/ */
@ -68,6 +76,7 @@ class PixelRatio {
* *
* Currently this is only implemented on Android and reflects the user preference set in * Currently this is only implemented on Android and reflects the user preference set in
* Settings > Display > Font size, on iOS it will always return the default pixel ratio. * Settings > Display > Font size, on iOS it will always return the default pixel ratio.
* @platform android
*/ */
static getFontScale(): number { static getFontScale(): number {
return Dimensions.get('window').fontScale || PixelRatio.get(); return Dimensions.get('window').fontScale || PixelRatio.get();

View File

@ -48,7 +48,7 @@
"dependencies": { "dependencies": {
"absolute-path": "0.0.0", "absolute-path": "0.0.0",
"babel": "5.4.3", "babel": "5.4.3",
"babel-core": "^5.6.4", "babel-core": "5.6.4",
"chalk": "^1.0.0", "chalk": "^1.0.0",
"connect": "2.8.3", "connect": "2.8.3",
"debug": "~2.1.0", "debug": "~2.1.0",