Skip to content

Commit

Permalink
feat: add showAttachedCropToolbar option to CropToolbarConfig (#177)
Browse files Browse the repository at this point in the history
* feat: add showNativeCropToolbar option to CropToolbarConfig

change CocoaPods deployment target 13.0
update an example to show showNativeCropToolbar's support
remove some unnecessary self

* feat: support 11.0 again

rename showBottomCropToolbar to showAttachedCropToolbar

* refactor: make CropToolbar buttons lazy vars

add getCancelIcon and getCropIcon to CropToolbarIconProvider protocol
  • Loading branch information
guoyingtao committed Jul 12, 2022
1 parent eaa8f06 commit 417f607
Show file tree
Hide file tree
Showing 13 changed files with 461 additions and 127 deletions.
4 changes: 4 additions & 0 deletions Example/MantisExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
5FC10B2A217A9EE100582874 /* MantisTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC10B29217A9EE100582874 /* MantisTests.swift */; };
5FD045EA245619D400B9D3D2 /* CustomizedCropToolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FD045E9245619D400B9D3D2 /* CustomizedCropToolbar.swift */; };
5FEBA88221961E4A0018DE62 /* EmbeddedCropViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FEBA88121961E4A0018DE62 /* EmbeddedCropViewController.swift */; };
66F909BD287B601A007E2FC6 /* MyNavigationCropToolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66F909BC287B601A007E2FC6 /* MyNavigationCropToolbar.swift */; };
CCBF2F602525B3050081B8FE /* CustomizedCropToolbarWithoutList.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCBF2F5F2525B3050081B8FE /* CustomizedCropToolbarWithoutList.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -51,6 +52,7 @@
5FD045E9245619D400B9D3D2 /* CustomizedCropToolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomizedCropToolbar.swift; sourceTree = "<group>"; };
5FEBA88121961E4A0018DE62 /* EmbeddedCropViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmbeddedCropViewController.swift; sourceTree = "<group>"; };
61C386518C3C25E57F8C83A5 /* Pods-MantisExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MantisExampleTests.release.xcconfig"; path = "Target Support Files/Pods-MantisExampleTests/Pods-MantisExampleTests.release.xcconfig"; sourceTree = "<group>"; };
66F909BC287B601A007E2FC6 /* MyNavigationCropToolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyNavigationCropToolbar.swift; sourceTree = "<group>"; };
89C5370690AB91AB238B90E9 /* Pods-MantisExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MantisExample.release.xcconfig"; path = "Target Support Files/Pods-MantisExample/Pods-MantisExample.release.xcconfig"; sourceTree = "<group>"; };
9326C1CDF121300C5CAAE2BE /* Pods-MantisExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MantisExample.debug.xcconfig"; path = "Target Support Files/Pods-MantisExample/Pods-MantisExample.debug.xcconfig"; sourceTree = "<group>"; };
B100014666B3974EEDE05B0C /* Pods_MantisExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MantisExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -89,6 +91,7 @@
5FC10B08217A9EDF00582874 = {
isa = PBXGroup;
children = (
66F909BC287B601A007E2FC6 /* MyNavigationCropToolbar.swift */,
5F90A3CA23DCEBE800D9F27E /* MantisExample.entitlements */,
5F0852B4237918510031B75D /* ImagePicker.swift */,
5FC10B14217A9EDF00582874 /* AppDelegate.swift */,
Expand Down Expand Up @@ -312,6 +315,7 @@
5F0852B5237918510031B75D /* ImagePicker.swift in Sources */,
CCBF2F602525B3050081B8FE /* CustomizedCropToolbarWithoutList.swift in Sources */,
5FEBA88221961E4A0018DE62 /* EmbeddedCropViewController.swift in Sources */,
66F909BD287B601A007E2FC6 /* MyNavigationCropToolbar.swift in Sources */,
5FC10B15217A9EDF00582874 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
59 changes: 59 additions & 0 deletions Example/MyNavigationCropToolbar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// MyNavigationCropToolbar.swift
// MantisExample
//
// Created by Echo on 7/10/22.
// Copyright © 2022 Echo. All rights reserved.
//

import Foundation
import Mantis
import UIKit

