Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
# iOS Objective-C Style Guide
# Based on Apple's coding conventions and common iOS practices

BasedOnStyle: LLVM

# Language specific settings
Language: ObjC

# Indentation
IndentWidth: 4
TabWidth: 4
UseTab: Never
ContinuationIndentWidth: 4

# Line length
ColumnLimit: 0

# Pointer and reference alignment
PointerAlignment: Right
ReferenceAlignment: Right

# Braces
BreakBeforeBraces: Attach
AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: false

# Method and function formatting
AlignAfterOpenBracket: Align
AllowAllParametersOfDeclarationOnNextLine: false
BinPackParameters: false
BinPackArguments: false

# Objective-C specific
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 4
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true

# Spacing
SpaceBeforeParens: ControlStatements
SpaceBeforeAssignmentOperators: true
SpaceAfterCStyleCast: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false

# Keep things together
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1

# Align consecutive assignments and declarations
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false

# Comments
ReflowComments: true
SpacesBeforeTrailingComments: 2

# Line breaks
AllowShortCaseLabelsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true

# Import/Include sorting
SortIncludes: CaseInsensitive
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*>'
Priority: 2
- Regex: '^"'
Priority: 3

# Penalty weights (fine-tuning line breaks)
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@

@implementation UIImage (CropRotate)

