Update crop view to reflect design.

pull/2/head
Matthew Chen 7 years ago
parent 4db09b45b6
commit 69635fafac

@ -1324,13 +1324,20 @@ extension AttachmentPrepViewController: UIScrollViewDelegate {
// MARK: - // MARK: -
extension AttachmentPrepViewController: ImageEditorViewDelegate { extension AttachmentPrepViewController: ImageEditorViewDelegate {
public func imageEditor(presentFullScreenOverlay viewController: UIViewController) { public func imageEditor(presentFullScreenOverlay viewController: UIViewController,
withNavigation: Bool) {
if withNavigation {
let navigationController = OWSNavigationController(rootViewController: viewController) let navigationController = OWSNavigationController(rootViewController: viewController)
navigationController.modalPresentationStyle = .overFullScreen navigationController.modalPresentationStyle = .overFullScreen
self.present(navigationController, animated: true) { self.present(navigationController, animated: true) {
// Do nothing. // Do nothing.
} }
} else {
self.present(viewController, animated: true) {
// Do nothing.
}
}
} }
} }

@ -83,23 +83,42 @@ class ImageEditorCropViewController: OWSViewController {
self.view.backgroundColor = .black self.view.backgroundColor = .black
let stackView = UIStackView() // MARK: - Buttons
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()
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, // TODO: Apply icons.
target: self, let doneButton = OWSButton(title: "Done") { [weak self] in
action: #selector(didTapBackButton)) 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() let wrapperView = UIView.container()
wrapperView.backgroundColor = .clear wrapperView.backgroundColor = .clear
wrapperView.isOpaque = false wrapperView.isOpaque = false
stackView.addArrangedSubview(wrapperView)
// TODO: We could mask the clipped region with a semi-transparent overlay like WA. // TODO: We could mask the clipped region with a semi-transparent overlay like WA.
clipView.clipsToBounds = true clipView.clipsToBounds = true
@ -127,33 +146,35 @@ class ImageEditorCropViewController: OWSViewController {
clipView.addSubview(contentView) clipView.addSubview(contentView)
contentView.ows_autoPinToSuperviewEdges() contentView.ows_autoPinToSuperviewEdges()
let rotate90Button = OWSButton() // MARK: - Footer
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()
}
let rotate45Button = OWSButton() let footer = UIStackView(arrangedSubviews: [
rotate45Button.setTitle(NSLocalizedString("IMAGE_EDITOR_ROTATE_45_BUTTON", comment: "Label for button that rotates image 45 degrees."), rotate90Button,
for: .normal) rotate45Button,
rotate45Button.block = { [weak self] in UIView.hStretchingSpacer(),
self?.rotate45ButtonPressed() zoom2xButton
} ])
footer.axis = .horizontal
footer.spacing = 16
footer.backgroundColor = .clear
footer.isOpaque = false
let resetButton = OWSButton() let stackView = UIStackView(arrangedSubviews: [
resetButton.setTitle(NSLocalizedString("IMAGE_EDITOR_RESET_BUTTON", comment: "Label for button that resets crop & rotation state."), header,
for: .normal) wrapperView,
resetButton.block = { [weak self] in footer
self?.resetButtonPressed() ])
} 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() // MARK: - Crop View
zoom2xButton.setTitle("Zoom 2x",
for: .normal) // Add crop view last so that it appears in front of the content.
zoom2xButton.block = { [weak self] in
self?.zoom2xButtonPressed()
}
cropView.setContentHuggingLow() cropView.setContentHuggingLow()
cropView.setCompressionResistanceLow() cropView.setCompressionResistanceLow()
@ -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() setCropViewAppearance()
updateClipViewLayout() updateClipViewLayout()

@ -6,7 +6,8 @@ import UIKit
@objc @objc
public protocol ImageEditorViewDelegate: class { public protocol ImageEditorViewDelegate: class {
func imageEditor(presentFullScreenOverlay viewController: UIViewController) func imageEditor(presentFullScreenOverlay viewController: UIViewController,
withNavigation: Bool)
} }
// MARK: - // MARK: -
@ -571,7 +572,8 @@ public class ImageEditorView: UIView {
// let maxTextWidthPoints = canvasView.imageView.width() * ImageEditorTextItem.kDefaultUnitWidth // let maxTextWidthPoints = canvasView.imageView.width() * ImageEditorTextItem.kDefaultUnitWidth
let textEditor = ImageEditorTextViewController(delegate: self, textItem: textItem, maxTextWidthPoints: maxTextWidthPoints) let textEditor = ImageEditorTextViewController(delegate: self, textItem: textItem, maxTextWidthPoints: maxTextWidthPoints)
self.delegate?.imageEditor(presentFullScreenOverlay: textEditor) self.delegate?.imageEditor(presentFullScreenOverlay: textEditor,
withNavigation: true)
} }
// MARK: - Crop Tool // MARK: - Crop Tool
@ -596,7 +598,8 @@ public class ImageEditorView: UIView {
} }
let cropTool = ImageEditorCropViewController(delegate: self, model: model, srcImage: srcImage, previewImage: previewImage) let cropTool = ImageEditorCropViewController(delegate: self, model: model, srcImage: srcImage, previewImage: previewImage)
self.delegate?.imageEditor(presentFullScreenOverlay: cropTool) self.delegate?.imageEditor(presentFullScreenOverlay: cropTool,
withNavigation: false)
}} }}
// MARK: - // MARK: -

@ -1,5 +1,5 @@
// //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
// //
import UIKit import UIKit
@ -15,8 +15,18 @@ public class OWSButton: UIButton {
@objc @objc
init(block: @escaping () -> Void = { }) { init(block: @escaping () -> Void = { }) {
super.init(frame: .zero) 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.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) { public required init?(coder aDecoder: NSCoder) {

Loading…
Cancel
Save