class MyNavigationCropToolbar: UIView, CropToolbarProtocol {
var config: CropToolbarConfigProtocol?

var heightForVerticalOrientation: CGFloat?

var widthForHorizonOrientation: CGFloat?

var cropToolbarDelegate: CropToolbarDelegate?

var iconProvider: CropToolbarIconProvider?

weak var cropViewController: Mantis.CropViewController?

func createToolbarUI(config: CropToolbarConfigProtocol?) {
guard let cropViewController = cropViewController else {
return
}

cropViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .close, target: self, action: #selector(cancel))

let rotateButton = UIBarButtonItem(image: UIImage(systemName: "rotate.right"), style: .plain, target: self, action: #selector(rotate))
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(crop))

cropViewController.navigationItem.rightBarButtonItems = [doneButton, rotateButton]
}

func handleFixedRatioSetted(ratio: Double) {

}

func handleFixedRatioUnSetted() {

}

@objc func crop() {
cropToolbarDelegate?.didSelectCrop()
}

@objc func cancel() {
cropToolbarDelegate?.didSelectCancel()
}

@objc func rotate() {
cropToolbarDelegate?.didSelectClockwiseRotate()
}
}

27 changes: 16 additions & 11 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class ViewController: UIViewController, CropViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()

self.imagePicker = ImagePicker(presentationController: self, delegate: self)
imagePicker = ImagePicker(presentationController: self, delegate: self)
}

override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

@IBAction func getImageFromAlbum(_ sender: UIButton) {
self.imagePicker.present(from: sender)
imagePicker.present(from: sender)
}

