Skip to content

Commit 4ee7faa

Browse files
committed
Run clang-format on project
1 parent 52630e4 commit 4ee7faa

23 files changed

+1474
-1597
lines changed

Objective-C/TOCropViewController/Categories/UIImage+CropRotate.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424

2525
@implementation UIImage (CropRotate)
2626

27-
- (BOOL)hasAlpha
28-
{
27+
- (BOOL)hasAlpha {
2928
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(self.CGImage);
3029
return (alphaInfo == kCGImageAlphaFirst || alphaInfo == kCGImageAlphaLast ||
3130
alphaInfo == kCGImageAlphaPremultipliedFirst || alphaInfo == kCGImageAlphaPremultipliedLast);
3231
}
3332

34-
- (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circularClip:(BOOL)circular
35-
{
33+
- (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circularClip:(BOOL)circular {
3634
UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat new];
3735
format.opaque = !self.hasAlpha && !circular;
3836
format.scale = self.scale;
@@ -53,7 +51,7 @@ - (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circular
5351
// If an angle was supplied, rotate the entire canvas + coordinate space to match
5452
if (angle != 0) {
5553
// Rotation in radians
56-
CGFloat rotation = angle * (M_PI/180.0f);
54+
CGFloat rotation = angle * (M_PI / 180.0f);
5755

5856
// Work out the new bounding size of the canvas after rotation
5957
CGRect imageBounds = (CGRect){CGPointZero, self.size};

Objective-C/TOCropViewController/Constants/TOCropViewConstants.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,36 @@
2626
The shape of the cropping region of this crop view controller
2727
*/
2828
typedef NS_ENUM(NSInteger, TOCropViewCroppingStyle) {
29-
TOCropViewCroppingStyleDefault, // The regular, rectangular crop box
30-
TOCropViewCroppingStyleCircular // A fixed, circular crop box
29+
TOCropViewCroppingStyleDefault, // The regular, rectangular crop box
30+
TOCropViewCroppingStyleCircular // A fixed, circular crop box
3131
};
3232

3333
/**
3434
Whether the control toolbar is placed at the bottom or the top
3535
*/
3636
typedef NS_ENUM(NSInteger, TOCropViewControllerToolbarPosition) {
3737
TOCropViewControllerToolbarPositionBottom, // Bar is placed along the bottom in portrait
38-
TOCropViewControllerToolbarPositionTop // Bar is placed along the top in portrait (Respects the status bar)
38+
TOCropViewControllerToolbarPositionTop // Bar is placed along the top in portrait (Respects the status bar)
3939
};
4040

4141
static inline NSBundle *TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(NSObject *object) {
4242
#if SWIFT_PACKAGE
43-
// SPM is supposed to support the keyword SWIFTPM_MODULE_BUNDLE
44-
// but I can't figure out how to make it work, so doing it manually
45-
NSString *bundleName = @"TOCropViewController_TOCropViewController";
43+
// SPM is supposed to support the keyword SWIFTPM_MODULE_BUNDLE
44+
// but I can't figure out how to make it work, so doing it manually
45+
NSString *bundleName = @"TOCropViewController_TOCropViewController";
4646
#else
47-
NSString *bundleName = @"TOCropViewControllerBundle";
47+
NSString *bundleName = @"TOCropViewControllerBundle";
4848
#endif
4949
NSBundle *resourceBundle = nil;
5050
NSBundle *classBundle = [NSBundle bundleForClass:object.class];
5151
NSURL *resourceBundleURL = [classBundle URLForResource:bundleName withExtension:@"bundle"];
5252
if (resourceBundleURL) {
5353
resourceBundle = [[NSBundle alloc] initWithURL:resourceBundleURL];
54-
#ifndef NDEBUG
55-
if (resourceBundle == nil) {
56-
@throw [[NSException alloc] initWithName:@"BundleAccessor" reason:[NSString stringWithFormat:@"unable to find bundle named %@", bundleName] userInfo:nil];
57-
}
58-
#endif
54+
#ifndef NDEBUG
55+
if (resourceBundle == nil) {
56+
@throw [[NSException alloc] initWithName:@"BundleAccessor" reason:[NSString stringWithFormat:@"unable to find bundle named %@", bundleName] userInfo:nil];
57+
}
58+
#endif
5959
} else {
6060
resourceBundle = classBundle;
6161
}

Objective-C/TOCropViewController/Models/TOActivityCroppedImageProvider.m

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222

2323
#import "TOActivityCroppedImageProvider.h"
24+
2425
#import "UIImage+CropRotate.h"
2526

2627
@interface TOActivityCroppedImageProvider ()
@@ -36,38 +37,34 @@ @interface TOActivityCroppedImageProvider ()
3637

3738
@implementation TOActivityCroppedImageProvider
3839

39-
- (instancetype)initWithImage:(UIImage *)image cropFrame:(CGRect)cropFrame angle:(NSInteger)angle circular:(BOOL)circular
40-
{
40+
- (instancetype)initWithImage:(UIImage *)image cropFrame:(CGRect)cropFrame angle:(NSInteger)angle circular:(BOOL)circular {
4141
if (self = [super initWithPlaceholderItem:[UIImage new]]) {
4242
_image = image;
4343
_cropFrame = cropFrame;
4444
_angle = angle;
4545
_circular = circular;
4646
}
47-
47+
4848
return self;
4949
}
5050

5151
#pragma mark - UIActivity Protocols -
52-
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController
53-
{
52+
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
5453
return [[UIImage alloc] init];
5554
}
5655

57-
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
58-
{
56+
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
5957
return self.croppedImage;
6058
}
6159

6260
#pragma mark - Image Generation -
63-
- (id)item
64-
{
65-
//If the user didn't touch the image, just forward along the original
61+
- (id)item {
62+
// If the user didn't touch the image, just forward along the original
6663
if (self.angle == 0 && CGRectEqualToRect(self.cropFrame, (CGRect){CGPointZero, self.image.size})) {
6764
self.croppedImage = self.image;
6865
return self.croppedImage;
6966
}
70-
67+
7168
UIImage *image = [self.image croppedImageWithFrame:self.cropFrame angle:self.angle circularClip:self.circular];
7269
self.croppedImage = image;
7370
return self.croppedImage;

Objective-C/TOCropViewController/Models/TOCropViewControllerAspectRatioPreset.m

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ @interface TOCropViewControllerAspectRatioPreset ()
3737

3838
@implementation TOCropViewControllerAspectRatioPreset
3939

40-
- (instancetype)initWithSize:(CGSize)size title:(NSString *)title
41-
{
40+
- (instancetype)initWithSize:(CGSize)size title:(NSString *)title {
4241
self = [super init];
4342
if (self) {
4443
_size = size;
@@ -58,37 +57,49 @@ - (BOOL)isEqual:(id)object {
5857
return CGSizeEqualToSize(self.size, other.size) && [self.title isEqualToString:other.title];
5958
}
6059

61-
+ (NSArray<TOCropViewControllerAspectRatioPreset *> *)portraitPresets
62-
{
60+
+ (NSArray<TOCropViewControllerAspectRatioPreset *> *)portraitPresets {
6361
TOCropViewControllerAspectRatioPreset *object = [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:@"Original"];
64-
NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object);
62+
NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object);
6563
return @[
66-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
67-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f) title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
68-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(2.0f, 3.0f) title:@"2:3"],
69-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 5.0f) title:@"3:5"],
70-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 4.0f) title:@"3:4"],
71-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 5.0f) title:@"4:5"],
72-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 7.0f) title:@"5:7"],
73-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(9.0f, 16.0f) title:@"9:16"],
64+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero
65+
title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
66+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f)
67+
title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
68+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(2.0f, 3.0f)
69+
title:@"2:3"],
70+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 5.0f)
71+
title:@"3:5"],
72+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 4.0f)
73+
title:@"3:4"],
74+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 5.0f)
75+
title:@"4:5"],
76+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 7.0f)
77+
title:@"5:7"],
78+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(9.0f, 16.0f)
79+
title:@"9:16"],
7480
];
7581
}
7682

