@onekeyfe/react-native-image-crop-picker 3.0.147
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +83 -0
- package/ReactNativeImageCropPicker.podspec +40 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +144 -0
- package/android/gradle.properties +4 -0
- package/android/src/main/AndroidManifest.xml +24 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/reactnativeimagecroppicker/ImageCropPickerException.kt +45 -0
- package/android/src/main/java/com/margelo/nitro/reactnativeimagecroppicker/ImageCropPickerImageProcessor.kt +308 -0
- package/android/src/main/java/com/margelo/nitro/reactnativeimagecroppicker/ImageCropPickerSession.kt +297 -0
- package/android/src/main/java/com/margelo/nitro/reactnativeimagecroppicker/ReactNativeImageCropPicker.kt +69 -0
- package/android/src/main/java/com/margelo/nitro/reactnativeimagecroppicker/ReactNativeImageCropPickerPackage.kt +24 -0
- package/ios/ImageCropPickerError.swift +57 -0
- package/ios/ImageCropPickerImageProcessor.swift +343 -0
- package/ios/ImageCropPickerSession.swift +407 -0
- package/ios/ReactNativeImageCropPicker.swift +65 -0
- package/ios/TOCropViewController/Categories/UIImage+CropRotate.h +39 -0
- package/ios/TOCropViewController/Categories/UIImage+CropRotate.m +94 -0
- package/ios/TOCropViewController/Constants/TOCropViewConstants.h +63 -0
- package/ios/TOCropViewController/LICENSE +21 -0
- package/ios/TOCropViewController/Models/TOActivityCroppedImageProvider.h +38 -0
- package/ios/TOCropViewController/Models/TOActivityCroppedImageProvider.m +73 -0
- package/ios/TOCropViewController/Models/TOCropViewControllerAspectRatioPreset.h +64 -0
- package/ios/TOCropViewController/Models/TOCropViewControllerAspectRatioPreset.m +121 -0
- package/ios/TOCropViewController/Models/TOCropViewControllerTransitioning.h +49 -0
- package/ios/TOCropViewController/Models/TOCropViewControllerTransitioning.m +125 -0
- package/ios/TOCropViewController/Models/TOCroppedImageAttributes.h +38 -0
- package/ios/TOCropViewController/Models/TOCroppedImageAttributes.m +45 -0
- package/ios/TOCropViewController/Resources/Base.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/PrivacyInfo.xcprivacy +14 -0
- package/ios/TOCropViewController/Resources/ar.lproj/TOCropViewControllerLocalizable.strings +9 -0
- package/ios/TOCropViewController/Resources/ca.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/cs.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/da-DK.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/de.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/en.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/es.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/fa-IR.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/fa.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/fi.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/fr.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/hu.lproj/TOCropViewControllerLocalizable.strings +9 -0
- package/ios/TOCropViewController/Resources/id.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/it.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/ja.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/ko.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/ms.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/nl.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/pl.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/pt-BR.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/pt.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/ro.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/ru.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/sk.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/tr.lproj/TOCropViewControllerLocalizable.strings +9 -0
- package/ios/TOCropViewController/Resources/uk.lproj/TOCropViewControllerLocalizable.strings +8 -0
- package/ios/TOCropViewController/Resources/vi.lproj/TOCropViewControllerLocalizable.strings +9 -0
- package/ios/TOCropViewController/Resources/zh-Hans.lproj/TOCropViewControllerLocalizable.strings +9 -0
- package/ios/TOCropViewController/Resources/zh-Hant.lproj/TOCropViewControllerLocalizable.strings +9 -0
- package/ios/TOCropViewController/TOCropViewController.h +479 -0
- package/ios/TOCropViewController/TOCropViewController.m +1355 -0
- package/ios/TOCropViewController/Views/TOCropOverlayView.h +43 -0
- package/ios/TOCropViewController/Views/TOCropOverlayView.m +240 -0
- package/ios/TOCropViewController/Views/TOCropScrollView.h +39 -0
- package/ios/TOCropViewController/Views/TOCropScrollView.m +48 -0
- package/ios/TOCropViewController/Views/TOCropToolbar.h +104 -0
- package/ios/TOCropViewController/Views/TOCropToolbar.m +783 -0
- package/ios/TOCropViewController/Views/TOCropView.h +311 -0
- package/ios/TOCropViewController/Views/TOCropView.m +1787 -0
- package/lib/module/ReactNativeImageCropPicker.nitro.js +4 -0
- package/lib/module/ReactNativeImageCropPicker.nitro.js.map +1 -0
- package/lib/module/index.js +83 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/ReactNativeImageCropPicker.nitro.d.ts +54 -0
- package/lib/typescript/src/ReactNativeImageCropPicker.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +31 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/nitro.json +23 -0
- package/nitrogen/generated/android/c++/JCropRect.hpp +69 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeImageCropPickerSpec.cpp +125 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeImageCropPickerSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JImageCropPickerOptions.hpp +154 -0
- package/nitrogen/generated/android/c++/JPickedImage.hpp +88 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativeimagecroppicker/CropRect.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativeimagecroppicker/HybridReactNativeImageCropPickerSpec.kt +69 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativeimagecroppicker/ImageCropPickerOptions.kt +171 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativeimagecroppicker/PickedImage.kt +86 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativeimagecroppicker/reactnativeimagecroppickerOnLoad.kt +35 -0
- package/nitrogen/generated/android/reactnativeimagecroppicker+autolinking.cmake +81 -0
- package/nitrogen/generated/android/reactnativeimagecroppicker+autolinking.gradle +27 -0
- package/nitrogen/generated/android/reactnativeimagecroppickerOnLoad.cpp +54 -0
- package/nitrogen/generated/android/reactnativeimagecroppickerOnLoad.hpp +34 -0
- package/nitrogen/generated/ios/ReactNativeImageCropPicker+autolinking.rb +62 -0
- package/nitrogen/generated/ios/ReactNativeImageCropPicker-Swift-Cxx-Bridge.cpp +57 -0
- package/nitrogen/generated/ios/ReactNativeImageCropPicker-Swift-Cxx-Bridge.hpp +221 -0
- package/nitrogen/generated/ios/ReactNativeImageCropPicker-Swift-Cxx-Umbrella.hpp +55 -0
- package/nitrogen/generated/ios/ReactNativeImageCropPickerAutolinking.mm +33 -0
- package/nitrogen/generated/ios/ReactNativeImageCropPickerAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeImageCropPickerSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeImageCropPickerSpecSwift.hpp +116 -0
- package/nitrogen/generated/ios/swift/CropRect.swift +44 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_PickedImage.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeImageCropPickerSpec.swift +58 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeImageCropPickerSpec_cxx.swift +202 -0
- package/nitrogen/generated/ios/swift/ImageCropPickerOptions.swift +474 -0
- package/nitrogen/generated/ios/swift/PickedImage.swift +96 -0
- package/nitrogen/generated/shared/c++/CropRect.hpp +95 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeImageCropPickerSpec.cpp +24 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeImageCropPickerSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/ImageCropPickerOptions.hpp +180 -0
- package/nitrogen/generated/shared/c++/PickedImage.hpp +114 -0
- package/package.json +173 -0
- package/src/ReactNativeImageCropPicker.nitro.ts +72 -0
- package/src/index.tsx +134 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//
|
|
2
|
+
// TOCropOverlayView.h
|
|
3
|
+
//
|
|
4
|
+
// Copyright 2015-2026 Timothy Oliver. All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to
|
|
8
|
+
// deal in the Software without restriction, including without limitation the
|
|
9
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
10
|
+
// sell copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in
|
|
14
|
+
// all copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
17
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
21
|
+
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
#import <UIKit/UIKit.h>
|
|
24
|
+
|
|
25
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
26
|
+
|
|
27
|
+
@interface TOCropOverlayView : UIView
|
|
28
|
+
|
|
29
|
+
/** Hides the interior grid lines, sans animation. */
|
|
30
|
+
@property (nonatomic, assign) BOOL gridHidden;
|
|
31
|
+
|
|
32
|
+
/** Add/Remove the interior horizontal grid lines. */
|
|
33
|
+
@property (nonatomic, assign) BOOL displayHorizontalGridLines;
|
|
34
|
+
|
|
35
|
+
/** Add/Remove the interior vertical grid lines. */
|
|
36
|
+
@property (nonatomic, assign) BOOL displayVerticalGridLines;
|
|
37
|
+
|
|
38
|
+
/** Shows and hides the interior grid lines with an optional crossfade animation. */
|
|
39
|
+
- (void)setGridHidden:(BOOL)hidden animated:(BOOL)animated;
|
|
40
|
+
|
|
41
|
+
@end
|
|
42
|
+
|
|
43
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
//
|
|
2
|
+
// TOCropOverlayView.m
|
|
3
|
+
//
|
|
4
|
+
// Copyright 2015-2026 Timothy Oliver. All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to
|
|
8
|
+
// deal in the Software without restriction, including without limitation the
|
|
9
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
10
|
+
// sell copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in
|
|
14
|
+
// all copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
17
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
21
|
+
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
#import "TOCropOverlayView.h"
|
|
24
|
+
|
|
25
|
+
static const CGFloat kTOCropOverLayerCornerWidth = 20.0f;
|
|
26
|
+
|
|
27
|
+
@interface TOCropOverlayView ()
|
|
28
|
+
|
|
29
|
+
@property (nonatomic, strong) NSArray *horizontalGridLines;
|
|
30
|
+
@property (nonatomic, strong) NSArray *verticalGridLines;
|
|
31
|
+
|
|
32
|
+
@property (nonatomic, strong) NSArray *outerLineViews; // top, right, bottom, left
|
|
33
|
+
|
|
34
|
+
@property (nonatomic, strong) NSArray *topLeftLineViews; // vertical, horizontal
|
|
35
|
+
@property (nonatomic, strong) NSArray *bottomLeftLineViews;
|
|
36
|
+
@property (nonatomic, strong) NSArray *bottomRightLineViews;
|
|
37
|
+
@property (nonatomic, strong) NSArray *topRightLineViews;
|
|
38
|
+
|
|
39
|
+
@end
|
|
40
|
+
|
|
41
|
+
@implementation TOCropOverlayView
|
|
42
|
+
|
|
43
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
44
|
+
if (self = [super initWithFrame:frame]) {
|
|
45
|
+
self.clipsToBounds = NO;
|
|
46
|
+
[self setup];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return self;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
- (void)setup {
|
|
53
|
+
UIView * (^newLineView)(void) = ^UIView *(void) {
|
|
54
|
+
return [self createNewLineView];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
_outerLineViews = @[newLineView(), newLineView(), newLineView(), newLineView()];
|
|
58
|
+
|
|
59
|
+
_topLeftLineViews = @[newLineView(), newLineView()];
|
|
60
|
+
_bottomLeftLineViews = @[newLineView(), newLineView()];
|
|
61
|
+
_topRightLineViews = @[newLineView(), newLineView()];
|
|
62
|
+
_bottomRightLineViews = @[newLineView(), newLineView()];
|
|
63
|
+
|
|
64
|
+
self.displayHorizontalGridLines = YES;
|
|
65
|
+
self.displayVerticalGridLines = YES;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
- (void)setFrame:(CGRect)frame {
|
|
69
|
+
[super setFrame:frame];
|
|
70
|
+
if (_outerLineViews) {
|
|
71
|
+
[self layoutLines];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
- (void)didMoveToSuperview {
|
|
76
|
+
[super didMoveToSuperview];
|
|
77
|
+
if (_outerLineViews) {
|
|
78
|
+
[self layoutLines];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
- (void)layoutLines {
|
|
83
|
+
CGSize boundsSize = self.bounds.size;
|
|
84
|
+
|
|
85
|
+
// border lines
|
|
86
|
+
for (NSInteger i = 0; i < 4; i++) {
|
|
87
|
+
UIView *lineView = self.outerLineViews[i];
|
|
88
|
+
|
|
89
|
+
CGRect frame = CGRectZero;
|
|
90
|
+
switch (i) {
|
|
91
|
+
case 0:
|
|
92
|
+
frame = (CGRect){-1.0f, -1.0f, boundsSize.width + 2.0f, 1.0f};
|
|
93
|
+
break; // top
|
|
94
|
+
case 1:
|
|
95
|
+
frame = (CGRect){boundsSize.width, 0.0f, 1.0f, boundsSize.height};
|
|
96
|
+
break; // right
|
|
97
|
+
case 2:
|
|
98
|
+
frame = (CGRect){-1.0f, boundsSize.height, boundsSize.width + 2.0f, 1.0f};
|
|
99
|
+
break; // bottom
|
|
100
|
+
case 3:
|
|
101
|
+
frame = (CGRect){-1.0f, 0, 1.0f, boundsSize.height + 1.0f};
|
|
102
|
+
break; // left
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
lineView.frame = frame;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// corner liness
|
|
109
|
+
NSArray *cornerLines = @[self.topLeftLineViews, self.topRightLineViews, self.bottomRightLineViews, self.bottomLeftLineViews];
|
|
110
|
+
for (NSInteger i = 0; i < 4; i++) {
|
|
111
|
+
NSArray *cornerLine = cornerLines[i];
|
|
112
|
+
|
|
113
|
+
CGRect verticalFrame = CGRectZero, horizontalFrame = CGRectZero;
|
|
114
|
+
switch (i) {
|
|
115
|
+
case 0: // top left
|
|
116
|
+
verticalFrame = (CGRect){-3.0f, -3.0f, 3.0f, kTOCropOverLayerCornerWidth + 3.0f};
|
|
117
|
+
horizontalFrame = (CGRect){0, -3.0f, kTOCropOverLayerCornerWidth, 3.0f};
|
|
118
|
+
break;
|
|
119
|
+
case 1: // top right
|
|
120
|
+
verticalFrame = (CGRect){boundsSize.width, -3.0f, 3.0f, kTOCropOverLayerCornerWidth + 3.0f};
|
|
121
|
+
horizontalFrame = (CGRect){boundsSize.width - kTOCropOverLayerCornerWidth, -3.0f, kTOCropOverLayerCornerWidth, 3.0f};
|
|
122
|
+
break;
|
|
123
|
+
case 2: // bottom right
|
|
124
|
+
verticalFrame = (CGRect){boundsSize.width, boundsSize.height - kTOCropOverLayerCornerWidth, 3.0f, kTOCropOverLayerCornerWidth + 3.0f};
|
|
125
|
+
horizontalFrame = (CGRect){boundsSize.width - kTOCropOverLayerCornerWidth, boundsSize.height, kTOCropOverLayerCornerWidth, 3.0f};
|
|
126
|
+
break;
|
|
127
|
+
case 3: // bottom left
|
|
128
|
+
verticalFrame = (CGRect){-3.0f, boundsSize.height - kTOCropOverLayerCornerWidth, 3.0f, kTOCropOverLayerCornerWidth};
|
|
129
|
+
horizontalFrame = (CGRect){-3.0f, boundsSize.height, kTOCropOverLayerCornerWidth + 3.0f, 3.0f};
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
[cornerLine[0] setFrame:verticalFrame];
|
|
134
|
+
[cornerLine[1] setFrame:horizontalFrame];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// grid lines - horizontal
|
|
138
|
+
// (displayScale can be 0 before the view joins a window)
|
|
139
|
+
CGFloat thickness = 1.0f / MAX(1.0f, self.traitCollection.displayScale);
|
|
140
|
+
NSInteger numberOfLines = self.horizontalGridLines.count;
|
|
141
|
+
CGFloat padding = (CGRectGetHeight(self.bounds) - (thickness * numberOfLines)) / (numberOfLines + 1);
|
|
142
|
+
for (NSInteger i = 0; i < numberOfLines; i++) {
|
|
143
|
+
UIView *lineView = self.horizontalGridLines[i];
|
|
144
|
+
CGRect frame = CGRectZero;
|
|
145
|
+
frame.size.height = thickness;
|
|
146
|
+
frame.size.width = CGRectGetWidth(self.bounds);
|
|
147
|
+
frame.origin.y = (padding * (i + 1)) + (thickness * i);
|
|
148
|
+
lineView.frame = frame;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// grid lines - vertical
|
|
152
|
+
numberOfLines = self.verticalGridLines.count;
|
|
153
|
+
padding = (CGRectGetWidth(self.bounds) - (thickness * numberOfLines)) / (numberOfLines + 1);
|
|
154
|
+
for (NSInteger i = 0; i < numberOfLines; i++) {
|
|
155
|
+
UIView *lineView = self.verticalGridLines[i];
|
|
156
|
+
CGRect frame = CGRectZero;
|
|
157
|
+
frame.size.width = thickness;
|
|
158
|
+
frame.size.height = CGRectGetHeight(self.bounds);
|
|
159
|
+
frame.origin.x = (padding * (i + 1)) + (thickness * i);
|
|
160
|
+
lineView.frame = frame;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
- (void)setGridHidden:(BOOL)hidden animated:(BOOL)animated {
|
|
165
|
+
_gridHidden = hidden;
|
|
166
|
+
|
|
167
|
+
if (animated == NO) {
|
|
168
|
+
for (UIView *lineView in self.horizontalGridLines) {
|
|
169
|
+
lineView.alpha = hidden ? 0.0f : 1.0f;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
for (UIView *lineView in self.verticalGridLines) {
|
|
173
|
+
lineView.alpha = hidden ? 0.0f : 1.0f;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
[UIView animateWithDuration:hidden ? 0.35f : 0.2f
|
|
180
|
+
animations:^{
|
|
181
|
+
for (UIView *lineView in self.horizontalGridLines)
|
|
182
|
+
lineView.alpha = hidden ? 0.0f : 1.0f;
|
|
183
|
+
|
|
184
|
+
for (UIView *lineView in self.verticalGridLines)
|
|
185
|
+
lineView.alpha = hidden ? 0.0f : 1.0f;
|
|
186
|
+
}];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
#pragma mark - Property methods
|
|
190
|
+
|
|
191
|
+
- (void)setDisplayHorizontalGridLines:(BOOL)displayHorizontalGridLines {
|
|
192
|
+
_displayHorizontalGridLines = displayHorizontalGridLines;
|
|
193
|
+
|
|
194
|
+
[self.horizontalGridLines enumerateObjectsUsingBlock:^(UIView *__nonnull lineView, NSUInteger idx, BOOL *__nonnull stop) {
|
|
195
|
+
[lineView removeFromSuperview];
|
|
196
|
+
}];
|
|
197
|
+
|
|
198
|
+
if (_displayHorizontalGridLines) {
|
|
199
|
+
self.horizontalGridLines = @[[self createNewLineView], [self createNewLineView]];
|
|
200
|
+
} else {
|
|
201
|
+
self.horizontalGridLines = @[];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Re-apply the current visibility to the rebuilt lines and lay them out
|
|
205
|
+
[self setGridHidden:_gridHidden animated:NO];
|
|
206
|
+
[self layoutLines];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
- (void)setDisplayVerticalGridLines:(BOOL)displayVerticalGridLines {
|
|
210
|
+
_displayVerticalGridLines = displayVerticalGridLines;
|
|
211
|
+
|
|
212
|
+
[self.verticalGridLines enumerateObjectsUsingBlock:^(UIView *__nonnull lineView, NSUInteger idx, BOOL *__nonnull stop) {
|
|
213
|
+
[lineView removeFromSuperview];
|
|
214
|
+
}];
|
|
215
|
+
|
|
216
|
+
if (_displayVerticalGridLines) {
|
|
217
|
+
self.verticalGridLines = @[[self createNewLineView], [self createNewLineView]];
|
|
218
|
+
} else {
|
|
219
|
+
self.verticalGridLines = @[];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Re-apply the current visibility to the rebuilt lines and lay them out
|
|
223
|
+
[self setGridHidden:_gridHidden animated:NO];
|
|
224
|
+
[self layoutLines];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
- (void)setGridHidden:(BOOL)gridHidden {
|
|
228
|
+
[self setGridHidden:gridHidden animated:NO];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
#pragma mark - Private methods
|
|
232
|
+
|
|
233
|
+
- (nonnull UIView *)createNewLineView {
|
|
234
|
+
UIView *newLine = [[UIView alloc] initWithFrame:CGRectZero];
|
|
235
|
+
newLine.backgroundColor = [UIColor whiteColor];
|
|
236
|
+
[self addSubview:newLine];
|
|
237
|
+
return newLine;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
@end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//
|
|
2
|
+
// TOCropScrollView
|
|
3
|
+
//
|
|
4
|
+
// Copyright 2015-2026 Timothy Oliver. All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to
|
|
8
|
+
// deal in the Software without restriction, including without limitation the
|
|
9
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
10
|
+
// sell copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in
|
|
14
|
+
// all copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
17
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
21
|
+
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
#import <UIKit/UIKit.h>
|
|
24
|
+
|
|
25
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
Subclassing UIScrollView was necessary in order to directly capture
|
|
29
|
+
touch events that weren't otherwise accessible via UIGestureRecognizer objects.
|
|
30
|
+
*/
|
|
31
|
+
@interface TOCropScrollView : UIScrollView
|
|
32
|
+
|
|
33
|
+
@property (nullable, nonatomic, copy) void (^touchesBegan)(void);
|
|
34
|
+
@property (nullable, nonatomic, copy) void (^touchesCancelled)(void);
|
|
35
|
+
@property (nullable, nonatomic, copy) void (^touchesEnded)(void);
|
|
36
|
+
|
|
37
|
+
@end
|
|
38
|
+
|
|
39
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//
|
|
2
|
+
// TOCropScrollView
|
|
3
|
+
//
|
|
4
|
+
// Copyright 2015-2026 Timothy Oliver. All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to
|
|
8
|
+
// deal in the Software without restriction, including without limitation the
|
|
9
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
10
|
+
// sell copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in
|
|
14
|
+
// all copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
17
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
21
|
+
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
#import "TOCropScrollView.h"
|
|
24
|
+
|
|
25
|
+
@implementation TOCropScrollView
|
|
26
|
+
|
|
27
|
+
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
|
28
|
+
if (self.touchesBegan)
|
|
29
|
+
self.touchesBegan();
|
|
30
|
+
|
|
31
|
+
[super touchesBegan:touches withEvent:event];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
|
35
|
+
if (self.touchesEnded)
|
|
36
|
+
self.touchesEnded();
|
|
37
|
+
|
|
38
|
+
[super touchesEnded:touches withEvent:event];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
|
|
42
|
+
if (self.touchesCancelled)
|
|
43
|
+
self.touchesCancelled();
|
|
44
|
+
|
|
45
|
+
[super touchesCancelled:touches withEvent:event];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
//
|
|
2
|
+
// TOCropToolbar.h
|
|
3
|
+
//
|
|
4
|
+
// Copyright 2015-2026 Timothy Oliver. All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to
|
|
8
|
+
// deal in the Software without restriction, including without limitation the
|
|
9
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
10
|
+
// sell copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in
|
|
14
|
+
// all copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
17
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
21
|
+
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
#import <UIKit/UIKit.h>
|
|
24
|
+
|
|
25
|
+
#if !__has_include(<TOCropViewController/TOCropViewConstants.h>)
|
|
26
|
+
#import "TOCropViewConstants.h"
|
|
27
|
+
#else
|
|
28
|
+
#import <TOCropViewController/TOCropViewConstants.h>
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
32
|
+
|
|
33
|
+
@interface TOCropToolbar : UIView
|
|
34
|
+
|
|
35
|
+
/* In horizontal mode, offsets all of the buttons vertically by height of status bar. */
|
|
36
|
+
@property (nonatomic, assign) CGFloat statusBarHeightInset;
|
|
37
|
+
|
|
38
|
+
/* Set an inset that will expand the background view beyond the bounds. */
|
|
39
|
+
@property (nonatomic, assign) UIEdgeInsets backgroundViewOutsets;
|
|
40
|
+
|
|
41
|
+
/* The 'Done' buttons to commit the crop. The text button is displayed
|
|
42
|
+
in portrait mode and the icon one, in landscape.
|
|
43
|
+
The text button is nil on iOS 26 and up, where the toolbar is always icon-only. */
|
|
44
|
+
@property (nullable, nonatomic, strong, readonly) UIButton *doneTextButton;
|
|
45
|
+
@property (nonatomic, strong, readonly) UIButton *doneIconButton;
|
|
46
|
+
@property (nonatomic, copy) NSString *doneTextButtonTitle;
|
|
47
|
+
@property (null_resettable, nonatomic, copy) UIColor *doneButtonColor;
|
|
48
|
+
|
|
49
|
+
/* The 'Cancel' buttons to cancel the crop. The text button is displayed
|
|
50
|
+
in portrait mode and the icon one, in landscape.
|
|
51
|
+
The text button is nil on iOS 26 and up, where the toolbar is always icon-only. */
|
|
52
|
+
@property (nullable, nonatomic, strong, readonly) UIButton *cancelTextButton;
|
|
53
|
+
@property (nonatomic, strong, readonly) UIButton *cancelIconButton;
|
|
54
|
+
@property (nonatomic, readonly) UIView *visibleCancelButton;
|
|
55
|
+
@property (nonatomic, copy) NSString *cancelTextButtonTitle;
|
|
56
|
+
@property (nullable, nonatomic, copy) UIColor *cancelButtonColor;
|
|
57
|
+
|
|
58
|
+
/* Show the tick and cross buttons instead of 'Done' and 'Cancel'.
|
|
59
|
+
Always YES, and not settable, on iOS 26 and up. */
|
|
60
|
+
@property (nonatomic, assign) BOOL showOnlyIcons API_DEPRECATED("iOS 26 uses icons only", ios(7.0, 18.0));
|
|
61
|
+
|
|
62
|
+
/* The cropper control buttons */
|
|
63
|
+
@property (nonatomic, strong, readonly) UIButton *rotateCounterclockwiseButton;
|
|
64
|
+
@property (nonatomic, strong, readonly) UIButton *resetButton;
|
|
65
|
+
@property (nonatomic, strong, readonly) UIButton *clampButton;
|
|
66
|
+
@property (nullable, nonatomic, strong, readonly) UIButton *rotateClockwiseButton;
|
|
67
|
+
|
|
68
|
+
/* Set the rotation buttons to be disabled while rotating is in progress */
|
|
69
|
+
@property (nonatomic, assign) BOOL disableRotationButtons;
|
|
70
|
+
|
|
71
|
+
@property (nonatomic, readonly) UIButton *rotateButton; // Points to `rotateCounterClockwiseButton`
|
|
72
|
+
|
|
73
|
+
/* Button feedback handler blocks */
|
|
74
|
+
@property (nullable, nonatomic, copy) void (^cancelButtonTapped)(void);
|
|
75
|
+
@property (nullable, nonatomic, copy) void (^doneButtonTapped)(void);
|
|
76
|
+
@property (nullable, nonatomic, copy) void (^rotateCounterclockwiseButtonTapped)(void);
|
|
77
|
+
@property (nullable, nonatomic, copy) void (^rotateClockwiseButtonTapped)(void);
|
|
78
|
+
@property (nullable, nonatomic, copy) void (^clampButtonTapped)(void);
|
|
79
|
+
@property (nullable, nonatomic, copy) void (^resetButtonTapped)(void);
|
|
80
|
+
|
|
81
|
+
/* State management for the 'clamp' button */
|
|
82
|
+
@property (nonatomic, assign) BOOL clampButtonGlowing;
|
|
83
|
+
@property (nonatomic, readonly) CGRect clampButtonFrame;
|
|
84
|
+
|
|
85
|
+
/* Aspect ratio button visibility settings */
|
|
86
|
+
@property (nonatomic, assign) BOOL clampButtonHidden;
|
|
87
|
+
@property (nonatomic, assign) BOOL rotateCounterclockwiseButtonHidden;
|
|
88
|
+
@property (nonatomic, assign) BOOL rotateClockwiseButtonHidden;
|
|
89
|
+
@property (nonatomic, assign) BOOL resetButtonHidden;
|
|
90
|
+
@property (nonatomic, assign) BOOL doneButtonHidden;
|
|
91
|
+
@property (nonatomic, assign) BOOL cancelButtonHidden;
|
|
92
|
+
|
|
93
|
+
/* For languages like Arabic where they natively present content flipped from English */
|
|
94
|
+
@property (nonatomic, assign) BOOL reverseContentLayout;
|
|
95
|
+
|
|
96
|
+
/* Enable the reset button */
|
|
97
|
+
@property (nonatomic, assign) BOOL resetButtonEnabled;
|
|
98
|
+
|
|
99
|
+
/* Done button frame for popover controllers */
|
|
100
|
+
@property (nonatomic, readonly) CGRect doneButtonFrame;
|
|
101
|
+
|
|
102
|
+
@end
|
|
103
|
+
|
|
104
|
+
NS_ASSUME_NONNULL_END
|