Merge branch 'charlesmchen/imageEditorDesign2'

pull/2/head
Matthew Chen 6 years ago
commit 5091587ed6

@ -48,6 +48,10 @@ class AttachmentItemCollection {
func remove(item: SignalAttachmentItem) { func remove(item: SignalAttachmentItem) {
attachmentItems = attachmentItems.filter { $0 != item } attachmentItems = attachmentItems.filter { $0 != item }
} }
var count: Int {
return attachmentItems.count
}
} }
// MARK: - // MARK: -
@ -618,6 +622,10 @@ extension AttachmentApprovalViewController: AttachmentPrepViewControllerDelegate
func prepViewControllerUpdateNavigationBar() { func prepViewControllerUpdateNavigationBar() {
self.updateNavigationBar() self.updateNavigationBar()
} }
func prepViewControllerAttachmentCount() -> Int {
return attachmentItemCollection.count
}
} }
// MARK: GalleryRail // MARK: GalleryRail
@ -671,6 +679,8 @@ protocol AttachmentPrepViewControllerDelegate: class {
func prepViewController(_ prepViewController: AttachmentPrepViewController, didUpdateCaptionForAttachmentItem attachmentItem: SignalAttachmentItem) func prepViewController(_ prepViewController: AttachmentPrepViewController, didUpdateCaptionForAttachmentItem attachmentItem: SignalAttachmentItem)
func prepViewControllerUpdateNavigationBar() func prepViewControllerUpdateNavigationBar()
func prepViewControllerAttachmentCount() -> Int
} }
public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarDelegate, OWSVideoPlayerDelegate { public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarDelegate, OWSVideoPlayerDelegate {
@ -883,10 +893,52 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
// MARK: - Navigation Bar // MARK: - Navigation Bar
public func navigationBarItems() -> [UIView] { public func navigationBarItems() -> [UIView] {
let captionButton = navigationBarButton(imageName: "image_editor_caption",
selector: #selector(didTapCaption(sender:)))
guard let imageEditorView = imageEditorView else { guard let imageEditorView = imageEditorView else {
// Show the "add caption" button for non-image attachments if
// there is more than one attachment.
if let prepDelegate = prepDelegate,
prepDelegate.prepViewControllerAttachmentCount() > 1 {
return [captionButton]
}
return [] return []
} }
return imageEditorView.navigationBarItems() var navigationBarItems = imageEditorView.navigationBarItems()
// Show the caption UI if there's more than one attachment
// OR if the attachment already has a caption.
var shouldShowCaptionUI = attachmentCount() > 0
if let captionText = attachmentItem.captionText, captionText.count > 0 {
shouldShowCaptionUI = true
}
if shouldShowCaptionUI {
navigationBarItems.append(captionButton)
}
return navigationBarItems
}
private func attachmentCount() -> Int {
guard let prepDelegate = prepDelegate else {
owsFailDebug("Missing prepDelegate.")
return 0
}
return prepDelegate.prepViewControllerAttachmentCount()
}
@objc func didTapCaption(sender: UIButton) {
Logger.verbose("")
presentCaptionView()
}
private func presentCaptionView() {
let view = AttachmentCaptionViewController(delegate: self, attachmentItem: attachmentItem)
self.imageEditor(presentFullScreenView: view, isTransparent: true)
isShowingCaptionView = true
} }
// MARK: - Event Handlers // MARK: - Event Handlers
@ -1132,34 +1184,23 @@ extension AttachmentPrepViewController: UIScrollViewDelegate {
// MARK: - // MARK: -
extension AttachmentPrepViewController: ImageEditorViewDelegate { extension AttachmentPrepViewController: ImageEditorViewDelegate {
public func imageEditor(presentFullScreenOverlay viewController: UIViewController, public func imageEditor(presentFullScreenView viewController: UIViewController,
withNavigation: Bool) { isTransparent: Bool) {
if withNavigation {
let navigationController = OWSNavigationController(rootViewController: viewController)
navigationController.modalPresentationStyle = .overFullScreen
if let navigationBar = navigationController.navigationBar as? OWSNavigationBar { let navigationController = OWSNavigationController(rootViewController: viewController)
navigationBar.overrideTheme(type: .clear) navigationController.modalPresentationStyle = (isTransparent
} else { ? .overFullScreen
owsFailDebug("navigationBar was nil or unexpected class") : .fullScreen)
}
self.present(navigationController, animated: false) { if let navigationBar = navigationController.navigationBar as? OWSNavigationBar {
// Do nothing. navigationBar.overrideTheme(type: .clear)
}
} else { } else {
self.present(viewController, animated: false) { owsFailDebug("navigationBar was nil or unexpected class")
// Do nothing.
}
} }
}
public func imageEditorPresentCaptionView() { self.present(navigationController, animated: false) {
let view = AttachmentCaptionViewController(delegate: self, attachmentItem: attachmentItem) // Do nothing.
self.imageEditor(presentFullScreenOverlay: view, withNavigation: true) }
isShowingCaptionView = true
} }
public func imageEditorUpdateNavigationBar() { public func imageEditorUpdateNavigationBar() {

@ -127,7 +127,7 @@ public class ImageEditorBrushViewController: OWSViewController {
private var currentStrokeSamples = [ImageEditorStrokeItem.StrokeSample]() private var currentStrokeSamples = [ImageEditorStrokeItem.StrokeSample]()
@objc @objc
public func handleBrushGesture(_ gestureRecognizer: UIGestureRecognizer) { public func handleBrushGesture(_ gestureRecognizer: ImageEditorPanGestureRecognizer) {
AssertIsOnMainThread() AssertIsOnMainThread()
let removeCurrentStroke = { let removeCurrentStroke = {
@ -137,10 +137,9 @@ public class ImageEditorBrushViewController: OWSViewController {
self.currentStroke = nil self.currentStroke = nil
self.currentStrokeSamples.removeAll() self.currentStrokeSamples.removeAll()
} }
let tryToAppendStrokeSample = { let tryToAppendStrokeSample = { (locationInView: CGPoint) in
let view = self.canvasView.gestureReferenceView let view = self.canvasView.gestureReferenceView
let viewBounds = view.bounds let viewBounds = view.bounds
let locationInView = gestureRecognizer.location(in: view)
let newSample = ImageEditorCanvasView.locationImageUnit(forLocationInView: locationInView, let newSample = ImageEditorCanvasView.locationImageUnit(forLocationInView: locationInView,
viewBounds: viewBounds, viewBounds: viewBounds,
model: self.model, model: self.model,
@ -162,14 +161,22 @@ public class ImageEditorBrushViewController: OWSViewController {
case .began: case .began:
removeCurrentStroke() removeCurrentStroke()
tryToAppendStrokeSample() // Apply the location history of the gesture so that the stroke reflects
// the touch's movement before the gesture recognized.
for location in gestureRecognizer.locations {
tryToAppendStrokeSample(location)
}
let locationInView = gestureRecognizer.location(in: canvasView.gestureReferenceView)
tryToAppendStrokeSample(locationInView)
let stroke = ImageEditorStrokeItem(color: strokeColor, unitSamples: currentStrokeSamples, unitStrokeWidth: unitStrokeWidth) let stroke = ImageEditorStrokeItem(color: strokeColor, unitSamples: currentStrokeSamples, unitStrokeWidth: unitStrokeWidth)
model.append(item: stroke) model.append(item: stroke)
currentStroke = stroke currentStroke = stroke
case .changed, .ended: case .changed, .ended:
tryToAppendStrokeSample() let locationInView = gestureRecognizer.location(in: canvasView.gestureReferenceView)
tryToAppendStrokeSample(locationInView)
guard let lastStroke = self.currentStroke else { guard let lastStroke = self.currentStroke else {
owsFailDebug("Missing last stroke.") owsFailDebug("Missing last stroke.")

@ -27,9 +27,13 @@ public class ImageEditorCanvasView: UIView {
private let model: ImageEditorModel private let model: ImageEditorModel
private let itemIdsToIgnore: [String]
@objc @objc
public required init(model: ImageEditorModel) { public required init(model: ImageEditorModel,
itemIdsToIgnore: [String] = []) {
self.model = model self.model = model
self.itemIdsToIgnore = itemIdsToIgnore
super.init(frame: .zero) super.init(frame: .zero)
@ -180,6 +184,11 @@ public class ImageEditorCanvasView: UIView {
updateImageLayer() updateImageLayer()
for item in model.items() { for item in model.items() {
guard !itemIdsToIgnore.contains(item.itemId) else {
// Ignore this item.
continue
}
guard let layer = ImageEditorCanvasView.layerForItem(item: item, guard let layer = ImageEditorCanvasView.layerForItem(item: item,
model: model, model: model,
transform: transform, transform: transform,

@ -13,7 +13,12 @@ public class ImageEditorPanGestureRecognizer: UIPanGestureRecognizer {
public weak var referenceView: UIView? public weak var referenceView: UIView?
public var locationStart: CGPoint? // Capture the location history of this gesture.
public var locations = [CGPoint]()
public var locationStart: CGPoint? {
return locations.first
}
// MARK: - Touch Handling // MARK: - Touch Handling
@ -25,12 +30,23 @@ public class ImageEditorPanGestureRecognizer: UIPanGestureRecognizer {
owsFailDebug("Missing view") owsFailDebug("Missing view")
return return
} }
locationStart = self.location(in: referenceView) locations.append(location(in: referenceView))
}
@objc
public override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesMoved(touches, with: event)
guard let referenceView = referenceView else {
owsFailDebug("Missing view")
return
}
locations.append(location(in: referenceView))
} }
public override func reset() { public override func reset() {
super.reset() super.reset()
locationStart = nil locations.removeAll()
} }
} }

@ -122,7 +122,8 @@ public class ImageEditorTextViewController: OWSViewController, VAlignTextViewDel
self.model = model self.model = model
self.textItem = textItem self.textItem = textItem
self.maxTextWidthPoints = maxTextWidthPoints self.maxTextWidthPoints = maxTextWidthPoints
self.canvasView = ImageEditorCanvasView(model: model) self.canvasView = ImageEditorCanvasView(model: model,
itemIdsToIgnore: [textItem.itemId])
self.paletteView = ImageEditorPaletteView(currentColor: textItem.color) self.paletteView = ImageEditorPaletteView(currentColor: textItem.color)
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)

@ -6,9 +6,8 @@ import UIKit
@objc @objc
public protocol ImageEditorViewDelegate: class { public protocol ImageEditorViewDelegate: class {
func imageEditor(presentFullScreenOverlay viewController: UIViewController, func imageEditor(presentFullScreenView viewController: UIViewController,
withNavigation: Bool) isTransparent: Bool)
func imageEditorPresentCaptionView()
func imageEditorUpdateNavigationBar() func imageEditorUpdateNavigationBar()
} }
@ -99,14 +98,15 @@ public class ImageEditorView: UIView {
selector: #selector(didTapCrop(sender:))) selector: #selector(didTapCrop(sender:)))
let newTextButton = navigationBarButton(imageName: "image_editor_text", let newTextButton = navigationBarButton(imageName: "image_editor_text",
selector: #selector(didTapNewText(sender:))) selector: #selector(didTapNewText(sender:)))
let captionButton = navigationBarButton(imageName: "image_editor_caption",
selector: #selector(didTapCaption(sender:)))
var buttons: [UIView]
if model.canUndo() { if model.canUndo() {
return [undoButton, newTextButton, brushButton, cropButton, captionButton] buttons = [undoButton, newTextButton, brushButton, cropButton]
} else { } else {
return [newTextButton, brushButton, cropButton, captionButton] buttons = [newTextButton, brushButton, cropButton]
} }
return buttons
} }
// MARK: - Actions // MARK: - Actions
@ -124,8 +124,8 @@ public class ImageEditorView: UIView {
Logger.verbose("") Logger.verbose("")
let brushView = ImageEditorBrushViewController(delegate: self, model: model, currentColor: currentColor) let brushView = ImageEditorBrushViewController(delegate: self, model: model, currentColor: currentColor)
self.delegate?.imageEditor(presentFullScreenOverlay: brushView, self.delegate?.imageEditor(presentFullScreenView: brushView,
withNavigation: true) isTransparent: false)
} }
@objc func didTapCrop(sender: UIButton) { @objc func didTapCrop(sender: UIButton) {
@ -152,12 +152,6 @@ public class ImageEditorView: UIView {
edit(textItem: textItem) edit(textItem: textItem)
} }
@objc func didTapCaption(sender: UIButton) {
Logger.verbose("")
delegate?.imageEditorPresentCaptionView()
}
@objc func didTapDone(sender: UIButton) { @objc func didTapDone(sender: UIButton) {
Logger.verbose("") Logger.verbose("")
} }
@ -424,8 +418,8 @@ public class ImageEditorView: UIView {
model: model, model: model,
textItem: textItem, textItem: textItem,
maxTextWidthPoints: maxTextWidthPoints) maxTextWidthPoints: maxTextWidthPoints)
self.delegate?.imageEditor(presentFullScreenOverlay: textEditor, self.delegate?.imageEditor(presentFullScreenView: textEditor,
withNavigation: true) isTransparent: false)
} }
// MARK: - Crop Tool // MARK: - Crop Tool
@ -448,8 +442,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(presentFullScreenView: cropTool,
withNavigation: true) isTransparent: false)
}} }}
// MARK: - // MARK: -

Loading…
Cancel
Save