77-
+ (NSArray<TOCropViewControllerAspectRatioPreset *> *)landscapePresets
78-
{
83+
+ (NSArray<TOCropViewControllerAspectRatioPreset *> *)landscapePresets {
7984
TOCropViewControllerAspectRatioPreset *object = [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:@"Original"];
80-
NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object);
85+
NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object);
8186
return @[
82-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
83-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f) title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
84-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 2.0f) title:@"3:2"],
85-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 3.0f) title:@"5:3"],
86-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 3.0f) title:@"4:3"],
87-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 4.0f) title:@"5:4"],
88-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(7.0f, 5.0f) title:@"7:5"],
89-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(16.0f, 9.0f) title:@"16:9"],
87+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero
88+
title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
89+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f)
90+
title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
91+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 2.0f)
92+
title:@"3:2"],
93+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 3.0f)
94+
title:@"5:3"],
95+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 3.0f)
96+
title:@"4:3"],
97+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 4.0f)
98+
title:@"5:4"],
99+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(7.0f, 5.0f)
100+
title:@"7:5"],
101+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(16.0f, 9.0f)
102+
title:@"16:9"],
90103
];
91104
}
92105
@end
93-
94-

Objective-C/TOCropViewController/Models/TOCropViewControllerTransitioning.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ NS_ASSUME_NONNULL_BEGIN
2828
@interface TOCropViewControllerTransitioning : NSObject <UIViewControllerAnimatedTransitioning>
2929

