Merge branch 'charlesmchen/imageEditorDesign2'

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

@ -48,6 +48,10 @@ class AttachmentItemCollection {
func remove(item: SignalAttachmentItem) {
attachmentItems = attachmentItems.filter { $0 != item }
}
var count: Int {
return attachmentItems.count
}
}
// MARK: -
@ -618,6 +622,10 @@ extension AttachmentApprovalViewController: AttachmentPrepViewControllerDelegate
func prepViewControllerUpdateNavigationBar() {
self.updateNavigationBar()
}
func prepViewControllerAttachmentCount() -> Int {
return attachmentItemCollection.count
}
}
// MARK: GalleryRail
@ -671,6 +679,8 @@ protocol AttachmentPrepViewControllerDelegate: class {
func prepViewController(_ prepViewController: AttachmentPrepViewController, didUpdateCaptionForAttachmentItem attachmentItem: SignalAttachmentItem)
func prepViewControllerUpdateNavigationBar()
func prepViewControllerAttachmentCount() -> Int
}
public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarDelegate, OWSVideoPlayerDelegate {
@ -883,10 +893,52 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
// MARK: - Navigation Bar
public func navigationBarItems() -> [UIView] {
let captionButton = navigationBarButton(imageName: "image_editor_caption",
selector: #selector(didTapCaption(sender:)))
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 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
@ -1132,34 +1184,23 @@ extension AttachmentPrepViewController: UIScrollViewDelegate {
// MARK: -
extension AttachmentPrepViewController: ImageEditorViewDelegate {
public func imageEditor(presentFullScreenOverlay viewController: UIViewController,
withNavigation: Bool) {
if withNavigation {
let navigationController = OWSNavigationController(rootViewController: viewController)
navigationController.modalPresentationStyle = .overFullScreen
public func imageEditor(presentFullScreenView viewController: UIViewController,
isTransparent: Bool) {
if let navigationBar = navigationController.navigationBar as? OWSNavigationBar {
navigationBar.overrideTheme(type: .clear)
} else {
owsFailDebug("navigationBar was nil or unexpected class")
}
let navigationController = OWSNavigationController(rootViewController: viewController)
navigationController.modalPresentationStyle = (isTransparent
? .overFullScreen
: .fullScreen)
self.present(navigationController, animated: false) {
// Do nothing.
}
if let navigationBar = navigationController.navigationBar as? OWSNavigationBar {
navigationBar.overrideTheme(type: .clear)
} else {
self.present(viewController, animated: false) {
// Do nothing.
}
owsFailDebug("navigationBar was nil or unexpected class")
}
}
public func imageEditorPresentCaptionView() {
let view = AttachmentCaptionViewController(delegate: self, attachmentItem: attachmentItem)
self.imageEditor(presentFullScreenOverlay: view, withNavigation: true)
isShowingCaptionView = true
self.present(navigationController, animated: false) {
// Do nothing.
}
}
public func imageEditorUpdateNavigationBar() {

@ -127,7 +127,7 @@ public class ImageEditorBrushViewController: OWSViewController {
private var currentStrokeSamples = [ImageEditorStrokeItem.StrokeSample]()
@objc
public func handleBrushGesture(_ gestureRecognizer: UIGestureRecognizer) {
public func handleBrushGesture(_ gestureRecognizer: ImageEditorPanGestureRecognizer) {
AssertIsOnMainThread()
let removeCurrentStroke = {
@ -137,10 +137,9 @@ public class ImageEditorBrushViewController: OWSViewController {
self.currentStroke = nil
self.currentStrokeSamples.removeAll()
}
let tryToAppendStrokeSample = {
let tryToAppendStrokeSample = { (locationInView: CGPoint) in
let view = self.canvasView.gestureReferenceView
let viewBounds = view.bounds
let locationInView = gestureRecognizer.location(in: view)
let newSample = ImageEditorCanvasView.locationImageUnit(forLocationInView: locationInView,
viewBounds: viewBounds,
model: self.model,
@ -162,14 +161,22 @@ public class ImageEditorBrushViewController: OWSViewController {
case .began:
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)
model.append(item: stroke)
currentStroke = stroke
case .changed, .ended:
tryToAppendStrokeSample()
let locationInView = gestureRecognizer.location(in: canvasView.gestureReferenceView)
tryToAppendStrokeSample(locationInView)
guard let lastStroke = self.currentStroke else {
owsFailDebug("Missing last stroke.")

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

@ -13,7 +13,12 @@ public class ImageEditorPanGestureRecognizer: UIPanGestureRecognizer {
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
@ -25,12 +30,23 @@ public class ImageEditorPanGestureRecognizer: UIPanGestureRecognizer {
owsFailDebug("Missing view")
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() {
super.reset()
locationStart = nil
locations.removeAll()
}
}

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

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

Loading…
Cancel
Save