- (BOOL)hasAlpha
{
- (BOOL)hasAlpha {
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(self.CGImage);
return (alphaInfo == kCGImageAlphaFirst || alphaInfo == kCGImageAlphaLast ||
alphaInfo == kCGImageAlphaPremultipliedFirst || alphaInfo == kCGImageAlphaPremultipliedLast);
}

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

// Work out the new bounding size of the canvas after rotation
CGRect imageBounds = (CGRect){CGPointZero, self.size};
Expand Down
24 changes: 12 additions & 12 deletions Objective-C/TOCropViewController/Constants/TOCropViewConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,36 @@
The shape of the cropping region of this crop view controller
*/
typedef NS_ENUM(NSInteger, TOCropViewCroppingStyle) {
TOCropViewCroppingStyleDefault, // The regular, rectangular crop box
TOCropViewCroppingStyleCircular // A fixed, circular crop box
TOCropViewCroppingStyleDefault, // The regular, rectangular crop box
TOCropViewCroppingStyleCircular // A fixed, circular crop box
};

/**
Whether the control toolbar is placed at the bottom or the top
*/
typedef NS_ENUM(NSInteger, TOCropViewControllerToolbarPosition) {
TOCropViewControllerToolbarPositionBottom, // Bar is placed along the bottom in portrait
TOCropViewControllerToolbarPositionTop // Bar is placed along the top in portrait (Respects the status bar)
TOCropViewControllerToolbarPositionTop // Bar is placed along the top in portrait (Respects the status bar)
};

static inline NSBundle *TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(NSObject *object) {
#if SWIFT_PACKAGE
// SPM is supposed to support the keyword SWIFTPM_MODULE_BUNDLE
// but I can't figure out how to make it work, so doing it manually
NSString *bundleName = @"TOCropViewController_TOCropViewController";
// SPM is supposed to support the keyword SWIFTPM_MODULE_BUNDLE
// but I can't figure out how to make it work, so doing it manually
NSString *bundleName = @"TOCropViewController_TOCropViewController";
#else
NSString *bundleName = @"TOCropViewControllerBundle";
NSString *bundleName = @"TOCropViewControllerBundle";
#endif
NSBundle *resourceBundle = nil;
NSBundle *classBundle = [NSBundle bundleForClass:object.class];
NSURL *resourceBundleURL = [classBundle URLForResource:bundleName withExtension:@"bundle"];
if (resourceBundleURL) {
resourceBundle = [[NSBundle alloc] initWithURL:resourceBundleURL];
#ifndef NDEBUG
if (resourceBundle == nil) {
@throw [[NSException alloc] initWithName:@"BundleAccessor" reason:[NSString stringWithFormat:@"unable to find bundle named %@", bundleName] userInfo:nil];
}
#endif
#ifndef NDEBUG
if (resourceBundle == nil) {
@throw [[NSException alloc] initWithName:@"BundleAccessor" reason:[NSString stringWithFormat:@"unable to find bundle named %@", bundleName] userInfo:nil];
}
#endif
} else {
resourceBundle = classBundle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#import "TOActivityCroppedImageProvider.h"

#import "UIImage+CropRotate.h"

@interface TOActivityCroppedImageProvider ()
Expand All @@ -36,38 +37,34 @@ @interface TOActivityCroppedImageProvider ()

@implementation TOActivityCroppedImageProvider

- (instancetype)initWithImage:(UIImage *)image cropFrame:(CGRect)cropFrame angle:(NSInteger)angle circular:(BOOL)circular
{
- (instancetype)initWithImage:(UIImage *)image cropFrame:(CGRect)cropFrame angle:(NSInteger)angle circular:(BOOL)circular {
if (self = [super initWithPlaceholderItem:[UIImage new]]) {
_image = image;
_cropFrame = cropFrame;
_angle = angle;
_circular = circular;
}

return self;
}

#pragma mark - UIActivity Protocols -
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController
{
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
return [[UIImage alloc] init];
}

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
return self.croppedImage;
}

#pragma mark - Image Generation -
- (id)item
{
//If the user didn't touch the image, just forward along the original
- (id)item {
// If the user didn't touch the image, just forward along the original
if (self.angle == 0 && CGRectEqualToRect(self.cropFrame, (CGRect){CGPointZero, self.image.size})) {
self.croppedImage = self.image;
return self.croppedImage;
}

UIImage *image = [self.image croppedImageWithFrame:self.cropFrame angle:self.angle circularClip:self.circular];
self.croppedImage = image;
return self.croppedImage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ @interface TOCropViewControllerAspectRatioPreset ()

@implementation TOCropViewControllerAspectRatioPreset

- (instancetype)initWithSize:(CGSize)size title:(NSString *)title
{
- (instancetype)initWithSize:(CGSize)size title:(NSString *)title {
self = [super init];
if (self) {
_size = size;
Expand All @@ -58,37 +57,49 @@ - (BOOL)isEqual:(id)object {
return CGSizeEqualToSize(self.size, other.size) && [self.title isEqualToString:other.title];
}

+ (NSArray<TOCropViewControllerAspectRatioPreset *> *)portraitPresets
{
+ (NSArray<TOCropViewControllerAspectRatioPreset *> *)portraitPresets {
TOCropViewControllerAspectRatioPreset *object = [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:@"Original"];
NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object);
NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object);
return @[
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f) title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(2.0f, 3.0f) title:@"2:3"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 5.0f) title:@"3:5"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 4.0f) title:@"3:4"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 5.0f) title:@"4:5"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 7.0f) title:@"5:7"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(9.0f, 16.0f) title:@"9:16"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero
title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f)
title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(2.0f, 3.0f)
title:@"2:3"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 5.0f)
title:@"3:5"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 4.0f)
title:@"3:4"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 5.0f)
title:@"4:5"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 7.0f)
title:@"5:7"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(9.0f, 16.0f)
title:@"9:16"],
];
}

+ (NSArray<TOCropViewControllerAspectRatioPreset *> *)landscapePresets
{
+ (NSArray<TOCropViewControllerAspectRatioPreset *> *)landscapePresets {
TOCropViewControllerAspectRatioPreset *object = [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:@"Original"];
NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object);
NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object);
return @[
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f) title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 2.0f) title:@"3:2"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 3.0f) title:@"5:3"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 3.0f) title:@"4:3"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 4.0f) title:@"5:4"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(7.0f, 5.0f) title:@"7:5"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(16.0f, 9.0f) title:@"16:9"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero
title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f)
title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 2.0f)
title:@"3:2"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 3.0f)
title:@"5:3"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 3.0f)
title:@"4:3"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 4.0f)
title:@"5:4"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(7.0f, 5.0f)
title:@"7:5"],
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(16.0f, 9.0f)
title:@"16:9"],
];
}
@end


Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface TOCropViewControllerTransitioning : NSObject <UIViewControllerAnimatedTransitioning>

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

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