3030
/* State Tracking */
31-
@property (nonatomic, assign) BOOL isDismissing; // Whether this animation is presenting or dismissing
32-
@property (nullable, nonatomic, strong) UIImage *image; // The image that will be used in this animation
31+
@property (nonatomic, assign) BOOL isDismissing; // Whether this animation is presenting or dismissing
32+
@property (nullable, nonatomic, strong) UIImage *image; // The image that will be used in this animation
3333

3434
/* Destination/Origin points */
3535
@property (nullable, nonatomic, strong) UIView *fromView; // The origin view who's frame the image will be animated from

Objective-C/TOCropViewController/Models/TOCropViewControllerTransitioning.m

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,93 +21,99 @@
2121
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222

2323
#import "TOCropViewControllerTransitioning.h"
24+
2425
#import <QuartzCore/QuartzCore.h>
2526

2627
@implementation TOCropViewControllerTransitioning
2728

28-
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
29-
{
29+
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
3030
return 0.45f;
3131
}
3232

33-
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
34-
{
33+
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
3534
// Get the master view where the animation takes place
3635
UIView *containerView = [transitionContext containerView];
37-
36+
3837
// Get the origin/destination view controllers
3938
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
4039
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
41-
40+
4241
// Work out which one is the crop view controller
4342
UIViewController *cropViewController = (self.isDismissing == NO) ? toViewController : fromViewController;
4443
UIViewController *previousController = (self.isDismissing == NO) ? fromViewController : toViewController;
45-
44+
4645
// Just in case, match up the frame sizes
4746
cropViewController.view.frame = containerView.bounds;
4847
if (self.isDismissing) {
4948
previousController.view.frame = containerView.bounds;
5049
}
51-
50+
5251
// Add the view layers beforehand as this will trigger the initial sets of layouts
5352
if (self.isDismissing == NO) {
5453
[containerView addSubview:cropViewController.view];
5554

56-
//Force a relayout now that the view is in the view hierarchy (so things like the safe area insets are now valid)]
55+
// Force a relayout now that the view is in the view hierarchy (so things like the safe area insets are now valid)]
5756
[cropViewController.view setNeedsLayout];
5857
[cropViewController.view layoutIfNeeded];
5958
[cropViewController viewDidLayoutSubviews];
60-
}
61-
else {
59+
} else {
6260
[containerView insertSubview:previousController.view belowSubview:cropViewController.view];
6361
}
64-
62+
6563
// Perform any last UI updates now so we can potentially factor them into our calculations, but after
6664
// the container views have been set up
6765
if (self.prepareForTransitionHandler) {
6866
self.prepareForTransitionHandler();
6967
}
70-
68+
7169
// If origin/destination views were supplied, use them to supplant the
7270
// frames
7371
if (!self.isDismissing && self.fromView) {
7472
self.fromFrame = [self.fromView.superview convertRect:self.fromView.frame toView:containerView];
75-
}
76-
else if (self.isDismissing && self.toView) {
73+
} else if (self.isDismissing && self.toView) {
7774
self.toFrame = [self.toView.superview convertRect:self.toView.frame toView:containerView];
7875
}
79-
76+
8077
UIImageView *imageView = nil;
8178
if ((self.isDismissing && !CGRectIsEmpty(self.toFrame)) || (!self.isDismissing && !CGRectIsEmpty(self.fromFrame))) {
8279
imageView = [[UIImageView alloc] initWithImage:self.image];
8380
imageView.frame = self.fromFrame;
8481
imageView.accessibilityIgnoresInvertColors = YES;
8582
[containerView addSubview:imageView];
8683
}
87-
84+
8885
cropViewController.view.alpha = (self.isDismissing ? 1.0f : 0.0f);
8986
if (imageView) {
90-
[UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0.0f usingSpringWithDamping:1.0f initialSpringVelocity:0.7f options:0 animations:^{
91-
imageView.frame = self.toFrame;
92-
} completion:^(BOOL complete) {
93-
[UIView animateWithDuration:0.25f animations:^{
94-
imageView.alpha = 0.0f;
95-
}completion:^(BOOL complete) {
96-
[imageView removeFromSuperview];
87+
[UIView animateWithDuration:[self transitionDuration:transitionContext]
88+
delay:0.0f
89+
usingSpringWithDamping:1.0f
90+
initialSpringVelocity:0.7f
91+
options:0
92+
animations:^{
93+
imageView.frame = self.toFrame;
94+
}
95+
completion:^(BOOL complete) {
96+
[UIView animateWithDuration:0.25f
97+
animations:^{
98+
imageView.alpha = 0.0f;
99+
}
100+
completion:^(BOOL complete) {
101+
[imageView removeFromSuperview];
102+
}];
97103
}];
98-
}];
99104
}
100-
101-
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
102-
cropViewController.view.alpha = (self.isDismissing ? 0.0f : 1.0f);
103-
} completion:^(BOOL complete) {
104-
[self reset];
105-
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
106-
}];
105+
106+
[UIView animateWithDuration:[self transitionDuration:transitionContext]
107+
animations:^{
108+
cropViewController.view.alpha = (self.isDismissing ? 0.0f : 1.0f);
109+
}
110+
completion:^(BOOL complete) {
111+
[self reset];
112+
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
113+
}];
107114
}
108115

109-
- (void)reset
110-
{
116+
- (void)reset {
111117
self.image = nil;
112118
self.toView = nil;
113119
self.fromView = nil;

Objective-C/TOCropViewController/Models/TOCroppedImageAttributes.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ @interface TOCroppedImageAttributes ()
3232

3333
@implementation TOCroppedImageAttributes
3434

35-
- (instancetype)initWithCroppedFrame:(CGRect)croppedFrame angle:(NSInteger)angle originalImageSize:(CGSize)originalSize
36-
{
35+
- (instancetype)initWithCroppedFrame:(CGRect)croppedFrame angle:(NSInteger)angle originalImageSize:(CGSize)originalSize {
3736
if (self = [super init]) {
3837
_angle = angle;
3938
_croppedFrame = croppedFrame;
4039
_originalImageSize = originalSize;
4140
}
42-
41+
4342
return self;
4443
}
4544

0 commit comments

Comments
 (0)