diff --git a/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift b/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift index cb179cc56..398c3e2c3 100644 --- a/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift +++ b/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift @@ -1324,12 +1324,19 @@ extension AttachmentPrepViewController: UIScrollViewDelegate { // MARK: - extension AttachmentPrepViewController: ImageEditorViewDelegate { - public func imageEditor(presentFullScreenOverlay viewController: UIViewController) { - - let navigationController = OWSNavigationController(rootViewController: viewController) - navigationController.modalPresentationStyle = .overFullScreen - self.present(navigationController, animated: true) { - // Do nothing. + public func imageEditor(presentFullScreenOverlay viewController: UIViewController, + withNavigation: Bool) { + + if withNavigation { + let navigationController = OWSNavigationController(rootViewController: viewController) + navigationController.modalPresentationStyle = .overFullScreen + self.present(navigationController, animated: true) { + // Do nothing. + } + } else { + self.present(viewController, animated: true) { + // Do nothing. + } } } } diff --git a/SignalMessaging/Views/ImageEditor/ImageEditorCropViewController.swift b/SignalMessaging/Views/ImageEditor/ImageEditorCropViewController.swift index 59a2d998e..014981652 100644 --- a/SignalMessaging/Views/ImageEditor/ImageEditorCropViewController.swift +++ b/SignalMessaging/Views/ImageEditor/ImageEditorCropViewController.swift @@ -83,23 +83,42 @@ class ImageEditorCropViewController: OWSViewController { self.view.backgroundColor = .black - let stackView = UIStackView() - stackView.axis = .vertical - stackView.alignment = .fill - stackView.spacing = 16 - stackView.layoutMargins = UIEdgeInsets(top: 16, left: 20, bottom: 16, right: 20) - stackView.isLayoutMarginsRelativeArrangement = true - self.view.addSubview(stackView) - stackView.ows_autoPinToSuperviewEdges() + // MARK: - Buttons - navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, - target: self, - action: #selector(didTapBackButton)) + // TODO: Apply icons. + let doneButton = OWSButton(title: "Done") { [weak self] in + self?.didTapBackButton() + } + let rotate90Button = OWSButton(title: "Rotate 90°") { [weak self] in + self?.rotate90ButtonPressed() + } + let rotate45Button = OWSButton(title: "Rotate 45°") { [weak self] in + self?.rotate45ButtonPressed() + } + let resetButton = OWSButton(title: "Reset") { [weak self] in + self?.resetButtonPressed() + } + let zoom2xButton = OWSButton(title: "Zoom 2x") { [weak self] in + self?.zoom2xButtonPressed() + } + + // MARK: - Header + + let header = UIStackView(arrangedSubviews: [ + UIView.hStretchingSpacer(), + resetButton, + doneButton + ]) + header.axis = .horizontal + header.spacing = 16 + header.backgroundColor = .clear + header.isOpaque = false + + // MARK: - Canvas & Wrapper let wrapperView = UIView.container() wrapperView.backgroundColor = .clear wrapperView.isOpaque = false - stackView.addArrangedSubview(wrapperView) // TODO: We could mask the clipped region with a semi-transparent overlay like WA. clipView.clipsToBounds = true @@ -127,33 +146,35 @@ class ImageEditorCropViewController: OWSViewController { clipView.addSubview(contentView) contentView.ows_autoPinToSuperviewEdges() - let rotate90Button = OWSButton() - rotate90Button.setTitle(NSLocalizedString("IMAGE_EDITOR_ROTATE_90_BUTTON", comment: "Label for button that rotates image 90 degrees."), - for: .normal) - rotate90Button.block = { [weak self] in - self?.rotate90ButtonPressed() - } + // MARK: - Footer - let rotate45Button = OWSButton() - rotate45Button.setTitle(NSLocalizedString("IMAGE_EDITOR_ROTATE_45_BUTTON", comment: "Label for button that rotates image 45 degrees."), - for: .normal) - rotate45Button.block = { [weak self] in - self?.rotate45ButtonPressed() - } + let footer = UIStackView(arrangedSubviews: [ + rotate90Button, + rotate45Button, + UIView.hStretchingSpacer(), + zoom2xButton + ]) + footer.axis = .horizontal + footer.spacing = 16 + footer.backgroundColor = .clear + footer.isOpaque = false - let resetButton = OWSButton() - resetButton.setTitle(NSLocalizedString("IMAGE_EDITOR_RESET_BUTTON", comment: "Label for button that resets crop & rotation state."), - for: .normal) - resetButton.block = { [weak self] in - self?.resetButtonPressed() - } + let stackView = UIStackView(arrangedSubviews: [ + header, + wrapperView, + footer + ]) + stackView.axis = .vertical + stackView.alignment = .fill + stackView.spacing = 24 + stackView.layoutMargins = UIEdgeInsets(top: 16, left: 20, bottom: 16, right: 20) + stackView.isLayoutMarginsRelativeArrangement = true + self.view.addSubview(stackView) + stackView.ows_autoPinToSuperviewEdges() - let zoom2xButton = OWSButton() - zoom2xButton.setTitle("Zoom 2x", - for: .normal) - zoom2xButton.block = { [weak self] in - self?.zoom2xButtonPressed() - } + // MARK: - Crop View + + // Add crop view last so that it appears in front of the content. cropView.setContentHuggingLow() cropView.setCompressionResistanceLow() @@ -166,8 +187,8 @@ class ImageEditorCropViewController: OWSViewController { cropCornerView.autoPinEdge(toSuperviewEdge: .left) case .topRight, .bottomRight: cropCornerView.autoPinEdge(toSuperviewEdge: .right) - default: - owsFailDebug("Invalid crop region: \(cropRegion)") + default: + owsFailDebug("Invalid crop region: \(cropRegion)") } switch cropCornerView.cropRegion { case .topLeft, .topRight: @@ -179,13 +200,6 @@ class ImageEditorCropViewController: OWSViewController { } } - let footer = UIStackView(arrangedSubviews: [rotate90Button, rotate45Button, resetButton, zoom2xButton]) - footer.axis = .horizontal - footer.spacing = 16 - footer.backgroundColor = .clear - footer.isOpaque = false - stackView.addArrangedSubview(footer) - setCropViewAppearance() updateClipViewLayout() diff --git a/SignalMessaging/Views/ImageEditor/ImageEditorView.swift b/SignalMessaging/Views/ImageEditor/ImageEditorView.swift index 187a55c3b..a91427d4e 100644 --- a/SignalMessaging/Views/ImageEditor/ImageEditorView.swift +++ b/SignalMessaging/Views/ImageEditor/ImageEditorView.swift @@ -6,7 +6,8 @@ import UIKit @objc public protocol ImageEditorViewDelegate: class { - func imageEditor(presentFullScreenOverlay viewController: UIViewController) + func imageEditor(presentFullScreenOverlay viewController: UIViewController, + withNavigation: Bool) } // MARK: - @@ -571,7 +572,8 @@ public class ImageEditorView: UIView { // let maxTextWidthPoints = canvasView.imageView.width() * ImageEditorTextItem.kDefaultUnitWidth let textEditor = ImageEditorTextViewController(delegate: self, textItem: textItem, maxTextWidthPoints: maxTextWidthPoints) - self.delegate?.imageEditor(presentFullScreenOverlay: textEditor) + self.delegate?.imageEditor(presentFullScreenOverlay: textEditor, + withNavigation: true) } // MARK: - Crop Tool @@ -596,7 +598,8 @@ public class ImageEditorView: UIView { } let cropTool = ImageEditorCropViewController(delegate: self, model: model, srcImage: srcImage, previewImage: previewImage) - self.delegate?.imageEditor(presentFullScreenOverlay: cropTool) + self.delegate?.imageEditor(presentFullScreenOverlay: cropTool, + withNavigation: false) }} // MARK: - diff --git a/SignalMessaging/Views/OWSButton.swift b/SignalMessaging/Views/OWSButton.swift index 9d51bf99d..03ffdf0a0 100644 --- a/SignalMessaging/Views/OWSButton.swift +++ b/SignalMessaging/Views/OWSButton.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // import UIKit @@ -15,8 +15,18 @@ public class OWSButton: UIButton { @objc init(block: @escaping () -> Void = { }) { super.init(frame: .zero) + + self.block = block + addTarget(self, action: #selector(didTap), for: .touchUpInside) + } + + @objc + init(title: String, block: @escaping () -> Void = { }) { + super.init(frame: .zero) + self.block = block - self.addTarget(self, action: #selector(didTap), for: .touchUpInside) + addTarget(self, action: #selector(didTap), for: .touchUpInside) + setTitle(title, for: .normal) } public required init?(coder aDecoder: NSCoder) {