@IBAction func normalPresent(_ sender: Any) {
Expand Down Expand Up @@ -74,11 +74,18 @@ class ViewController: UIViewController, CropViewControllerDelegate {

var config = Mantis.Config()
config.showRotationDial = false
config.showAttachedCropToolbar = false

let cropViewController = Mantis.cropViewController(image: image, config: config)
cropViewController.modalPresentationStyle = .fullScreen
let cropToolbar = MyNavigationCropToolbar(frame: .zero)
let cropViewController = Mantis.cropViewController(image: image, config: config, cropToolbar: cropToolbar)
cropViewController.delegate = self
present(cropViewController, animated: true)
cropViewController.title = "Change Profile Picture"
let navigationController = UINavigationController(rootViewController: cropViewController)
navigationController.modalPresentationStyle = .fullScreen

cropToolbar.cropViewController = cropViewController

present(navigationController, animated: true)
}

@IBAction func alwayUserOnPresetRatioPresent(_ sender: Any) {
Expand All @@ -94,7 +101,7 @@ class ViewController: UIViewController, CropViewControllerDelegate {
cropViewController.config.presetFixedRatioType = .alwaysUsingOnePresetFixedRatio(ratio: 16.0 / 9.0)
present(cropViewController, animated: true)
}

@IBAction func customizedCropToolbarButtonTouched(_ sender: Any) {
guard let image = image else {
return
Expand All @@ -112,7 +119,6 @@ class ViewController: UIViewController, CropViewControllerDelegate {
cropViewController.modalPresentationStyle = .fullScreen
cropViewController.delegate = self
present(cropViewController, animated: true)

}

@IBAction func customizedCropToolbarWithoutListButtonTouched(_ sender: Any) {
Expand Down Expand Up @@ -250,22 +256,21 @@ class ViewController: UIViewController, CropViewControllerDelegate {
print("transformation is \(transformation)")
print("cropInfo is \(cropInfo)")
croppedImageView.image = cropped
self.dismiss(animated: true)
dismiss(animated: true)
}

func cropViewControllerDidCancel(_ cropViewController: CropViewController, original: UIImage) {
self.dismiss(animated: true)
dismiss(animated: true)
}
}

extension ViewController: ImagePickerDelegate {

func didSelect(image: UIImage?) {
guard let image = image else {
return
}

self.image = image
self.croppedImageView.image = image
croppedImageView.image = image
}
}
2 changes: 1 addition & 1 deletion Mantis.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Pod::Spec.new do |s|
s.social_media_url = "http://twitter.com/guoyingtao"
s.platform = :ios
s.swift_version = "5.0"
s.ios.deployment_target = "13.0"
s.ios.deployment_target = "11.0"
s.source = { :git => "https://github.com/guoyingtao/Mantis.git", :tag => "v#{s.version}" }
s.source_files = "Sources/**/*.{h,swift}"
s.resource_bundles = {
Expand Down
12 changes: 8 additions & 4 deletions Mantis.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
6659429D2877DAE80096A5DB /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6659429C2877DAE80096A5DB /* Config.swift */; };
6659429F2877DC8A0096A5DB /* Enum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6659429E2877DC8A0096A5DB /* Enum.swift */; };
665942A12877DD1C0096A5DB /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = 665942A02877DD1C0096A5DB /* TypeAlias.swift */; };
66F909BF287D22E7007E2FC6 /* ToolBarButtonImageBuilder+DrawImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66F909BE287D22E7007E2FC6 /* ToolBarButtonImageBuilder+DrawImage.swift */; };
8EFB6F6725D16B0F00C0DDB2 /* MantisLocalizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8EFB6F3525D154D900C0DDB2 /* MantisLocalizable.strings */; };
8EFB6FB125D187A000C0DDB2 /* Resource.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 8EFB6F5425D16A9E00C0DDB2 /* Resource.bundle */; };
FEDAAD8625205CC300D95667 /* RatioSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEDAAD8525205CC300D95667 /* RatioSelector.swift */; };
Expand Down Expand Up @@ -104,6 +105,7 @@
6659429C2877DAE80096A5DB /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
6659429E2877DC8A0096A5DB /* Enum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Enum.swift; sourceTree = "<group>"; };
665942A02877DD1C0096A5DB /* TypeAlias.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeAlias.swift; sourceTree = "<group>"; };
66F909BE287D22E7007E2FC6 /* ToolBarButtonImageBuilder+DrawImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ToolBarButtonImageBuilder+DrawImage.swift"; sourceTree = "<group>"; };
8EFB6F3625D154D900C0DDB2 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/MantisLocalizable.strings; sourceTree = "<group>"; };
8EFB6F3725D154D900C0DDB2 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/MantisLocalizable.strings; sourceTree = "<group>"; };
8EFB6F3825D154D900C0DDB2 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/MantisLocalizable.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -229,6 +231,7 @@
OBJ_26 /* FixedRatioManager.swift */,
OBJ_27 /* RatioPresenter.swift */,
OBJ_28 /* ToolBarButtonImageBuilder.swift */,
66F909BE287D22E7007E2FC6 /* ToolBarButtonImageBuilder+DrawImage.swift */,
FEDAAD8525205CC300D95667 /* RatioSelector.swift */,
FEDAAD8B25205DE900D95667 /* RatioItemView.swift */,
);
Expand Down Expand Up @@ -548,6 +551,7 @@
OBJ_71 /* CropMaskViewManager.swift in Sources */,
OBJ_72 /* CropOverlayView.swift in Sources */,
OBJ_73 /* CropScrollView.swift in Sources */,
66F909BF287D22E7007E2FC6 /* ToolBarButtonImageBuilder+DrawImage.swift in Sources */,
OBJ_74 /* CropView+Touches.swift in Sources */,
OBJ_75 /* CropView+UIScrollViewDelegate.swift in Sources */,
OBJ_76 /* CropView.swift in Sources */,
Expand Down Expand Up @@ -831,7 +835,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
ONLY_ACTIVE_ARCH = YES;
OTHER_SWIFT_FLAGS = "$(inherited) -DXcode";
Expand Down Expand Up @@ -885,7 +889,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
OTHER_SWIFT_FLAGS = "$(inherited) -DXcode";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -909,7 +913,7 @@
);
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = Mantis.xcodeproj/Mantis_Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.9.0;
Expand Down Expand Up @@ -940,7 +944,7 @@
);
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = Mantis.xcodeproj/Mantis_Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.9.0;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</p>

## Requirements
* iOS 13.0+
* iOS 11.0+
* MacOS 10.15+
* Xcode 10.0+

Expand Down
1 change: 1 addition & 0 deletions Sources/Mantis/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public struct Config {
public var dialConfig = DialConfig()
public var cropToolbarConfig: CropToolbarConfigProtocol = CropToolbarConfig()
public private(set) var localizationConfig = Mantis.localizationConfig
public var showAttachedCropToolbar = true

var customRatios: [(width: Int, height: Int)] = []

Expand Down

0 comments on commit 417f607

Please sign in to comment.