From c130931132291016111e780486220427fea4f0ae Mon Sep 17 00:00:00 2001 From: Ran Greenberg Date: Sun, 11 Oct 2020 14:07:01 +0300 Subject: [PATCH] Remove wix mentions in commnets in iOS files (#309) Remove Wix mentions --- LICENSE | 2 - README.md | 2 +- ReactNativeCameraKit.podspec | 2 +- .../project.pbxproj | 3 +- ios/lib/ReactNativeCameraKit/CKCamera.h | 8 - ios/lib/ReactNativeCameraKit/CKCamera.m | 232 +++++++++-------- .../ReactNativeCameraKit/CKCameraManager.h | 8 - .../ReactNativeCameraKit/CKCameraManager.m | 20 +- .../CKCameraOverlayView.h | 8 - .../CKCameraOverlayView.m | 48 ++-- .../ReactNativeCameraKit/CKCompressedImage.h | 8 - .../ReactNativeCameraKit/CKCompressedImage.m | 18 +- .../CKGalleryCollectionViewCell.h | 8 - .../CKGalleryCollectionViewCell.m | 120 +++++---- .../CKGalleryCustomCollectionViewCell.h | 8 - .../CKGalleryCustomCollectionViewCell.m | 16 +- .../ReactNativeCameraKit/CKGalleryManager.h | 8 - .../ReactNativeCameraKit/CKGalleryManager.m | 100 ++++---- .../CKGalleryViewManager.h | 8 - .../CKGalleryViewManager.m | 238 +++++++++--------- .../ReactNativeCameraKit/CKOverlayObject.h | 8 - .../ReactNativeCameraKit/CKOverlayObject.m | 18 +- ios/lib/ReactNativeCameraKit/GalleryData.h | 8 - ios/lib/ReactNativeCameraKit/GalleryData.m | 20 +- .../ReactNativeCameraKit/SelectionGesture.h | 8 - .../ReactNativeCameraKit/SelectionGesture.m | 8 - .../main/java/com/example/MainActivity.java | 1 - .../java/com/example/MainApplication.java | 2 +- package.json | 6 - 29 files changed, 380 insertions(+), 564 deletions(-) diff --git a/LICENSE b/LICENSE index 85e970c11c..d13cc4b26a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,5 @@ The MIT License (MIT) -Copyright (c) 2014 Wix.com - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights diff --git a/README.md b/README.md index c5fe76a3bb..783ed5dc32 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Then add to your app `app/build.gradle` in the `dependencies` section: Then in `MainApplication.java` add: ```diff -+ import com.wix.RNCameraKit.RNCameraKitPackage; ++ import com.rncamerakit.RNCameraKitPackage; ``` And in the package list in the same file (e.g. `getPackages`) add: diff --git a/ReactNativeCameraKit.podspec b/ReactNativeCameraKit.podspec index b5a5a19231..5fe9ecf630 100644 --- a/ReactNativeCameraKit.podspec +++ b/ReactNativeCameraKit.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.summary = "Advanced native camera and gallery controls and device photos API" s.license = "MIT" - s.authors = "Wix" + s.authors = "CameraKit" s.homepage = "https://github.com/wix/react-native-camera-kit" s.platform = :ios, "9.0" diff --git a/ios/lib/ReactNativeCameraKit.xcodeproj/project.pbxproj b/ios/lib/ReactNativeCameraKit.xcodeproj/project.pbxproj index 56065df428..3a99190d3b 100644 --- a/ios/lib/ReactNativeCameraKit.xcodeproj/project.pbxproj +++ b/ios/lib/ReactNativeCameraKit.xcodeproj/project.pbxproj @@ -159,7 +159,7 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 0730; - ORGANIZATIONNAME = Wix; + ORGANIZATIONNAME = ""; TargetAttributes = { 2646934D1CFB2A6B00F3A740 = { CreatedOnToolsVersion = 7.3; @@ -171,6 +171,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 264693451CFB2A6B00F3A740; diff --git a/ios/lib/ReactNativeCameraKit/CKCamera.h b/ios/lib/ReactNativeCameraKit/CKCamera.h index 9e3428a791..bee7264d4a 100644 --- a/ios/lib/ReactNativeCameraKit/CKCamera.h +++ b/ios/lib/ReactNativeCameraKit/CKCamera.h @@ -1,11 +1,3 @@ -// -// CKCamera.h -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 31/05/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import @import AVFoundation; diff --git a/ios/lib/ReactNativeCameraKit/CKCamera.m b/ios/lib/ReactNativeCameraKit/CKCamera.m index d0fc8d2c0e..91c0142bb1 100644 --- a/ios/lib/ReactNativeCameraKit/CKCamera.m +++ b/ios/lib/ReactNativeCameraKit/CKCamera.m @@ -1,11 +1,3 @@ -// -// CKCamera.m -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 31/05/2016. -// Copyright © 2016 Wix. All rights reserved. -// - @import Foundation; @import Photos; @@ -143,7 +135,7 @@ - (void)dealloc } -(PHFetchOptions *)fetchOptions { - + PHFetchOptions *fetchOptions = [PHFetchOptions new]; fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]]; fetchOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType = %d && creationDate <= %@",PHAssetMediaTypeImage, [NSDate date]]; @@ -151,7 +143,7 @@ -(PHFetchOptions *)fetchOptions { if ([fetchOptions respondsToSelector:@selector(fetchLimit)]) { fetchOptions.fetchLimit = 1; } - + return fetchOptions; } @@ -163,7 +155,7 @@ - (void)removeReactSubview:(UIView *)subview - (void)removeFromSuperview { - + dispatch_async( self.sessionQueue, ^{ if ( self.setupResult == CKSetupResultSuccess ) { [self.session stopRunning]; @@ -171,24 +163,24 @@ - (void)removeFromSuperview } } ); [super removeFromSuperview]; - + } - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; - + if (self){ // Create the AVCaptureSession. self.session = [[AVCaptureSession alloc] init]; // Fit camera preview inside of viewport self.session.sessionPreset = AVCaptureSessionPresetPhoto; - + // Communicate with the session and other session objects on this queue. self.sessionQueue = dispatch_queue_create( "session queue", DISPATCH_QUEUE_SERIAL ); - + [self handleCameraPermission]; - + #if !(TARGET_IPHONE_SIMULATOR) [self setupCaptureSession]; self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session]; @@ -201,55 +193,55 @@ - (instancetype)initWithFrame:(CGRect)frame { focusView.layer.borderWidth = 1; focusView.hidden = YES; self.focusView = focusView; - + [self addSubview:self.focusView]; - + // defualts self.zoomMode = CKCameraZoomModeOn; self.flashMode = CKCameraFlashModeAuto; self.focusMode = CKCameraFocushModeOn; } - + return self; } -(void)setCameraOptions:(NSDictionary *)cameraOptions { _cameraOptions = cameraOptions; - + // CAMERA_OPTION_FLASH_MODE id flashMode = self.cameraOptions[CAMERA_OPTION_FLASH_MODE]; if (flashMode) { self.flashMode = [RCTConvert CKCameraFlashMode:flashMode]; } - + // CAMERA_OPTION_FOCUS_MODE id focusMode = self.cameraOptions[CAMERA_OPTION_FOCUS_MODE]; if (focusMode) { self.focusMode = [RCTConvert CKCameraFocushMode:focusMode]; - + if (self.focusMode == CKCameraFocushModeOn) { UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(focusAndExposeTap:)]; [self addGestureRecognizer:tapGesture]; } } - + // CAMERA_OPTION_FOCUS_MODE id zoomMode = self.cameraOptions[CAMERA_OPTION_ZOOM_MODE]; if (zoomMode) { self.zoomMode = [RCTConvert CKCameraZoomMode:zoomMode]; - + if (self.zoomMode == CKCameraZoomModeOn) { UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchToZoomRecognizer:)]; [self addGestureRecognizer:pinchGesture]; } } - + // CAMERA_OPTION_CAMERA_RATIO_OVERLAY_COLOR id ratioOverlayColor = self.cameraOptions[CAMERA_OPTION_CAMERA_RATIO_OVERLAY_COLOR]; if (ratioOverlayColor) { self.ratioOverlayColor = [RCTConvert UIColor:ratioOverlayColor]; } - + // CAMERA_OPTION_CAMERA_RATIO_OVERLAY id ratioOverlay = self.cameraOptions[CAMERA_OPTION_CAMERA_RATIO_OVERLAY]; if (ratioOverlay) { @@ -274,15 +266,15 @@ -(void)setupCaptureSession { if ( self.setupResult != CKSetupResultSuccess ) { return; } - + self.backgroundRecordingID = UIBackgroundTaskInvalid; NSError *error = nil; - + AVCaptureDevice *videoDevice = [CKCamera deviceWithMediaType:AVMediaTypeVideo preferringPosition:AVCaptureDevicePositionBack]; AVCaptureDeviceInput *videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error]; - + [self.session beginConfiguration]; - + if ( [self.session canAddInput:videoDeviceInput] ) { [self.session addInput:videoDeviceInput]; self.videoDeviceInput = videoDeviceInput; @@ -291,7 +283,7 @@ -(void)setupCaptureSession { else { self.setupResult = CKSetupResultSessionConfigurationFailed; } - + AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init]; if ( [self.session canAddOutput:movieFileOutput] ) { [self.session addOutput:movieFileOutput]; @@ -304,7 +296,7 @@ -(void)setupCaptureSession { else { self.setupResult = CKSetupResultSessionConfigurationFailed; } - + AVCaptureStillImageOutput *stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; if ( [self.session canAddOutput:stillImageOutput] ) { stillImageOutput.outputSettings = @{AVVideoCodecKey : AVVideoCodecJPEG}; @@ -314,7 +306,7 @@ -(void)setupCaptureSession { else { self.setupResult = CKSetupResultSessionConfigurationFailed; } - + AVCaptureMetadataOutput * output = [[AVCaptureMetadataOutput alloc] init]; if ([self.session canAddOutput:output]) { self.metadataOutput = output; @@ -322,14 +314,14 @@ -(void)setupCaptureSession { [self.metadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; [self.metadataOutput setMetadataObjectTypes:[self.metadataOutput availableMetadataObjectTypes]]; } - + [self.session commitConfiguration]; } ); } -(void)handleCameraPermission { - + switch ( [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] ) { case AVAuthorizationStatusAuthorized: @@ -363,17 +355,17 @@ -(void)handleCameraPermission { -(void)reactSetFrame:(CGRect)frame { [super reactSetFrame:frame]; - + #if TARGET_IPHONE_SIMULATOR return; #endif - + self.previewLayer.frame = self.bounds; - - - + + + [self setOverlayRatioView]; - + dispatch_async( self.sessionQueue, ^{ switch ( self.setupResult ) { @@ -441,14 +433,14 @@ -(void)setOverlayRatioView { + (AVCaptureDevice *)deviceWithMediaType:(NSString *)mediaType preferringPosition:(AVCaptureDevicePosition)position { NSArray *devices = [AVCaptureDevice devicesWithMediaType:mediaType]; AVCaptureDevice *captureDevice = devices.firstObject; - + for (AVCaptureDevice *device in devices) { if (device.position == position) { captureDevice = device; break; } } - + return captureDevice; } @@ -502,7 +494,7 @@ - (void)setRatio:(NSString*)ratioString { - (void)snapStillImage:(NSDictionary*)options success:(CaptureBlock)onSuccess onError:(void (^)(NSString*))onError { dispatch_async( self.sessionQueue, ^{ AVCaptureConnection *connection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo]; - + UIImageOrientation imageOrientation = UIImageOrientationUp; switch([UIDevice currentDevice].orientation) { default: @@ -523,7 +515,7 @@ - (void)snapStillImage:(NSDictionary*)options success:(CaptureBlock)onSuccess on imageOrientation = UIImageOrientationRightMirrored; break; } - + // Capture a still image. [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:connection completionHandler:^( CMSampleBufferRef imageDataSampleBuffer, NSError *error ) { if (!imageDataSampleBuffer) { @@ -531,27 +523,27 @@ - (void)snapStillImage:(NSDictionary*)options success:(CaptureBlock)onSuccess on onError(@"Could not capture still image"); return; } - + // The sample buffer is not retained. Create image data before saving the still image to the photo library asynchronously. NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; UIImage *capturedImage = [UIImage imageWithData:imageData]; - + NSMutableDictionary *imageInfoDict = [[NSMutableDictionary alloc] init]; - + imageInfoDict[@"size"] = [NSNumber numberWithInteger:imageData.length]; - + if (capturedImage && [capturedImage isKindOfClass:[UIImage class]]) { imageInfoDict[@"width"] = [NSNumber numberWithDouble:capturedImage.size.width]; imageInfoDict[@"height"] = [NSNumber numberWithDouble:capturedImage.size.height]; } - + if (self.saveToCameraRoll) { [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { if (status != PHAuthorizationStatusAuthorized) { onError(@"Photo library permission is not authorized."); return; } - + // To preserve the metadata, we create an asset from the JPEG NSData representation. // Note that creating an asset from a UIImage discards the metadata. // In iOS 9, we can use -[PHAssetCreationRequest addResourceWithType:data:options]. @@ -563,16 +555,16 @@ - (void)snapStillImage:(NSDictionary*)options success:(CaptureBlock)onSuccess on onError(@"Photo library asset creation failed"); return; } - + // Get local identifier PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:self.fetchOptions]; PHAsset *firstAsset = [fetchResult firstObject]; NSString *localIdentifier = firstAsset.localIdentifier; - + if (localIdentifier) { imageInfoDict[@"id"] = localIdentifier; } - + // 'ph://' is a rnc/cameraroll URL scheme for loading PHAssets by localIdentifier // which are loaded via RNCAssetsLibraryRequestHandler module that conforms to RCTURLRequestHandler if (self.saveToCameraRollWithPhUrl) { @@ -585,14 +577,14 @@ - (void)snapStillImage:(NSDictionary*)options success:(CaptureBlock)onSuccess on [options setNetworkAccessAllowed:YES]; [firstAsset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput * _Nullable contentEditingInput, NSDictionary * _Nonnull info) { imageInfoDict[@"uri"] = contentEditingInput.fullSizeImageURL.absoluteString; - + dispatch_async(dispatch_get_main_queue(), ^{ onSuccess(imageInfoDict); }); }]; } - - + + }]; }]; } else { @@ -601,10 +593,10 @@ - (void)snapStillImage:(NSDictionary*)options success:(CaptureBlock)onSuccess on imageInfoDict[@"uri"] = temporaryFileURL.description; imageInfoDict[@"name"] = temporaryFileURL.lastPathComponent; } - + onSuccess(imageInfoDict); } - + [self resetFocus]; }]; }); @@ -616,12 +608,12 @@ -(void)changeCamera:(CallbackBlock)block NSLog(@"changeCamera isn't support on simulator"); return; #endif - + dispatch_async( self.sessionQueue, ^{ AVCaptureDevice *currentVideoDevice = self.videoDeviceInput.device; AVCaptureDevicePosition preferredPosition = AVCaptureDevicePositionUnspecified; AVCaptureDevicePosition currentPosition = currentVideoDevice.position; - + switch ( currentPosition ) { case AVCaptureDevicePositionUnspecified: @@ -632,42 +624,42 @@ -(void)changeCamera:(CallbackBlock)block preferredPosition = AVCaptureDevicePositionFront; break; } - + AVCaptureDevice *videoDevice = [CKCamera deviceWithMediaType:AVMediaTypeVideo preferringPosition:preferredPosition]; AVCaptureDeviceInput *videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil]; - + [self removeObservers]; [self.session beginConfiguration]; - + // Remove the existing device input first, since using the front and back camera simultaneously is not supported. [self.session removeInput:self.videoDeviceInput]; - + if ( [self.session canAddInput:videoDeviceInput] ) { [[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceSubjectAreaDidChangeNotification object:currentVideoDevice]; - + [CKCamera setFlashMode:self.flashMode forDevice:videoDevice]; - + [self.session addInput:videoDeviceInput]; self.videoDeviceInput = videoDeviceInput; } else { [self.session addInput:self.videoDeviceInput]; } - + AVCaptureConnection *connection = [self.movieFileOutput connectionWithMediaType:AVMediaTypeVideo]; if ( connection.isVideoStabilizationSupported ) { connection.preferredVideoStabilizationMode = AVCaptureVideoStabilizationModeAuto; } - + [self.session commitConfiguration]; [self addObservers]; - + dispatch_async( dispatch_get_main_queue(), ^{ - + if (block) { block(YES); } - + } ); } ); } @@ -676,10 +668,10 @@ +(NSURL*)saveToTmpFolder:(NSData*)data { NSString *temporaryFileName = [NSProcessInfo processInfo].globallyUniqueString; NSString *temporaryFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[temporaryFileName stringByAppendingPathExtension:@"jpg"]]; NSURL *temporaryFileURL = [NSURL fileURLWithPath:temporaryFilePath]; - + NSError *error = nil; [data writeToURL:temporaryFileURL options:NSDataWritingAtomic error:&error]; - + if (error) { NSLog(@"Error occured while writing image data to a temporary file: %@", error); } @@ -698,32 +690,32 @@ - (void)focusAndExposeTap:(UIGestureRecognizer *)gestureRecognizer { CGPoint touchPoint = [gestureRecognizer locationInView:self]; CGPoint devicePoint = [(AVCaptureVideoPreviewLayer *)self.previewLayer captureDevicePointOfInterestForPoint:touchPoint]; - + // Engage manual focus [self focusWithMode:AVCaptureFocusModeAutoFocus exposeWithMode:AVCaptureExposureModeAutoExpose atDevicePoint:devicePoint monitorSubjectAreaChange:YES]; - + // Disengage manual focus once focusing finishing (if focusTimeout > 0) // See [self observeValueForKeyPath] self.startFocusResetTimerAfterFocusing = YES; - + self.tapToFocusEngaged = YES; // Animate focus rectangle CGFloat halfDiagonal = 73; CGFloat halfDiagonalAnimation = halfDiagonal*2; - + CGRect focusViewFrame = CGRectMake(touchPoint.x - (halfDiagonal/2), touchPoint.y - (halfDiagonal/2), halfDiagonal, halfDiagonal); - + self.focusView.alpha = 0; self.focusView.hidden = NO; self.focusView.frame = CGRectMake(touchPoint.x - (halfDiagonalAnimation/2), touchPoint.y - (halfDiagonalAnimation/2), halfDiagonalAnimation, halfDiagonalAnimation); - + [UIView animateWithDuration:0.2 animations:^{ self.focusView.frame = focusViewFrame; self.focusView.alpha = 1; @@ -739,7 +731,7 @@ - (void)resetFocus [self.focusResetTimer invalidate]; self.focusResetTimer = nil; } - + // Resetting focus to continuous focus, so not interested in resetting anymore self.startFocusResetTimerAfterFocusing = NO; @@ -747,33 +739,33 @@ - (void)resetFocus if (!self.tapToFocusEngaged) { return; } - + self.tapToFocusEngaged = NO; - + // 1. Reset actual camera focus CGPoint deviceCenter = CGPointMake(0.5, 0.5); [self focusWithMode:AVCaptureFocusModeContinuousAutoFocus exposeWithMode:AVCaptureExposureModeContinuousAutoExposure atDevicePoint:deviceCenter monitorSubjectAreaChange:NO]; - + // 2. Create animation to indicate the new focus location CGPoint layerCenter = [self.previewLayer pointForCaptureDevicePointOfInterest:deviceCenter]; - + CGFloat halfDiagonal = 123; CGFloat halfDiagonalAnimation = halfDiagonal*2; - + CGRect focusViewFrame = CGRectMake(layerCenter.x - (halfDiagonal/2), layerCenter.y - (halfDiagonal/2), halfDiagonal, halfDiagonal); CGRect focusViewFrameForAnimation = CGRectMake(layerCenter.x - (halfDiagonalAnimation/2), layerCenter.y - (halfDiagonalAnimation/2), halfDiagonalAnimation, halfDiagonalAnimation); - + self.focusView.alpha = 0; self.focusView.hidden = NO; self.focusView.frame = focusViewFrameForAnimation; - + [UIView animateWithDuration:0.2 animations:^{ self.focusView.frame = focusViewFrame; self.focusView.alpha = 1; } completion:^(BOOL finished) { self.focusView.alpha = 1; self.focusView.frame = focusViewFrame; - + if (self.focusViewTimer) { [self.focusViewTimer invalidate]; } @@ -797,19 +789,19 @@ - (void)focusWithMode:(AVCaptureFocusMode)focusMode exposeWithMode:(AVCaptureExp NSLog(@"Unable to device.lockForConfiguration() %@", error); return; } - + // Setting (focus/exposure)PointOfInterest alone does not initiate a (focus/exposure) operation. // Call -set(Focus/Exposure)Mode: to apply the new point of interest. if ( device.isFocusPointOfInterestSupported && [device isFocusModeSupported:focusMode] ) { device.focusPointOfInterest = point; device.focusMode = focusMode; } - + if ( device.isExposurePointOfInterestSupported && [device isExposureModeSupported:exposureMode] ) { device.exposurePointOfInterest = point; device.exposureMode = exposureMode; } - + device.subjectAreaChangeMonitoringEnabled = monitorSubjectAreaChange && self.resetFocusWhenMotionDetected; [device unlockForConfiguration]; }); @@ -850,34 +842,34 @@ + (UIImage *)imageWithImage:(UIImage *)image scaledToRect:(CGSize)newSize { +(CGRect)cropRectForSize:(CGRect)frame overlayObject:(CKOverlayObject*)overlayObject { - + CGRect ans = CGRectZero; CGSize centerSize = CGSizeZero; - + if (overlayObject.width < overlayObject.height) { centerSize.width = frame.size.width; centerSize.height = frame.size.height * overlayObject.ratio; - + ans.origin.x = 0; ans.origin.y = (frame.size.height - centerSize.height)*0.5; - + } else if (overlayObject.width > overlayObject.height){ centerSize.width = frame.size.width / overlayObject.ratio; centerSize.height = frame.size.height; - + ans.origin.x = (frame.size.width - centerSize.width)*0.5; ans.origin.y = 0; - + } else { // ratio is 1:1 centerSize.width = frame.size.width; centerSize.height = frame.size.width; - + ans.origin.x = 0; ans.origin.y = (frame.size.height - centerSize.height)/2; } - + ans.size = centerSize; ans.origin.x += frame.origin.x; ans.origin.y += frame.origin.y; @@ -885,10 +877,10 @@ +(CGRect)cropRectForSize:(CGRect)frame overlayObject:(CKOverlayObject*)overlayOb } +(CGSize)cropImageToPreviewSize:(UIImage*)image size:(CGSize)previewSize { - + float imageToPreviewWidthScale = image.size.width/previewSize.width; float imageToPreviewHeightScale = image.size.width/previewSize.width; - + return CGSizeMake(previewSize.width*imageToPreviewWidthScale, previewSize.height*imageToPreviewHeightScale); } @@ -924,12 +916,12 @@ - (void)addFrameForScanner { self.dataReadingFrame.backgroundColor = [UIColor clearColor]; [self createCustomFramesForView:self.dataReadingFrame]; [self addSubview:self.dataReadingFrame]; - - + + [self startAnimatingScanner:self.dataReadingFrame]; - + [self addVisualEffects:self.dataReadingFrame.frame]; - + CGRect visibleRect = [self.previewLayer metadataOutputRectOfInterestForRect:self.dataReadingFrame.frame]; self.metadataOutput.rectOfInterest = visibleRect; } @@ -974,7 +966,7 @@ - (void)createCustomFramesForView:(UIView *)frameView { UIView * cornerView = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)]; cornerView.backgroundColor = self.frameColor; [frameView addSubview:cornerView]; - + } } @@ -982,20 +974,20 @@ - (void)addVisualEffects:(CGRect)inputRect { UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, inputRect.origin.y)]; topView.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.4]; [self addSubview:topView]; - + UIView *leftSideView = [[UIView alloc] initWithFrame:CGRectMake(0, inputRect.origin.y, self.frameOffset, self.heightFrame)]; //paddingForScanner scannerHeight leftSideView.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.4]; [self addSubview:leftSideView]; - + UIView *rightSideView = [[UIView alloc] initWithFrame:CGRectMake(inputRect.size.width + self.frameOffset, inputRect.origin.y, self.frameOffset, self.heightFrame)]; rightSideView.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.4]; [self addSubview:rightSideView]; - + UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, inputRect.origin.y + self.heightFrame, self.frame.size.width, self.frame.size.height - inputRect.origin.y - self.heightFrame)]; bottomView.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.4]; [self addSubview:bottomView]; - + } - (void)startAnimatingScanner:(UIView *)inputView { @@ -1032,11 +1024,11 @@ - (void)willEnterForeground:(NSNotification *)notification { - (void)addObservers { - + if (!self.isAddedOberver) { [self.session addObserver:self forKeyPath:@"running" options:NSKeyValueObservingOptionNew context:SessionRunningContext]; [self.stillImageOutput addObserver:self forKeyPath:@"capturingStillImage" options:NSKeyValueObservingOptionNew context:CapturingStillImageContext]; - + [self.videoDeviceInput.device addObserver:self forKeyPath:@"adjustingFocus" options:NSKeyValueObservingOptionNew context:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(subjectAreaDidChange:) name:AVCaptureDeviceSubjectAreaDidChangeNotification object:self.videoDeviceInput.device]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionRuntimeError:) name:AVCaptureSessionRuntimeErrorNotification object:self.session]; @@ -1053,7 +1045,7 @@ - (void)addObservers selector:@selector(willEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; - + self.isAddedOberver = YES; } } @@ -1069,12 +1061,12 @@ - (void)sessionWasInterrupted:(NSNotification *)notification // Note that stopping music playback in control center will not automatically resume the session running. // Also note that it is not always possible to resume, see -[resumeInterruptedSession:]. BOOL showResumeButton = NO; - + // In iOS 9 and later, the userInfo dictionary contains information on why the session was interrupted. if ( &AVCaptureSessionInterruptionReasonKey ) { AVCaptureSessionInterruptionReason reason = [notification.userInfo[AVCaptureSessionInterruptionReasonKey] integerValue]; //NSLog( @"Capture session was interrupted with reason %ld", (long)reason ); - + if ( reason == AVCaptureSessionInterruptionReasonAudioDeviceInUseByAnotherClient || reason == AVCaptureSessionInterruptionReasonVideoDeviceInUseByAnotherClient ) { showResumeButton = YES; @@ -1098,7 +1090,7 @@ - (void)sessionRuntimeError:(NSNotification *)notification { NSError *error = notification.userInfo[AVCaptureSessionErrorKey]; //NSLog( @"Capture session runtime error: %@", error ); - + // Automatically try to restart the session running if media services were reset and the last start running succeeded. // Otherwise, enable the user to try to resume the session running. if ( error.code == AVErrorMediaServicesWereReset ) { @@ -1142,7 +1134,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N if (self.startFocusResetTimerAfterFocusing == YES && !isFocusing && self.resetFocusTimeout > 0) { self.startFocusResetTimerAfterFocusing = NO; - + // Disengage manual focus after focusTimeout milliseconds NSTimeInterval focusTimeoutSeconds = self.resetFocusTimeout / 1000; self.focusResetTimer = [NSTimer scheduledTimerWithTimeInterval:focusTimeoutSeconds repeats:NO block:^(NSTimer *timer) { @@ -1172,11 +1164,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N - (void)captureOutput:(AVCaptureOutput *)output didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects fromConnection:(AVCaptureConnection *)connection { - + for(AVMetadataObject *metadataObject in metadataObjects) { if ([metadataObject isKindOfClass:[AVMetadataMachineReadableCodeObject class]] && [self isSupportedBarCodeType:metadataObject.type]) { - + AVMetadataMachineReadableCodeObject *code = (AVMetadataMachineReadableCodeObject*)[self.previewLayer transformedMetadataObjectForMetadataObject:metadataObject]; if (self.onReadCode && code.stringValue && ![code.stringValue isEqualToString:self.codeStringValue]) { self.onReadCode(@{@"codeStringValue": code.stringValue}); diff --git a/ios/lib/ReactNativeCameraKit/CKCameraManager.h b/ios/lib/ReactNativeCameraKit/CKCameraManager.h index eb3ae88d3a..304dfd3b95 100644 --- a/ios/lib/ReactNativeCameraKit/CKCameraManager.h +++ b/ios/lib/ReactNativeCameraKit/CKCameraManager.h @@ -1,11 +1,3 @@ -// -// CKCameraManager.h -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 30/05/2016. -// Copyright © 2016 Wix. All rights reserved. -// - @import AVFoundation; #if __has_include() diff --git a/ios/lib/ReactNativeCameraKit/CKCameraManager.m b/ios/lib/ReactNativeCameraKit/CKCameraManager.m index ad859d1025..1ee940c83a 100644 --- a/ios/lib/ReactNativeCameraKit/CKCameraManager.m +++ b/ios/lib/ReactNativeCameraKit/CKCameraManager.m @@ -1,11 +1,3 @@ -// -// CKCameraManager.m -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 30/05/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import "CKCameraManager.h" #import "CKCamera.h" @@ -38,7 +30,7 @@ - (UIView *)view { RCT_EXPORT_METHOD(checkDeviceCameraAuthorizationStatus:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject) { - + AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if(authStatus == AVAuthorizationStatusAuthorized) { resolve(@YES); @@ -52,7 +44,7 @@ - (UIView *)view { RCT_EXPORT_METHOD(requestDeviceCameraAuthorization:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject) { __block NSString *mediaType = AVMediaTypeVideo; - + [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) { if (resolve) { resolve(@(granted)); @@ -64,7 +56,7 @@ - (UIView *)view { RCT_EXPORT_METHOD(capture:(NSDictionary*)options resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) { - + [self.camera snapStillImage:options success:^(NSDictionary *imageObject) { resolve(imageObject); } onError:^(NSString* error) { @@ -74,7 +66,7 @@ - (UIView *)view { RCT_EXPORT_METHOD(changeCamera:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) { - + [self.camera changeCamera:^(BOOL success) { if (success) { resolve([NSNumber numberWithBool:success]); @@ -87,7 +79,7 @@ - (UIView *)view { RCT_EXPORT_METHOD(setFlashMode:(CKCameraFlashMode)flashMode resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) { - + [self.camera setFlashMode:flashMode callback:^(BOOL success) { resolve([NSNumber numberWithBool:success]); }]; @@ -96,7 +88,7 @@ - (UIView *)view { RCT_EXPORT_METHOD(setTorchMode:(CKCameraTorchMode)torchMode resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) { - + [self.camera setTorchMode:torchMode callback:^(BOOL success) { resolve([NSNumber numberWithBool:success]); }]; diff --git a/ios/lib/ReactNativeCameraKit/CKCameraOverlayView.h b/ios/lib/ReactNativeCameraKit/CKCameraOverlayView.h index 40c8f5133e..034e5af3cf 100644 --- a/ios/lib/ReactNativeCameraKit/CKCameraOverlayView.h +++ b/ios/lib/ReactNativeCameraKit/CKCameraOverlayView.h @@ -1,11 +1,3 @@ -// -// CKCameraOverlayView.h -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 17/07/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import #import "CKOverlayObject.h" diff --git a/ios/lib/ReactNativeCameraKit/CKCameraOverlayView.m b/ios/lib/ReactNativeCameraKit/CKCameraOverlayView.m index bd83db8524..4f99afbcba 100644 --- a/ios/lib/ReactNativeCameraKit/CKCameraOverlayView.m +++ b/ios/lib/ReactNativeCameraKit/CKCameraOverlayView.m @@ -1,11 +1,3 @@ -// -// CKCameraOverlayView.m -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 17/07/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import "CKCameraOverlayView.h" @@ -24,47 +16,47 @@ @implementation CKCameraOverlayView -(instancetype)initWithFrame:(CGRect)frame ratioString:(NSString*)ratioString overlayColor:(UIColor*)overlayColor { - + self = [super initWithFrame:frame]; - + if (self) { - + self.overlayObject = [[CKOverlayObject alloc] initWithString:ratioString]; self.topView = [[UIView alloc] initWithFrame:CGRectZero]; self.centerView = [[UIView alloc] initWithFrame:CGRectZero]; self.bottomView = [[UIView alloc] initWithFrame:CGRectZero]; - + overlayColor = overlayColor ? overlayColor : [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3]; - + self.topView.backgroundColor = overlayColor; self.bottomView.backgroundColor = overlayColor; - + [self addSubview:self.topView]; [self addSubview:self.centerView]; [self addSubview:self.bottomView]; - + [self setOverlayParts]; } - + return self; } -(void)setOverlayParts { - + if (self.overlayObject.ratio == 0) return; - + CGSize centerSize = CGSizeZero; CGSize sideSize = CGSizeZero; - + if (self.overlayObject.width < self.overlayObject.height) { - + centerSize.width = self.frame.size.width; centerSize.height = self.frame.size.height * self.overlayObject.ratio; - + sideSize.width = centerSize.width; sideSize.height = (self.frame.size.height - centerSize.height)/2.0; - + self.topView.frame = CGRectMake(0, 0, sideSize.width, sideSize.height); self.centerView.frame = CGRectMake(0, self.topView.frame.size.height + self.topView.frame.origin.y, centerSize.width, centerSize.height); self.bottomView.frame = CGRectMake(0, self.centerView.frame.size.height + self.centerView.frame.origin.y, sideSize.width, sideSize.height); @@ -72,10 +64,10 @@ -(void)setOverlayParts { else if (self.overlayObject.width > self.overlayObject.height){ centerSize.width = self.frame.size.width / self.overlayObject.ratio; centerSize.height = self.frame.size.height; - + sideSize.width = (self.frame.size.width - centerSize.width)/2.0; sideSize.height = centerSize.height; - + self.topView.frame = CGRectMake(0, 0, sideSize.width, sideSize.height); self.centerView.frame = CGRectMake(self.topView.frame.size.width + self.topView.frame.origin.x, 0, centerSize.width, centerSize.height); self.bottomView.frame = CGRectMake(self.centerView.frame.size.width + self.centerView.frame.origin.x, 0, sideSize.width, sideSize.height); @@ -83,10 +75,10 @@ -(void)setOverlayParts { else { // ratio is 1:1 centerSize.width = self.frame.size.width; centerSize.height = self.frame.size.width; - + sideSize.width = centerSize.width; sideSize.height = (self.frame.size.height - centerSize.height)/2.0; - + self.topView.frame = CGRectMake(0, 0, sideSize.width, sideSize.height); self.centerView.frame = CGRectMake(0, self.topView.frame.size.height + self.topView.frame.origin.y, centerSize.width, centerSize.height); self.bottomView.frame = CGRectMake(0, self.centerView.frame.size.height + self.centerView.frame.origin.y, sideSize.width, sideSize.height); @@ -96,12 +88,12 @@ -(void)setOverlayParts { -(void)setRatio:(NSString*)ratioString { self.overlayObject = [[CKOverlayObject alloc] initWithString:ratioString]; - + // self.alpha =0; [UIView animateWithDuration:0.2 animations:^{ [self setOverlayParts]; } completion:nil]; - + } diff --git a/ios/lib/ReactNativeCameraKit/CKCompressedImage.h b/ios/lib/ReactNativeCameraKit/CKCompressedImage.h index 958c02b1ee..311fd453bd 100644 --- a/ios/lib/ReactNativeCameraKit/CKCompressedImage.h +++ b/ios/lib/ReactNativeCameraKit/CKCompressedImage.h @@ -1,11 +1,3 @@ -// -// CKCompressedImage.h -// ReactNativeCameraKit -// -// Created by Sergey Ilyevsky on 15/05/2017. -// Copyright © 2017 Wix. All rights reserved. -// - #import @interface CKCompressedImage : NSObject diff --git a/ios/lib/ReactNativeCameraKit/CKCompressedImage.m b/ios/lib/ReactNativeCameraKit/CKCompressedImage.m index f4fa1f69c5..a453160887 100644 --- a/ios/lib/ReactNativeCameraKit/CKCompressedImage.m +++ b/ios/lib/ReactNativeCameraKit/CKCompressedImage.m @@ -1,11 +1,3 @@ -// -// CKCompressedImage.m -// ReactNativeCameraKit -// -// Created by Sergey Ilyevsky on 15/05/2017. -// Copyright © 2017 Wix. All rights reserved. -// - #import "CKCompressedImage.h" @implementation CKCompressedImage @@ -26,13 +18,13 @@ - (instancetype)initWithImage:(UIImage *)image imageQuality:(NSString*)imageQual } float actualHeight = image.size.height; float actualWidth = image.size.width; - + float imgRatio = actualWidth/actualHeight; - + float newHeight = (actualHeight > actualWidth) ? max : max/imgRatio; float newWidth = (actualHeight > actualWidth) ? max*imgRatio : max; - - + + CGRect rect = CGRectMake(0.0, 0.0, newWidth, newHeight); UIGraphicsBeginImageContext(rect.size); [image drawInRect:rect]; @@ -40,7 +32,7 @@ - (instancetype)initWithImage:(UIImage *)image imageQuality:(NSString*)imageQual UIGraphicsEndImageContext(); _data = UIImageJPEGRepresentation(_image, 0.85f); } - + return self; } diff --git a/ios/lib/ReactNativeCameraKit/CKGalleryCollectionViewCell.h b/ios/lib/ReactNativeCameraKit/CKGalleryCollectionViewCell.h index f3bd1323e7..d33aa2f30f 100644 --- a/ios/lib/ReactNativeCameraKit/CKGalleryCollectionViewCell.h +++ b/ios/lib/ReactNativeCameraKit/CKGalleryCollectionViewCell.h @@ -1,11 +1,3 @@ -// -// CKGalleryCollectionViewCell.h -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 20/06/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import #define SUPPORTED_FILE_TYPES @"supportedFileTypes" diff --git a/ios/lib/ReactNativeCameraKit/CKGalleryCollectionViewCell.m b/ios/lib/ReactNativeCameraKit/CKGalleryCollectionViewCell.m index 99690e7ae4..4865decb59 100644 --- a/ios/lib/ReactNativeCameraKit/CKGalleryCollectionViewCell.m +++ b/ios/lib/ReactNativeCameraKit/CKGalleryCollectionViewCell.m @@ -1,11 +1,3 @@ -// -// CKGalleryCollectionViewCell.m -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 20/06/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #if __has_include() #import #else @@ -123,7 +115,7 @@ -(UIActivityIndicatorView*)spinner { if (remoteDownloadIndicatorColor) { [_spinner setColor:remoteDownloadIndicatorColor]; } - + } return _spinner; } @@ -142,7 +134,7 @@ -(UIProgressView*)progressView { } -(M13ProgressViewPie *)progressPieView { - + if (!_progressPieView) { CGRect frame = CGRectMake(0, 0, self.bounds.size.width/3, self.bounds.size.height/3); _progressPieView = [[M13ProgressViewPie alloc] initWithFrame:frame]; @@ -151,11 +143,11 @@ -(M13ProgressViewPie *)progressPieView { _progressPieView.primaryColor = [UIColor whiteColor]; _progressPieView.animationDuration = 0.1; [_progressPieView setProgress:0 animated:NO]; - + if (remoteDownloadIndicatorColor) { _progressPieView.secondaryColor = remoteDownloadIndicatorColor; _progressPieView.primaryColor = remoteDownloadIndicatorColor; - + } } return _progressPieView; @@ -166,9 +158,9 @@ -(M13ProgressViewPie *)progressPieView { -(instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; - + CGRect imageViewFrame = self.bounds; - + if(imageStrokeColor) { if (imageStrokeColorWidth && imageStrokeColorWidth.floatValue > 0) { imageViewFrame.size.height -= imageStrokeColorWidth.floatValue; @@ -176,35 +168,35 @@ -(instancetype)initWithFrame:(CGRect)frame { } self.backgroundColor = imageStrokeColor; } - + self.imageView = [[UIImageView alloc] initWithFrame:imageViewFrame]; self.imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.imageView.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); self.imageView.backgroundColor = [UIColor clearColor]; self.imageView.contentMode = UIViewContentModeScaleAspectFill; self.imageView.clipsToBounds = YES; - + [self addSubview:self.imageView]; - + self.imageOveray = [[UIView alloc] initWithFrame:self.imageView.bounds]; self.imageOveray.opaque = NO; self.imageOveray.backgroundColor = [UIColor clearColor]; - + [self.imageView addSubview:self.imageOveray]; - + self.badgeImageView = [[UIImageView alloc] init]; [self addSubview:self.badgeImageView]; - + self.isSupported = YES; - - + + self.gesture = [[SelectionGesture alloc] initWithTarget:self action:@selector(handleGesture:)]; [self addGestureRecognizer:self.gesture]; self.gesture.cancelsTouchesInView = NO; self.gesture.delegate = self; - + [self applyStyleOnInit]; - + return self; } @@ -213,29 +205,29 @@ -(void)applyStyleOnInit { if(selectedImageIconProp) { selectedImageIcon = [RCTConvert UIImage:selectedImageIconProp]; } - + id unselectedImageIconProp = selection[SELECTION_UNSELECTED_IMAGE]; if(unselectedImageIconProp) { unSelectedImageIcon = [RCTConvert UIImage:unselectedImageIconProp]; } - + id overlayColorProp = selection[SELECTION_OVERLAY_COLOR]; if(overlayColorProp) { selectionOverlayColor = [RCTConvert UIColor:overlayColorProp]; } - + } -(CGRect)frameforImagePosition:(NSString*)position image:(UIImage*)image { CGRect badgeRect; - - + + CGSize badgeImageSize = image.size; CGFloat aspectRatio = badgeImageSize.width/badgeImageSize.height; badgeImageSize.width = MIN(badgeImageSize.width, self.bounds.size.width/4); badgeImageSize.height = badgeImageSize.width/aspectRatio; - - + + if ([position isEqualToString:@"top-right"]) { badgeRect= CGRectMake(self.imageView.bounds.size.width - (badgeImageSize.width + BADGE_MARGIN), BADGE_MARGIN, badgeImageSize.width, badgeImageSize.height); } @@ -254,9 +246,9 @@ -(CGRect)frameforImagePosition:(NSString*)position image:(UIImage*)image { else { badgeRect = CGRectZero; } - + return badgeRect; - + } -(void)updateBadgeImageViewFrame { @@ -266,7 +258,7 @@ -(void)updateBadgeImageViewFrame { if (!CGRectIsEmpty(badgeRect)) { self.badgeImageView.frame = badgeRect; }; - + } - (void)prepareForReuse { @@ -276,16 +268,16 @@ - (void)prepareForReuse { _isDownloading = NO; self.isSupported = YES; self.gesture.enabled = YES; - + [self.unsupportedView removeFromSuperview]; self.unsupportedView = nil; - + [_spinner removeFromSuperview]; _spinner = nil; - + [_progressBarView removeFromSuperview]; _progressBarView = nil; - + [_progressPieView removeFromSuperview]; _progressPieView = nil; } @@ -298,33 +290,33 @@ - (void)setThumbnailImage:(UIImage *)thumbnailImage { -(void)setIsSupported:(BOOL)isSupported { _isSupported = isSupported; - + if (!_isSupported) { if (supported) { - + UIImageView *imageView; UILabel *unsupportedLabel; - + self.unsupportedView = [[UIView alloc] initWithFrame:self.bounds]; - + UIColor *overlayColor = supported[UNSUPPORTED_OVERLAY_COLOR]; if (overlayColor) { self.unsupportedView.backgroundColor = overlayColor; } - + UIImage *unsupportedImage = supported[UNSUPPORTED_IMAGE]; if (unsupportedImage) { CGRect imageViewFrame = self.unsupportedView.bounds; imageViewFrame.size.height = self.unsupportedView.bounds.size.height/4*2; imageViewFrame.origin.y = self.unsupportedView.bounds.size.height/4 - (imageViewFrame.size.height/6); - + imageView = [[UIImageView alloc] initWithImage:unsupportedImage]; imageView.frame = imageViewFrame; imageView.contentMode = UIViewContentModeScaleAspectFit; [self.unsupportedView addSubview:imageView]; } - - + + NSString *unsupportedText = supported[UNSUPPORTED_TEXT]; if (unsupportedText) { CGRect labelFrame = self.unsupportedView.bounds; @@ -336,27 +328,27 @@ -(void)setIsSupported:(BOOL)isSupported { unsupportedLabel = [[UILabel alloc] initWithFrame:labelFrame]; unsupportedLabel.text = unsupportedText; unsupportedLabel.textAlignment = NSTextAlignmentCenter; - + UIColor *unsupportedTextColor = supported[UNSUPPORTED_TEXT_COLOR]; if (unsupportedTextColor) { unsupportedLabel.textColor = unsupportedTextColor; } - + [self.unsupportedView addSubview:unsupportedLabel]; } - + [self addSubview:self.unsupportedView]; [self.badgeImageView removeFromSuperview]; self.gesture.enabled = NO; } } - + else { [self.unsupportedView removeFromSuperview]; self.unsupportedView = nil; [self addSubview:self.badgeImageView]; self.gesture.enabled = YES; - + } } @@ -365,7 +357,7 @@ -(void)setSelectedOverLay:(BOOL)shouldShowOverlayColor forceOverlay:(BOOL)force{ self.imageOveray.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5]; return; } - + if (shouldShowOverlayColor) { self.imageOveray.backgroundColor = selectionOverlayColor ? selectionOverlayColor : [[UIColor whiteColor] colorWithAlphaComponent:0.5]; } @@ -376,13 +368,13 @@ -(void)setSelectedOverLay:(BOOL)shouldShowOverlayColor forceOverlay:(BOOL)force{ -(void)setIsSelected:(BOOL)isSelected { - + _isSelected = isSelected; - + if (self.disableSelectionIcons) return; - + [self setSelectedOverLay:isSelected forceOverlay:NO]; - + if (_isSelected) { if (selectedImageIcon) { double frameDuration = 1.0/2.0; // 4 = number of keyframes @@ -390,13 +382,13 @@ -(void)setIsSelected:(BOOL)isSelected { [self updateBadgeImageViewFrame]; self.badgeImageView.transform = CGAffineTransformMakeScale(0.5, 0.5); [UIView animateKeyframesWithDuration:0.2 delay:0 options:0 animations:^{ - + [UIView addKeyframeWithRelativeStartTime:0*frameDuration relativeDuration:frameDuration animations:^{ self.badgeImageView.transform = CGAffineTransformIdentity; }]; - + } completion:nil]; - + } else { self.badgeImageView.backgroundColor = UIColorFromRGB(BADGE_COLOR); @@ -421,14 +413,14 @@ -(void)setIsDownloading:(BOOL)isDownloading { -(void)setDownloadingProgress:(CGFloat)downloadingProgress { _downloadingProgress = downloadingProgress; - + if ([remoteDownloadIndicatorType isEqualToString:REMOTE_DOWNLOAD_INDICATOR_TYPE_PROGRESS_BAR]) { self.progressView.progress = downloadingProgress; } else if ([remoteDownloadIndicatorType isEqualToString:REMOTE_DOWNLOAD_INDICATOR_TYPE_PROGRESS_PIE]) { [self.progressPieView setProgress:downloadingProgress animated:YES]; } - + [self updateRemoteDownload]; } @@ -448,7 +440,7 @@ -(void)updateRemoteDownload { } } } - + else { [UIView animateWithDuration:0.5 delay:1 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ self.progressPieView.alpha = 0; @@ -463,10 +455,10 @@ -(void)updateRemoteDownload { -(void)removeRemoteDownloadIndicator { [_spinner removeFromSuperview]; _spinner = nil; - + [_progressBarView removeFromSuperview]; _progressBarView = nil; - + [_progressPieView removeFromSuperview]; _progressPieView = nil; } diff --git a/ios/lib/ReactNativeCameraKit/CKGalleryCustomCollectionViewCell.h b/ios/lib/ReactNativeCameraKit/CKGalleryCustomCollectionViewCell.h index 7dd4d027ab..0973132663 100644 --- a/ios/lib/ReactNativeCameraKit/CKGalleryCustomCollectionViewCell.h +++ b/ios/lib/ReactNativeCameraKit/CKGalleryCustomCollectionViewCell.h @@ -1,11 +1,3 @@ -// -// CKGalleryCustomCellCollectionViewCell.h -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 28/02/2017. -// Copyright © 2017 Wix. All rights reserved. -// - #import #if __has_include() diff --git a/ios/lib/ReactNativeCameraKit/CKGalleryCustomCollectionViewCell.m b/ios/lib/ReactNativeCameraKit/CKGalleryCustomCollectionViewCell.m index cc3a26c9a0..e44b90633c 100644 --- a/ios/lib/ReactNativeCameraKit/CKGalleryCustomCollectionViewCell.m +++ b/ios/lib/ReactNativeCameraKit/CKGalleryCustomCollectionViewCell.m @@ -1,11 +1,3 @@ -// -// CKGalleryCustomCellCollectionViewCell.m -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 28/02/2017. -// Copyright © 2017 Wix. All rights reserved. -// - #import "CKGalleryCustomCollectionViewCell.h" #if __has_include() @@ -38,7 +30,7 @@ @implementation CKGalleryCustomCollectionViewCell -(void) applyStyle:(NSDictionary*)styleDict { - + if (styleDict[CUSOM_BUTTON_COMPONENT]) { if (!_componentRootView) { _componentRootView = [[RCTRootView alloc] initWithBridge:self.bridge moduleName:styleDict[CUSOM_BUTTON_COMPONENT] initialProperties:nil]; @@ -51,7 +43,7 @@ -(void) applyStyle:(NSDictionary*)styleDict { _componentRootView.frame = self.bounds; } } - + if (_componentRootView == nil) { id imageProps = styleDict[CUSOM_BUTTON_IMAGE]; if (imageProps) { @@ -68,14 +60,14 @@ -(void) applyStyle:(NSDictionary*)styleDict { _imageView.image = image; } } - + id backgroundColorProps = styleDict[CUSOM_BUTTON_BACKGROUND_COLOR]; if (backgroundColorProps) { UIColor *backgroundColor = [RCTConvert UIColor:backgroundColorProps]; self.backgroundColor = backgroundColor; } } - + _prevStyleDict = styleDict; } diff --git a/ios/lib/ReactNativeCameraKit/CKGalleryManager.h b/ios/lib/ReactNativeCameraKit/CKGalleryManager.h index 3e8dd00a6f..ffb5e46d4f 100644 --- a/ios/lib/ReactNativeCameraKit/CKGalleryManager.h +++ b/ios/lib/ReactNativeCameraKit/CKGalleryManager.h @@ -1,11 +1,3 @@ -// -// CKGallery.h -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 30/05/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import #import diff --git a/ios/lib/ReactNativeCameraKit/CKGalleryManager.m b/ios/lib/ReactNativeCameraKit/CKGalleryManager.m index 70595380c5..4b5263403d 100644 --- a/ios/lib/ReactNativeCameraKit/CKGalleryManager.m +++ b/ios/lib/ReactNativeCameraKit/CKGalleryManager.m @@ -1,11 +1,3 @@ -// -// CKGallery.m -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 30/05/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #if __has_include() #import #else @@ -69,7 +61,7 @@ -(void)extractCollection:(id)collection imageRequestOptions:(PHImageRequestOptions*)options thumbnailSize:(CGSize)thumbnailSize block:(AlbumsBlock)block { - + NSInteger collectionCount; if ([collection isKindOfClass:[PHAssetCollection class]]) { collectionCount = [PHAsset fetchAssetsInAssetCollection:collection options:nil].count; @@ -80,34 +72,34 @@ -(void)extractCollection:(id)collection else { collectionCount = 0; } - + if (collectionCount > 0){ - + NSString *albumName = ([collection isKindOfClass:[PHAssetCollection class]]) ? ((PHAssetCollection*)collection).localizedTitle : @"All photos"; PHFetchResult *fetchResult = ([collection isKindOfClass:[PHAssetCollection class]]) ? [PHAsset fetchKeyAssetsInAssetCollection:collection options:nil] : (PHAssetCollection*)collection; PHAsset *thumbnail = [fetchResult firstObject]; - + NSMutableDictionary *albumInfo = [[NSMutableDictionary alloc] init]; albumInfo[@"albumName"] = albumName; albumInfo[@"imagesCount"] = [NSNumber numberWithInteger:collectionCount]; - + [[PHImageManager defaultManager] requestImageForAsset:thumbnail targetSize:thumbnailSize contentMode:PHImageContentModeAspectFit options:options resultHandler:^(UIImage *result, NSDictionary *info) { - + if (!albumInfo[@"image"]) { albumInfo[@"image"] = [UIImageJPEGRepresentation(result, 1.0) base64Encoding]; } - + if (block) { block(albumInfo); } }]; } - + else { if (block) { block(nil); @@ -120,25 +112,25 @@ -(void)extractCollectionsDetails:(PHFetchResult*)collections imageRequestOptions:(PHImageRequestOptions*)options thumbnailSize:(CGSize)thumbnailSize block:(AlbumsBlock)block { - + NSMutableArray *albumsArray = [[NSMutableArray alloc] init]; NSInteger collectionCount = collections.count; - + if (collectionCount == 0) { if (block) { block(nil); } } - + [collections enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL * _Nonnull stop) { - + [self extractCollection:collection imageRequestOptions:options thumbnailSize:thumbnailSize block:^(NSDictionary *album) { - + NSString *albumName = collection.localizedTitle; if (album) { [albumsArray addObject:album]; } - + if (idx == collectionCount-1) { if (block) { block(@{@"albums" : albumsArray}); @@ -151,37 +143,37 @@ -(void)extractCollectionsDetails:(PHFetchResult*)collections RCT_EXPORT_METHOD(getAlbumsWithThumbnails:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) { - + PHImageRequestOptions *imageRequestOptions = [[PHImageRequestOptions alloc] init]; imageRequestOptions.resizeMode = PHImageRequestOptionsResizeModeExact; imageRequestOptions.synchronous = YES; NSInteger retinaScale = [UIScreen mainScreen].scale; CGSize retinaSquare = CGSizeMake(100*retinaScale, 100*retinaScale); - + __block NSMutableArray *albumsArray = [[NSMutableArray alloc] init]; - + [self extractCollectionsDetails:self.topLevelUserCollections imageRequestOptions:imageRequestOptions thumbnailSize:retinaSquare block:^(NSDictionary *albums) { - + [self extractCollection:self.allPhotos imageRequestOptions:imageRequestOptions thumbnailSize:retinaSquare block:^(NSDictionary *allPhotosAlbum) { - - + + if (resolve) { NSMutableArray *albumsArrayAns = [[NSMutableArray alloc] init];; - + if(albums[@"albums"]) { [albumsArrayAns addObjectsFromArray:albums[@"albums"]]; } if(allPhotosAlbum) { [albumsArrayAns insertObject:allPhotosAlbum atIndex:0]; } - + if (!albumsArrayAns || albumsArrayAns.count == 0) { NSError *error = [[NSError alloc] initWithDomain:NSCocoaErrorDomain code:-100 userInfo:nil]; - + reject(@"-100", @"no albums", error); } else { @@ -206,7 +198,7 @@ -(void)extractCollectionsDetails:(PHFetchResult*)collections imageQuality:(NSString*)imageQuality resolve:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject) { - + [self imagesForIds:imagesIdArray imageQuality:imageQuality resolve:resolve reject:reject]; } @@ -214,22 +206,22 @@ -(void)extractCollectionsDetails:(PHFetchResult*)collections quality:(NSString*)quality resolve:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject) { - + NSMutableDictionary *ans = [NSMutableDictionary dictionaryWithDictionary:image]; - + NSString *imageUrlString = image[@"uri"]; if (imageUrlString) { - + NSURL *url = [NSURL URLWithString:imageUrlString]; if (!url) { resolve(nil); } NSData *data = [NSData dataWithContentsOfURL:url]; - + UIImage *originalImage = [UIImage imageWithData:data]; CKCompressedImage *compressedImage = [[CKCompressedImage alloc] initWithImage:originalImage imageQuality:quality]; - - + + NSURL *temporaryFileURL = [CKCamera saveToTmpFolder:compressedImage.data]; if (temporaryFileURL) { ans[@"uri"] = temporaryFileURL.description; @@ -247,28 +239,28 @@ -(void)imagesForIds:(NSArray*)imagesIdArray imageQuality:(NSString*)imageQuality resolve:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject { - + if (!imagesIdArray || ![imagesIdArray isKindOfClass:[NSArray class]] || imagesIdArray.count <= 0 ) { resolve(@{@"images": @[]}); return; } - + NSMutableArray *assetsArray = [[NSMutableArray alloc] initWithArray:imagesIdArray]; - + PHImageRequestOptions *imageRequestOptions = [[PHImageRequestOptions alloc] init]; imageRequestOptions.synchronous = YES; - + PHFetchResult *assets = [PHAsset fetchAssetsWithLocalIdentifiers:imagesIdArray options:nil]; - + for (PHAsset *asset in assets) { - + NSDictionary *assetInfoDict = [CKGalleryViewManager infoForAsset:asset imageRequestOptions:imageRequestOptions imageQuality:imageQuality]; NSString *assetLocalId = asset.localIdentifier; - + if (assetInfoDict && assetInfoDict[@"uri"] && assetInfoDict[@"size"] && assetInfoDict[@"name"] && assetLocalId) { - + NSUInteger originalArrayIndex = [imagesIdArray indexOfObject:assetLocalId]; - + [assetsArray replaceObjectAtIndex:originalArrayIndex withObject:@{@"uri": assetInfoDict[@"uri"], @"width": assetInfoDict[@"width"], @"height": assetInfoDict[@"height"], @@ -277,19 +269,19 @@ -(void)imagesForIds:(NSArray*)imagesIdArray @"id": assetLocalId}]; } } - + NSMutableArray *resolveArray = [NSMutableArray new]; for (id obj in assetsArray) { if ([obj isKindOfClass:[NSDictionary class]]) { [resolveArray addObject:obj]; } } - + if (resolve) { resolve(@{@"images": resolveArray}); } - - + + } @@ -333,9 +325,9 @@ +(void)requestDeviceGalleryAuthorization:(CallbackGalleryAuthorizationStatus)cal } +(NSNumber*)checkDeviceGalleryAuthorizationStatus { - + PHAuthorizationStatus authorizationStatus = [PHPhotoLibrary authorizationStatus]; - + if (authorizationStatus == PHAuthorizationStatusAuthorized) { return @YES; } @@ -359,7 +351,7 @@ +(NSNumber*)checkDeviceGalleryAuthorizationStatus { result[@"error"] = [error description]; } } - + if(resolve) { resolve(result); } diff --git a/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.h b/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.h index 7c65ec8dc7..3810a8f7da 100644 --- a/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.h +++ b/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.h @@ -1,11 +1,3 @@ -// -// CKGalleryViewManager.h -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 20/06/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import @import AVFoundation; diff --git a/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.m b/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.m index 5875f6a05f..7d6940f623 100644 --- a/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.m +++ b/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.m @@ -1,11 +1,3 @@ -// -// CKGalleryViewManager.m -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 20/06/2016. -// Copyright © 2016 Wix. All rights reserved. -// - @import Photos; #import "CKGalleryViewManager.h" @@ -91,22 +83,22 @@ @implementation CKGalleryView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; - + if (self) { - + self.selectedImages = [[NSMutableArray alloc] init]; self.imageManager = [[PHCachingImageManager alloc] init]; - + self.imageRequestOptions = [[PHImageRequestOptions alloc] init]; self.imageRequestOptions.synchronous = YES; - + self.contentInset = UIEdgeInsetsZero; - + self.isHorizontal = NO; self.cellSizeInvalidated = NO; self.collectionViewIsScrolling = NO; } - + return self; } @@ -130,10 +122,10 @@ -(PHFetchOptions *)fetchOptions { PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init]; fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]]; fetchOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType = %d",PHAssetMediaTypeImage]; - + _fetchOptions = fetchOptions; } - + return _fetchOptions; } @@ -146,9 +138,9 @@ -(void)removeFromSuperview { -(void)reactSetFrame:(CGRect)frame { [super reactSetFrame:frame]; - + if (CGRectIsEmpty(frame)) return; - + if (!self.collectionView) { self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:[self getCollectionViewFlowLayout:self.isHorizontal]]; self.collectionView.contentInset = self.contentInset; @@ -156,7 +148,7 @@ -(void)reactSetFrame:(CGRect)frame { [self handleSetAlwaysBounce:self.alwaysBounce isHorizontal:self.isHorizontal]; self.collectionView.delegate = self; self.collectionView.dataSource = self; - + [self.collectionView registerClass:[CKGalleryCollectionViewCell class] forCellWithReuseIdentifier:CellReuseIdentifier]; [self.collectionView registerClass:[CKGalleryCustomCollectionViewCell class] forCellWithReuseIdentifier:CustomCellReuseIdentifier]; [self addSubview:self.collectionView]; @@ -178,7 +170,7 @@ -(UICollectionViewFlowLayout*)getCollectionViewFlowLayout:(BOOL)isHorizontal { } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { - + return self.cellSize; } @@ -193,11 +185,11 @@ - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectio } -(void)upadateCollectionView:(PHFetchResult*)fetchResults animated:(BOOL)animated { - + self.galleryData = [[GalleryData alloc] initWithFetchResults:fetchResults selectedImagesIds:self.selectedImages]; - + if (animated) { - + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^ { [self.collectionView performBatchUpdates:^{ [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]]; @@ -289,73 +281,73 @@ -(void)setIsHorizontal:(BOOL)isHorizontal { -(void)setFileTypeSupport:(NSDictionary *)supported { _fileTypeSupport = supported; - + NSMutableDictionary *supportedDict = [[NSMutableDictionary alloc] init]; - + // SUPPORTED_FILE_TYPES id supportedFileTypesId = self.fileTypeSupport[SUPPORTED_FILE_TYPES]; if (supportedFileTypesId) { NSArray *supportedFileTypesArray = [RCTConvert NSArray:supportedFileTypesId]; supportedDict[SUPPORTED_FILE_TYPES] = supportedFileTypesArray; - + self.supportedFileTypesArray = [NSArray arrayWithArray:supportedFileTypesArray]; } - + // UNSUPPORTED_OVERLAY_COLOR id unsupportedOverlayColorId = self.fileTypeSupport[UNSUPPORTED_OVERLAY_COLOR]; if (unsupportedOverlayColorId) { UIColor *unsupportedOverlayColor = [RCTConvert UIColor:unsupportedOverlayColorId]; supportedDict[UNSUPPORTED_OVERLAY_COLOR] = unsupportedOverlayColor; } - + // UNSUPPORTED_OVERLAY_COLOR id unsupportedImageId = self.fileTypeSupport[UNSUPPORTED_IMAGE]; if (unsupportedImageId) { UIImage *unsupportedImage = [RCTConvert UIImage:unsupportedImageId]; supportedDict[UNSUPPORTED_IMAGE] = unsupportedImage; } - + // UNSUPPORTED_TEXT id unsupportedTextId = self.fileTypeSupport[UNSUPPORTED_TEXT]; if (unsupportedTextId) { NSString *unsupportedText = [RCTConvert NSString:unsupportedTextId]; supportedDict[UNSUPPORTED_TEXT] = unsupportedText; } - + // UNSUPPORTED_TEXT_COLOR id unsupportedTextColorId = self.fileTypeSupport[UNSUPPORTED_TEXT_COLOR]; if (unsupportedTextColorId) { UIColor *unsupportedTextColor = [RCTConvert UIColor:unsupportedTextColorId]; supportedDict[UNSUPPORTED_TEXT_COLOR] = unsupportedTextColor; } - + [CKGalleryCollectionViewCell setSupported:supportedDict]; } -(void)setAlbumName:(NSString *)albumName { - - + + if ([albumName caseInsensitiveCompare:@"all photos"] == NSOrderedSame || !albumName || [albumName isEqualToString:@""]) { - + PHFetchResult *allPhotosFetchResults = [PHAsset fetchAssetsWithOptions:self.fetchOptions]; [self upadateCollectionView:allPhotosFetchResults animated:(self.galleryData != nil)]; return; } - + PHFetchResult *collections = [PHCollectionList fetchTopLevelUserCollectionsWithOptions:nil]; - + [collections enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL * _Nonnull stop) { - + if ([collection.localizedTitle isEqualToString:albumName]) { - + PHFetchResult *collectionFetchResults = [PHAsset fetchAssetsInAssetCollection:collection options:nil]; [self upadateCollectionView:collectionFetchResults animated:(self.galleryData != nil)]; *stop = YES; return; } }]; - + } @@ -372,56 +364,56 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { - + NSInteger cellIndex = indexPath.row; if (self.customButtonStyle ) { cellIndex--; - + if (indexPath.row == 0) { CKGalleryCustomCollectionViewCell *customCell = [collectionView dequeueReusableCellWithReuseIdentifier:CustomCellReuseIdentifier forIndexPath:indexPath]; customCell.bridge = self.bridge; [customCell applyStyle:self.customButtonStyle]; return customCell; } - + } - + if ([self.galleryData.data count] < cellIndex) { return nil; } - + NSDictionary *assetDictionary = (NSDictionary*)self.galleryData.data[cellIndex]; PHAsset *asset = assetDictionary[@"asset"]; - + NSString *fileType = [self extractFileTypeForAsset:asset]; - + CFStringRef fileExtension = (__bridge CFStringRef)[fileType pathExtension]; CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL); CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType); CFRelease(UTI); NSString *MIMETypeString = (__bridge_transfer NSString *)MIMEType; - + __block CKGalleryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellReuseIdentifier forIndexPath:indexPath]; cell.delegate = self; cell.disableSelectionIcons = self.disableSelectionIcons ? self.disableSelectionIcons.boolValue : false; - + if (self.supportedFileTypesArray) { cell.isSupported = [self.supportedFileTypesArray containsObject:[MIMETypeString lowercaseString]]; } - + cell.representedAssetIdentifier = asset.localIdentifier; - + [self.imageManager requestImageForAsset:asset targetSize:CGSizeMake(self.cellSize.width*IMAGE_SIZE_MULTIPLIER, self.cellSize.height*IMAGE_SIZE_MULTIPLIER) contentMode:PHImageContentModeDefault options:nil resultHandler:^(UIImage *result, NSDictionary *info) { - + if ([cell.representedAssetIdentifier isEqualToString:asset.localIdentifier]) { cell.thumbnailImage = result; } }]; - + return cell; } @@ -441,7 +433,7 @@ -(NSString*)extractFileTypeForAsset:(PHAsset*)asset { } -(void)downloadImageFromICloud:(PHAsset *)asset cell:(CKGalleryCollectionViewCell *)cell completion:(CompletionBlock)completion { - + PHImageManager *manager = [PHImageManager defaultManager]; PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; options.networkAccessAllowed = YES; @@ -451,16 +443,16 @@ -(void)downloadImageFromICloud:(PHAsset *)asset cell:(CKGalleryCollectionViewCel [self remoteDownloadingUpdate:cell progress:progress isDownloading:YES]; }); }]; - + [manager requestImageDataForAsset:asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { - + if (imageData) { dispatch_async(dispatch_get_main_queue(), ^{ [self remoteDownloadingUpdate:cell progress:1 isDownloading:NO]; - + if (completion) { completion(YES); } @@ -474,32 +466,32 @@ -(void)downloadImageFromICloud:(PHAsset *)asset cell:(CKGalleryCollectionViewCel } }); } - + }]; - + } -(void)simulateICloudDownload:(NSTimer *)timer { CKGalleryCollectionViewCell *cell = (CKGalleryCollectionViewCell *)timer.userInfo[@"cell"]; CFAbsoluteTime currentTimePassed = CFAbsoluteTimeGetCurrent() - self.timePassed; - + if (currentTimePassed <= [self.iCloudDownloadSimulateTime doubleValue]) { - + [self remoteDownloadingUpdate:cell progress:currentTimePassed/[self.iCloudDownloadSimulateTime doubleValue] isDownloading:YES]; - + } else { CompletionBlock completion = (CompletionBlock)timer.userInfo[@"completion"]; - + [self.iCloudDownloadSimulateTimer invalidate]; self.iCloudDownloadSimulateTimer = nil; [self remoteDownloadingUpdate:cell progress:1 isDownloading:NO]; - + if (completion) { completion(YES); } @@ -507,30 +499,30 @@ -(void)simulateICloudDownload:(NSTimer *)timer { } -(void)downloadImageFromICloudIfNeeded:(PHAsset *)asset cell:(CKGalleryCollectionViewCell *)cell completion:(CompletionBlock)completion { - + if (self.iCloudDownloadSimulateTime && !cell.isSelected) { self.timePassed = CFAbsoluteTimeGetCurrent(); - + self.iCloudDownloadSimulateTimer = [NSTimer scheduledTimerWithTimeInterval:[self.iCloudDownloadSimulateTime doubleValue]/100 target:self selector:@selector(simulateICloudDownload:) userInfo:@{@"cell": cell, @"completion": completion} repeats:YES]; - + return; } - - + + PHImageManager *manager = [PHImageManager defaultManager]; PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; options.networkAccessAllowed = NO; options.synchronous = YES; - + [manager requestImageDataForAsset:asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { - + if ([[info valueForKey:PHImageResultIsInCloudKey] boolValue]) { dispatch_async(dispatch_get_main_queue(), ^{ [self remoteDownloadingUpdate:cell progress:0 isDownloading:YES]; @@ -552,36 +544,36 @@ -(void)downloadImageFromICloudIfNeeded:(PHAsset *)asset cell:(CKGalleryCollectio - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { - + NSInteger galleryDataIndex = indexPath.row; if (self.customButtonStyle) { galleryDataIndex--; } - + if (indexPath.row == 0 && self.onCustomButtonPress) { self.onCustomButtonPress(@{@"selected":@"customButtonPressed"}); return; } - + id selectedCell =[collectionView cellForItemAtIndexPath:indexPath]; - + if ([selectedCell isKindOfClass:[CKGalleryCollectionViewCell class]]) { CKGalleryCollectionViewCell *ckCell = (CKGalleryCollectionViewCell*)selectedCell; - + NSMutableDictionary *assetDictionary = (NSMutableDictionary*)self.galleryData.data[galleryDataIndex]; PHAsset *asset = assetDictionary[@"asset"]; NSNumber *isSelectedNumber = assetDictionary[@"isSelected"]; assetDictionary[@"isSelected"] = [NSNumber numberWithBool:!(isSelectedNumber.boolValue)]; - + [self downloadImageFromICloudIfNeeded:asset cell:ckCell completion:^(BOOL success) { - + if (success) { if (!ckCell.isSupported) { return; } - + ckCell.isSelected = !ckCell.isSelected; - + [self onSelectChanged:asset isSelected:ckCell.isSelected]; } }]; @@ -591,7 +583,7 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath { if([cell isKindOfClass:[CKGalleryCollectionViewCell class]]) { CKGalleryCollectionViewCell *ckCell = (CKGalleryCollectionViewCell*)cell; - + NSInteger galleryDataIndex = indexPath.row; if (self.customButtonStyle) { galleryDataIndex--; @@ -615,7 +607,7 @@ -(void)setSelectedImages:(NSMutableArray *)selectedImages { if (selectedImages) { _selectedImages = selectedImages; } - + if(selectionDirty && [self.autoSyncSelection boolValue]) { //sync visible cells for (CKGalleryCollectionViewCell *cell in [self.collectionView visibleCells]) { @@ -643,10 +635,10 @@ -(void)refreshGalleryView:(NSArray*)selectedImages { -(void)onSelectChanged:(PHAsset*)asset isSelected:(BOOL)isSelected{ if (self.onTapImage) { - + NSMutableDictionary *imageTapInfo = [@{@"width": [NSNumber numberWithUnsignedInteger:asset.pixelWidth], @"height": [NSNumber numberWithUnsignedInteger:asset.pixelHeight]} mutableCopy]; - + BOOL shouldReturnUrl = self.getUrlOnTapImage ? [self.getUrlOnTapImage boolValue] : NO; NSNumber *isSelectedNumber = [NSNumber numberWithBool:isSelected]; if (shouldReturnUrl) { @@ -654,7 +646,7 @@ -(void)onSelectChanged:(PHAsset*)asset isSelected:(BOOL)isSelected{ imageRequestOptions.synchronous = YES; NSDictionary *info = [CKGalleryViewManager infoForAsset:asset imageRequestOptions:imageRequestOptions imageQuality:self.imageQualityOnTap]; NSString *uriString = info[@"uri"]; - + if (uriString) { [imageTapInfo addEntriesFromDictionary:@{@"selected": uriString, @"selectedId": asset.localIdentifier, @"isSelected": isSelectedNumber}]; self.onTapImage(imageTapInfo); @@ -662,7 +654,7 @@ -(void)onSelectChanged:(PHAsset*)asset isSelected:(BOOL)isSelected{ else { self.onTapImage(@{@"Error": @"Could not get image uri"}); } - + } else { [imageTapInfo addEntriesFromDictionary:@{@"selected":asset.localIdentifier, @"isSelected": isSelectedNumber}]; @@ -673,13 +665,13 @@ -(void)onSelectChanged:(PHAsset*)asset isSelected:(BOOL)isSelected{ +(PHFetchResult*)filterFetchResults:(PHFetchResult*)fetchResults typesArray:(NSArray*)typesArray { - + [fetchResults enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { NSLog(@"obj"); }]; - + return nil; - + } #pragma mark - UIScrollViewDelegate methods @@ -691,7 +683,7 @@ -(void)clearCollectionViewIsScrolling { - (void)scrollViewDidScroll:(UIScrollView *)scrollView { self.collectionViewIsScrolling = YES; - + if (self.lastPressedCell != nil) { [self.lastPressedCell setPressed:NO]; } @@ -768,46 +760,46 @@ - (UIView *)view RCT_EXPORT_METHOD(getSelectedImages:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) { - + NSError *error = nil; NSURL *directoryURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]] isDirectory:YES]; [[NSFileManager defaultManager] createDirectoryAtURL:directoryURL withIntermediateDirectories:YES attributes:nil error:&error]; - + NSMutableArray *assetsUrls = [[NSMutableArray alloc] init]; - + for (PHAsset *asset in self.galleryView.selectedImages) { - + [self.galleryView.imageManager requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { - + NSURL *fileURLKey = info[@"PHImageFileURLKey"]; if (!fileURLKey) { if (resolve) { resolve(nil); } } - + NSMutableDictionary *assetInfoDict = [[NSMutableDictionary alloc] init]; imageData = [CKGalleryViewManager handleNonJPEGOrPNGFormatsData:imageData dataUTI:dataUTI]; NSString *fileName = ((NSURL*)info[@"PHImageFileURLKey"]).lastPathComponent; - + fileName = [CKGalleryViewManager handleNonJPEGOrPNGFormatsFileName:fileName dataUTI:dataUTI]; if (fileName) { assetInfoDict[@"name"] = fileName; } - + float imageSize = imageData.length; assetInfoDict[@"size"] = [NSNumber numberWithFloat:imageSize]; - + NSURL *fileURL = [directoryURL URLByAppendingPathComponent:fileName]; NSError *error = nil; [imageData writeToURL:fileURL options:NSDataWritingAtomic error:&error]; - + if (!error && fileURL) { assetInfoDict[@"uri"] = fileURL.absoluteString; } - + [assetsUrls addObject:assetInfoDict]; - + if (asset == self.galleryView.selectedImages.lastObject) { if (resolve) { resolve(@{@"selectedImages":assetsUrls}); @@ -823,7 +815,7 @@ - (UIView *)view reject:(RCTPromiseRejectBlock)reject) { NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:selectedImages]; [self.galleryView refreshGalleryView:newArray]; - + if (resolve) resolve(@YES); } @@ -845,21 +837,21 @@ - (UIView *)view +(NSMutableDictionary*)infoForAsset:(PHAsset*)asset imageRequestOptions:(PHImageRequestOptions*)imageRequestOptions imageQuality:(NSString*)imageQuality { - + NSError *error = nil; NSURL *directoryURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]] isDirectory:YES]; - + [[NSFileManager defaultManager] createDirectoryAtURL:directoryURL withIntermediateDirectories:YES attributes:nil error:&error]; - + if (error) { //NSLog(@"ERROR while creating directory:%@",error); } - - + + __block NSMutableDictionary *assetInfoDict = nil; - + [[PHCachingImageManager defaultManager] requestImageDataForAsset:asset options:imageRequestOptions resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { - + NSString *fileName = ((NSURL*)info[@"PHImageFileURLKey"]).lastPathComponent; if (!fileName) { @@ -868,41 +860,41 @@ +(NSMutableDictionary*)infoForAsset:(PHAsset*)asset fileName = [CKGalleryViewManager handleNonJPEGOrPNGFormatsFileName:fileName dataUTI:dataUTI]; imageData = [CKGalleryViewManager handleNonJPEGOrPNGFormatsData:imageData dataUTI:dataUTI]; - + NSData *compressedImageData = imageData; - + UIImage *compressedImage = [UIImage imageWithData:imageData]; - + NSURL *fileURLKey = info[@"PHImageFileURLKey"]; if (!fileURLKey) { fileURLKey = info[@"PHImageFileUTIKey"]; } - + if (fileURLKey) { - + assetInfoDict = [[NSMutableDictionary alloc] init]; - + assetInfoDict[@"width"] = [NSNumber numberWithFloat:compressedImage.size.width]; assetInfoDict[@"height"] = [NSNumber numberWithFloat:compressedImage.size.height]; - + if (fileName) { assetInfoDict[@"name"] = fileName; } else { fileName = @""; } - + float imageSize = 0; if (compressedImageData) { imageSize = compressedImageData.length; } assetInfoDict[@"size"] = [NSNumber numberWithFloat:imageSize]; - + NSURL *fileURL = [directoryURL URLByAppendingPathComponent:fileName]; NSError *error = nil; - + [compressedImageData writeToURL:fileURL options:NSDataWritingAtomic error:&error]; - + if (!error && fileURL) { assetInfoDict[@"uri"] = fileURL.absoluteString; } @@ -911,11 +903,11 @@ +(NSMutableDictionary*)infoForAsset:(PHAsset*)asset } } }]; - + if (assetInfoDict && asset) { assetInfoDict[@"asset"] = asset; } - + return assetInfoDict; } @@ -926,7 +918,7 @@ +(NSData*)handleNonJPEGOrPNGFormatsData:(NSData*)imageData dataUTI:(NSString*)da { CIImage* image = [CIImage imageWithData:imageData]; CIContext* context = [CIContext contextWithOptions:nil]; - + if ([context respondsToSelector:@selector(JPEGRepresentationOfImage:colorSpace:options:)]) { ans = [context JPEGRepresentationOfImage:image colorSpace:CGColorSpaceCreateWithName(kCGColorSpaceSRGB) diff --git a/ios/lib/ReactNativeCameraKit/CKOverlayObject.h b/ios/lib/ReactNativeCameraKit/CKOverlayObject.h index baafeaf616..e1f6bf9c6d 100644 --- a/ios/lib/ReactNativeCameraKit/CKOverlayObject.h +++ b/ios/lib/ReactNativeCameraKit/CKOverlayObject.h @@ -1,11 +1,3 @@ -// -// CKOverlayObject.h -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 17/07/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import @interface CKOverlayObject : NSObject diff --git a/ios/lib/ReactNativeCameraKit/CKOverlayObject.m b/ios/lib/ReactNativeCameraKit/CKOverlayObject.m index ae0aa5a92c..102db93eae 100644 --- a/ios/lib/ReactNativeCameraKit/CKOverlayObject.m +++ b/ios/lib/ReactNativeCameraKit/CKOverlayObject.m @@ -1,11 +1,3 @@ -// -// CKOverlayObject.m -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 17/07/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import "CKOverlayObject.h" @interface CKOverlayObject () @@ -19,23 +11,23 @@ @interface CKOverlayObject () @implementation CKOverlayObject -(instancetype)initWithString:(NSString*)str { - + self = [super init]; - + if (self) { [self commonInit:str]; } - + return self; } -(void)commonInit:(NSString*)str { - + NSArray *array = [str componentsSeparatedByString:@":"]; if (array.count == 2) { float height = [array[0] floatValue]; float width = [array[1] floatValue]; - + if (width != 0 && height != 0) { self.width = width; self.height = height; diff --git a/ios/lib/ReactNativeCameraKit/GalleryData.h b/ios/lib/ReactNativeCameraKit/GalleryData.h index 80c2fa9cf3..d84413f601 100644 --- a/ios/lib/ReactNativeCameraKit/GalleryData.h +++ b/ios/lib/ReactNativeCameraKit/GalleryData.h @@ -1,11 +1,3 @@ -// -// GalleryData.h -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 30/06/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import @import Photos; diff --git a/ios/lib/ReactNativeCameraKit/GalleryData.m b/ios/lib/ReactNativeCameraKit/GalleryData.m index cecd0d366b..3c0a14d713 100644 --- a/ios/lib/ReactNativeCameraKit/GalleryData.m +++ b/ios/lib/ReactNativeCameraKit/GalleryData.m @@ -1,11 +1,3 @@ -// -// GalleryData.m -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 30/06/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import "GalleryData.h" @interface GalleryData () @@ -19,7 +11,7 @@ @interface GalleryData () @implementation GalleryData -(instancetype)initWithFetchResults:(PHFetchResult*)fetchResults selectedImagesIds:(NSArray*)selectedImagesIds{ - + self = [super init]; if (self) { self.fetchResults = fetchResults; @@ -31,17 +23,17 @@ -(instancetype)initWithFetchResults:(PHFetchResult*)fetchResults selectedImagesI -(NSArray*)arrayWithFetchResults:(PHFetchResult*)fetchResults selectedImagesIds:(NSArray*)selectedImagesIds{ - + NSMutableArray *array = [[NSMutableArray alloc] init]; - + for (PHAsset *asset in fetchResults) { BOOL isSelected = ([selectedImagesIds containsObject:asset.localIdentifier]) ? YES : NO; - + NSMutableDictionary *assetDictionary = [@{@"asset": asset, @"isSelected": @(isSelected)} mutableCopy]; - + [array addObject:assetDictionary]; } - + return array; } diff --git a/ios/lib/ReactNativeCameraKit/SelectionGesture.h b/ios/lib/ReactNativeCameraKit/SelectionGesture.h index e3edf5489a..63dbdba3c3 100644 --- a/ios/lib/ReactNativeCameraKit/SelectionGesture.h +++ b/ios/lib/ReactNativeCameraKit/SelectionGesture.h @@ -1,11 +1,3 @@ -// -// SelectionGesture.h -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 05/07/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import #import diff --git a/ios/lib/ReactNativeCameraKit/SelectionGesture.m b/ios/lib/ReactNativeCameraKit/SelectionGesture.m index af8dfb9b27..10d7d2db71 100644 --- a/ios/lib/ReactNativeCameraKit/SelectionGesture.m +++ b/ios/lib/ReactNativeCameraKit/SelectionGesture.m @@ -1,11 +1,3 @@ -// -// SelectionGesture.m -// ReactNativeCameraKit -// -// Created by Ran Greenberg on 05/07/2016. -// Copyright © 2016 Wix. All rights reserved. -// - #import "SelectionGesture.h" @implementation SelectionGesture diff --git a/old-example/android/app/src/main/java/com/example/MainActivity.java b/old-example/android/app/src/main/java/com/example/MainActivity.java index a20fc54d97..fe4f406050 100644 --- a/old-example/android/app/src/main/java/com/example/MainActivity.java +++ b/old-example/android/app/src/main/java/com/example/MainActivity.java @@ -3,7 +3,6 @@ import com.facebook.react.ReactActivity; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage; -import com.wix.RNCameraKit.RNCameraKitPackage; import java.util.Arrays; import java.util.List; diff --git a/old-example/android/app/src/main/java/com/example/MainApplication.java b/old-example/android/app/src/main/java/com/example/MainApplication.java index 8b28d8525d..9d97edc472 100644 --- a/old-example/android/app/src/main/java/com/example/MainApplication.java +++ b/old-example/android/app/src/main/java/com/example/MainApplication.java @@ -6,7 +6,7 @@ import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage; -import com.wix.RNCameraKit.RNCameraKitPackage; +import com.rncamerakit.RNCameraKitPackage; import java.util.Arrays; import java.util.List; diff --git a/package.json b/package.json index a036c45c7a..6ad1b933dd 100644 --- a/package.json +++ b/package.json @@ -2,18 +2,13 @@ "name": "react-native-camera-kit", "repository": { "type": "git", - "url": "https://github.com/wix/react-native-camera-kit.git" }, "publishConfig": { "registry": "https://registry.npmjs.org/" }, "version": "9.0.0", "description": "Advanced native camera control with pre-defined aspect ratio, crop, etc", - "author": "Ran Greenberg ", "nativePackage": true, - "bugs": { - "url": "https://github.com/wix/react-native-camera-kit/issues" - }, "scripts": { "start": "watchman watch-del-all && node node_modules/react-native/local-cli/cli.js start", "xcode": "open example-ios/CameraKit.xcodeproj", @@ -34,5 +29,4 @@ "metro-react-native-babel-preset": "0.51.0", "jsc-android": "245459.0.0" }, - "homepage": "https://github.com/wix/react-native-camera-kit" }