Remove wix mentions in commnets in iOS files (#309)
Remove Wix mentions
This commit is contained in:
parent
323ed94609
commit
c130931132
2
LICENSE
2
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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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"
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
//
|
||||
// CKCamera.h
|
||||
// ReactNativeCameraKit
|
||||
//
|
||||
// Created by Ran Greenberg on 31/05/2016.
|
||||
// Copyright © 2016 Wix. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
@import AVFoundation;
|
||||
|
||||
|
||||
@ -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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
}
|
||||
|
||||
-(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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
if ([fetchOptions respondsToSelector:@selector(fetchLimit)]) {
|
||||
fetchOptions.fetchLimit = 1;
|
||||
}
|
||||
|
||||
|
||||
return fetchOptions;
|
||||
}
|
||||
|
||||
@ -163,7 +155,7 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
|
||||
- (void)removeFromSuperview
|
||||
{
|
||||
|
||||
|
||||
dispatch_async( self.sessionQueue, ^{
|
||||
if ( self.setupResult == CKSetupResultSuccess ) {
|
||||
[self.session stopRunning];
|
||||
@ -171,24 +163,24 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
}
|
||||
} );
|
||||
[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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
else {
|
||||
self.setupResult = CKSetupResultSessionConfigurationFailed;
|
||||
}
|
||||
|
||||
|
||||
AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
|
||||
if ( [self.session canAddOutput:movieFileOutput] ) {
|
||||
[self.session addOutput:movieFileOutput];
|
||||
@ -304,7 +296,7 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
else {
|
||||
self.setupResult = CKSetupResultSessionConfigurationFailed;
|
||||
}
|
||||
|
||||
|
||||
AVCaptureStillImageOutput *stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
|
||||
if ( [self.session canAddOutput:stillImageOutput] ) {
|
||||
stillImageOutput.outputSettings = @{AVVideoCodecKey : AVVideoCodecJPEG};
|
||||
@ -314,7 +306,7 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
else {
|
||||
self.setupResult = CKSetupResultSessionConfigurationFailed;
|
||||
}
|
||||
|
||||
|
||||
AVCaptureMetadataOutput * output = [[AVCaptureMetadataOutput alloc] init];
|
||||
if ([self.session canAddOutput:output]) {
|
||||
self.metadataOutput = output;
|
||||
@ -322,14 +314,14 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
[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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
|
||||
-(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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
+ (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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
- (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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
imageOrientation = UIImageOrientationRightMirrored;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Capture a still image.
|
||||
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:connection completionHandler:^( CMSampleBufferRef imageDataSampleBuffer, NSError *error ) {
|
||||
if (!imageDataSampleBuffer) {
|
||||
@ -531,27 +523,27 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
[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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
imageInfoDict[@"uri"] = temporaryFileURL.description;
|
||||
imageInfoDict[@"name"] = temporaryFileURL.lastPathComponent;
|
||||
}
|
||||
|
||||
|
||||
onSuccess(imageInfoDict);
|
||||
}
|
||||
|
||||
|
||||
[self resetFocus];
|
||||
}];
|
||||
});
|
||||
@ -616,12 +608,12 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
[self.focusResetTimer invalidate];
|
||||
self.focusResetTimer = nil;
|
||||
}
|
||||
|
||||
|
||||
// Resetting focus to continuous focus, so not interested in resetting anymore
|
||||
self.startFocusResetTimerAfterFocusing = NO;
|
||||
|
||||
@ -747,33 +739,33 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
|
||||
|
||||
+(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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
}
|
||||
|
||||
+(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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
UIView * cornerView = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
|
||||
cornerView.backgroundColor = self.frameColor;
|
||||
[frameView addSubview:cornerView];
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -982,20 +974,20 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
|
||||
- (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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
selector:@selector(willEnterForeground:)
|
||||
name:UIApplicationWillEnterForegroundNotification
|
||||
object:nil];
|
||||
|
||||
|
||||
self.isAddedOberver = YES;
|
||||
}
|
||||
}
|
||||
@ -1069,12 +1061,12 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
// 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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
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 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
|
||||
- (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});
|
||||
|
||||
@ -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(<React/RCTBridge.h>)
|
||||
|
||||
@ -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 @@ RCT_EXPORT_VIEW_PROPERTY(saveToCameraRollWithPhUrl, BOOL)
|
||||
RCT_EXPORT_METHOD(checkDeviceCameraAuthorizationStatus:(RCTPromiseResolveBlock)resolve
|
||||
reject:(__unused RCTPromiseRejectBlock)reject) {
|
||||
|
||||
|
||||
|
||||
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
||||
if(authStatus == AVAuthorizationStatusAuthorized) {
|
||||
resolve(@YES);
|
||||
@ -52,7 +44,7 @@ RCT_EXPORT_METHOD(checkDeviceCameraAuthorizationStatus:(RCTPromiseResolveBlock)r
|
||||
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 @@ RCT_EXPORT_METHOD(requestDeviceCameraAuthorization:(RCTPromiseResolveBlock)resol
|
||||
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 @@ RCT_EXPORT_METHOD(capture:(NSDictionary*)options
|
||||
|
||||
RCT_EXPORT_METHOD(changeCamera:(RCTPromiseResolveBlock)resolve
|
||||
reject:(RCTPromiseRejectBlock)reject) {
|
||||
|
||||
|
||||
[self.camera changeCamera:^(BOOL success) {
|
||||
if (success) {
|
||||
resolve([NSNumber numberWithBool:success]);
|
||||
@ -87,7 +79,7 @@ RCT_EXPORT_METHOD(changeCamera:(RCTPromiseResolveBlock)resolve
|
||||
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 @@ RCT_EXPORT_METHOD(setFlashMode:(CKCameraFlashMode)flashMode
|
||||
RCT_EXPORT_METHOD(setTorchMode:(CKCameraTorchMode)torchMode
|
||||
resolve:(RCTPromiseResolveBlock)resolve
|
||||
reject:(RCTPromiseRejectBlock)reject) {
|
||||
|
||||
|
||||
[self.camera setTorchMode:torchMode callback:^(BOOL success) {
|
||||
resolve([NSNumber numberWithBool:success]);
|
||||
}];
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
//
|
||||
// CKCameraOverlayView.h
|
||||
// ReactNativeCameraKit
|
||||
//
|
||||
// Created by Ran Greenberg on 17/07/2016.
|
||||
// Copyright © 2016 Wix. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "CKOverlayObject.h"
|
||||
|
||||
|
||||
@ -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 @@
|
||||
|
||||
|
||||
-(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 @@
|
||||
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 @@
|
||||
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)setRatio:(NSString*)ratioString {
|
||||
self.overlayObject = [[CKOverlayObject alloc] initWithString:ratioString];
|
||||
|
||||
|
||||
// self.alpha =0;
|
||||
[UIView animateWithDuration:0.2 animations:^{
|
||||
[self setOverlayParts];
|
||||
} completion:nil];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
//
|
||||
// CKCompressedImage.h
|
||||
// ReactNativeCameraKit
|
||||
//
|
||||
// Created by Sergey Ilyevsky on 15/05/2017.
|
||||
// Copyright © 2017 Wix. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface CKCompressedImage : NSObject
|
||||
|
||||
@ -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 @@
|
||||
}
|
||||
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 @@
|
||||
UIGraphicsEndImageContext();
|
||||
_data = UIImageJPEGRepresentation(_image, 0.85f);
|
||||
}
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
//
|
||||
// CKGalleryCollectionViewCell.h
|
||||
// ReactNativeCameraKit
|
||||
//
|
||||
// Created by Ran Greenberg on 20/06/2016.
|
||||
// Copyright © 2016 Wix. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#define SUPPORTED_FILE_TYPES @"supportedFileTypes"
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
//
|
||||
// CKGalleryCollectionViewCell.m
|
||||
// ReactNativeCameraKit
|
||||
//
|
||||
// Created by Ran Greenberg on 20/06/2016.
|
||||
// Copyright © 2016 Wix. All rights reserved.
|
||||
//
|
||||
|
||||
#if __has_include(<React/RCTBridge.h>)
|
||||
#import <React/RCTConvert.h>
|
||||
#else
|
||||
@ -123,7 +115,7 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
if (remoteDownloadIndicatorColor) {
|
||||
[_spinner setColor:remoteDownloadIndicatorColor];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return _spinner;
|
||||
}
|
||||
@ -142,7 +134,7 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
}
|
||||
|
||||
-(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 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
_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 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
|
||||
-(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 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
}
|
||||
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 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
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 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
else {
|
||||
badgeRect = CGRectZero;
|
||||
}
|
||||
|
||||
|
||||
return badgeRect;
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(void)updateBadgeImageViewFrame {
|
||||
@ -266,7 +258,7 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
if (!CGRectIsEmpty(badgeRect)) {
|
||||
self.badgeImageView.frame = badgeRect;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)prepareForReuse {
|
||||
@ -276,16 +268,16 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
_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 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
|
||||
-(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 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
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 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
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 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
|
||||
|
||||
-(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 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
[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 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
|
||||
-(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 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
[UIView animateWithDuration:0.5 delay:1 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
|
||||
self.progressPieView.alpha = 0;
|
||||
@ -463,10 +455,10 @@ static NSString *remoteDownloadIndicatorType = REMOTE_DOWNLOAD_INDICATOR_TYPE_SP
|
||||
-(void)removeRemoteDownloadIndicator {
|
||||
[_spinner removeFromSuperview];
|
||||
_spinner = nil;
|
||||
|
||||
|
||||
[_progressBarView removeFromSuperview];
|
||||
_progressBarView = nil;
|
||||
|
||||
|
||||
[_progressPieView removeFromSuperview];
|
||||
_progressPieView = nil;
|
||||
}
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
//
|
||||
// CKGalleryCustomCellCollectionViewCell.h
|
||||
// ReactNativeCameraKit
|
||||
//
|
||||
// Created by Ran Greenberg on 28/02/2017.
|
||||
// Copyright © 2017 Wix. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#if __has_include(<React/RCTBridge.h>)
|
||||
|
||||
@ -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(<React/RCTBridge.h>)
|
||||
@ -38,7 +30,7 @@
|
||||
|
||||
|
||||
-(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 @@
|
||||
_componentRootView.frame = self.bounds;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (_componentRootView == nil) {
|
||||
id imageProps = styleDict[CUSOM_BUTTON_IMAGE];
|
||||
if (imageProps) {
|
||||
@ -68,14 +60,14 @@
|
||||
_imageView.image = image;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
id backgroundColorProps = styleDict[CUSOM_BUTTON_BACKGROUND_COLOR];
|
||||
if (backgroundColorProps) {
|
||||
UIColor *backgroundColor = [RCTConvert UIColor:backgroundColorProps];
|
||||
self.backgroundColor = backgroundColor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_prevStyleDict = styleDict;
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
//
|
||||
// CKGallery.h
|
||||
// ReactNativeCameraKit
|
||||
//
|
||||
// Created by Ran Greenberg on 30/05/2016.
|
||||
// Copyright © 2016 Wix. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Photos/Photos.h>
|
||||
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
//
|
||||
// CKGallery.m
|
||||
// ReactNativeCameraKit
|
||||
//
|
||||
// Created by Ran Greenberg on 30/05/2016.
|
||||
// Copyright © 2016 Wix. All rights reserved.
|
||||
//
|
||||
|
||||
#if __has_include(<React/RCTBridge.h>)
|
||||
#import <React/RCTConvert.h>
|
||||
#else
|
||||
@ -69,7 +61,7 @@ RCT_EXPORT_MODULE();
|
||||
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 @@ RCT_EXPORT_MODULE();
|
||||
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 @@ RCT_EXPORT_MODULE();
|
||||
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 @@ RCT_EXPORT_MODULE();
|
||||
|
||||
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 @@ RCT_EXPORT_METHOD(getImagesForIds:(NSArray*)imagesIdArray
|
||||
imageQuality:(NSString*)imageQuality
|
||||
resolve:(RCTPromiseResolveBlock)resolve
|
||||
reject:(__unused RCTPromiseRejectBlock)reject) {
|
||||
|
||||
|
||||
[self imagesForIds:imagesIdArray imageQuality:imageQuality resolve:resolve reject:reject];
|
||||
}
|
||||
|
||||
@ -214,22 +206,22 @@ RCT_EXPORT_METHOD(resizeImage:(NSDictionary*)image
|
||||
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 @@ RCT_EXPORT_METHOD(resizeImage:(NSDictionary*)image
|
||||
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 @@ RCT_EXPORT_METHOD(resizeImage:(NSDictionary*)image
|
||||
@"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 @@ RCT_EXPORT_METHOD(requestDevicePhotosAuthorization:(RCTPromiseResolveBlock)resol
|
||||
}
|
||||
|
||||
+(NSNumber*)checkDeviceGalleryAuthorizationStatus {
|
||||
|
||||
|
||||
PHAuthorizationStatus authorizationStatus = [PHPhotoLibrary authorizationStatus];
|
||||
|
||||
|
||||
if (authorizationStatus == PHAuthorizationStatusAuthorized) {
|
||||
return @YES;
|
||||
}
|
||||
@ -359,7 +351,7 @@ RCT_EXPORT_METHOD(deleteTempImage:(NSString*)tempImageURL
|
||||
result[@"error"] = [error description];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(resolve) {
|
||||
resolve(result);
|
||||
}
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
//
|
||||
// CKGalleryViewManager.h
|
||||
// ReactNativeCameraKit
|
||||
//
|
||||
// Created by Ran Greenberg on 20/06/2016.
|
||||
// Copyright © 2016 Wix. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
@import AVFoundation;
|
||||
|
||||
|
||||
@ -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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
|
||||
- (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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
|
||||
-(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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
[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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
}
|
||||
|
||||
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
|
||||
|
||||
return self.cellSize;
|
||||
}
|
||||
|
||||
@ -193,11 +185,11 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
}
|
||||
|
||||
-(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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
|
||||
-(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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
|
||||
|
||||
- (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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
}
|
||||
|
||||
-(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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
[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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
-(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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
}
|
||||
|
||||
-(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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
|
||||
|
||||
- (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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
- (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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
if (selectedImages) {
|
||||
_selectedImages = selectedImages;
|
||||
}
|
||||
|
||||
|
||||
if(selectionDirty && [self.autoSyncSelection boolValue]) {
|
||||
//sync visible cells
|
||||
for (CKGalleryCollectionViewCell *cell in [self.collectionView visibleCells]) {
|
||||
@ -643,10 +635,10 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
|
||||
-(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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
else {
|
||||
self.onTapImage(@{@"Error": @"Could not get image uri"});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
[imageTapInfo addEntriesFromDictionary:@{@"selected":asset.localIdentifier, @"isSelected": isSelectedNumber}];
|
||||
@ -673,13 +665,13 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
|
||||
|
||||
+(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 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||||
self.collectionViewIsScrolling = YES;
|
||||
|
||||
|
||||
if (self.lastPressedCell != nil) {
|
||||
[self.lastPressedCell setPressed:NO];
|
||||
}
|
||||
@ -768,46 +760,46 @@ RCT_EXPORT_VIEW_PROPERTY(iCloudDownloadSimulateTime, NSNumber);
|
||||
|
||||
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 @@ RCT_EXPORT_METHOD(refreshGalleryView:(NSArray*)selectedImages
|
||||
reject:(RCTPromiseRejectBlock)reject) {
|
||||
NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:selectedImages];
|
||||
[self.galleryView refreshGalleryView:newArray];
|
||||
|
||||
|
||||
if (resolve)
|
||||
resolve(@YES);
|
||||
}
|
||||
@ -845,21 +837,21 @@ RCT_EXPORT_METHOD(modifyGalleryViewContentOffset:(NSDictionary*)params) {
|
||||
+(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 @@ RCT_EXPORT_METHOD(modifyGalleryViewContentOffset:(NSDictionary*)params) {
|
||||
|
||||
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 @@ RCT_EXPORT_METHOD(modifyGalleryViewContentOffset:(NSDictionary*)params) {
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
if (assetInfoDict && asset) {
|
||||
assetInfoDict[@"asset"] = asset;
|
||||
}
|
||||
|
||||
|
||||
return assetInfoDict;
|
||||
}
|
||||
|
||||
@ -926,7 +918,7 @@ RCT_EXPORT_METHOD(modifyGalleryViewContentOffset:(NSDictionary*)params) {
|
||||
{
|
||||
CIImage* image = [CIImage imageWithData:imageData];
|
||||
CIContext* context = [CIContext contextWithOptions:nil];
|
||||
|
||||
|
||||
if ([context respondsToSelector:@selector(JPEGRepresentationOfImage:colorSpace:options:)]) {
|
||||
ans = [context JPEGRepresentationOfImage:image
|
||||
colorSpace:CGColorSpaceCreateWithName(kCGColorSpaceSRGB)
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
//
|
||||
// CKOverlayObject.h
|
||||
// ReactNativeCameraKit
|
||||
//
|
||||
// Created by Ran Greenberg on 17/07/2016.
|
||||
// Copyright © 2016 Wix. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface CKOverlayObject : NSObject
|
||||
|
||||
@ -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 @@
|
||||
@implementation CKOverlayObject
|
||||
|
||||
-(instancetype)initWithString:(NSString*)str {
|
||||
|
||||
|
||||
self = [super init];
|
||||
|
||||
|
||||
if (self) {
|
||||
[self commonInit:str];
|
||||
}
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)commonInit:(NSString*)str {
|
||||
|
||||
|
||||
NSArray<NSString*> *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;
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
//
|
||||
// GalleryData.h
|
||||
// ReactNativeCameraKit
|
||||
//
|
||||
// Created by Ran Greenberg on 30/06/2016.
|
||||
// Copyright © 2016 Wix. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
@import Photos;
|
||||
|
||||
|
||||
@ -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 @@
|
||||
@implementation GalleryData
|
||||
|
||||
-(instancetype)initWithFetchResults:(PHFetchResult*)fetchResults selectedImagesIds:(NSArray*)selectedImagesIds{
|
||||
|
||||
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.fetchResults = fetchResults;
|
||||
@ -31,17 +23,17 @@
|
||||
|
||||
|
||||
-(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;
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
//
|
||||
// SelectionGesture.h
|
||||
// ReactNativeCameraKit
|
||||
//
|
||||
// Created by Ran Greenberg on 05/07/2016.
|
||||
// Copyright © 2016 Wix. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <UIKit/UIGestureRecognizerSubclass.h>
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -3,7 +3,6 @@ package com.example;
|
||||
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;
|
||||
|
||||
@ -6,7 +6,7 @@ import com.facebook.react.ReactApplication;
|
||||
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;
|
||||
|
||||
@ -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 <rang@wix.com>",
|
||||
"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"
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user