From 6ac2dd7ea1260a30916a3dc3c7600dbef8cb9cb8 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 6 Feb 2019 14:21:32 -0500 Subject: [PATCH] First draft of image editor's text tool. --- .../xcshareddata/xcschemes/Signal.xcscheme | 17 +++++----- Signal/Signal-Info.plist | 2 +- .../ConversationViewController.m | 26 ++++++++++++++ .../HomeView/HomeViewController.m | 18 ++++++++++ .../Views/ImageEditor/ImageEditorModel.swift | 34 ++++++++----------- .../ImageEditorPinchGestureRecognizer.swift | 5 +++ .../ImageEditorTextViewController.swift | 4 +-- .../src/Network/WebSockets/OWSWebSocket.m | 2 ++ 8 files changed, 76 insertions(+), 32 deletions(-) diff --git a/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme b/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme index f5fde70a8..16d93f758 100644 --- a/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme +++ b/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme @@ -28,7 +28,7 @@ buildForAnalyzing = "YES"> @@ -56,7 +56,7 @@ skipped = "NO"> @@ -66,7 +66,7 @@ skipped = "NO"> @@ -76,7 +76,7 @@ skipped = "NO"> @@ -86,7 +86,7 @@ skipped = "NO"> @@ -96,7 +96,7 @@ skipped = "NO"> @@ -106,7 +106,7 @@ skipped = "NO"> @@ -136,8 +136,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - enableThreadSanitizer = "YES" - enableUBSanitizer = "YES" + disableMainThreadChecker = "YES" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist index 319894846..bbc073f5d 100644 --- a/Signal/Signal-Info.plist +++ b/Signal/Signal-Info.plist @@ -7,7 +7,7 @@ CarthageVersion 0.31.2 OSXVersion - 10.14.2 + 10.14.3 WebRTCCommit 55de5593cc261fa9368c5ccde98884ed1e278ba0 M72 diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index a40183cd2..51c1bf479 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -1234,6 +1234,32 @@ typedef enum : NSUInteger { self.actionOnOpen = ConversationViewActionNone; [self updateInputToolbarLayout]; + + [self showDebugImageEditorAsync]; +} + +- (void)showDebugImageEditorAsync +{ + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *_Nullable filePath = [[NSBundle mainBundle] pathForResource:@"qr@2x" ofType:@"png" inDirectory:nil]; + if (!filePath) { + OWSFailDebug(@"Missing asset."); + } + + DataSource *_Nullable dataSource = + [DataSourcePath dataSourceWithFilePath:filePath shouldDeleteOnDeallocation:NO]; + if (!dataSource) { + OWSFailDebug(@"Invalid asset."); + return; + } + + // "Document picker" attachments _SHOULD NOT_ be resized, if possible. + SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource + dataUTI:(NSString *)kUTTypePNG + imageQuality:TSImageQualityOriginal]; + + [self showApprovalDialogForAttachment:attachment]; + }); } // `viewWillDisappear` is called whenever the view *starts* to disappear, diff --git a/Signal/src/ViewControllers/HomeView/HomeViewController.m b/Signal/src/ViewControllers/HomeView/HomeViewController.m index 2e8ab8ba1..02850c1d2 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewController.m @@ -482,8 +482,26 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations [self.searchResultsController viewDidAppear:animated]; self.hasEverAppeared = YES; + + [self presentFirstThreadAsync]; } +#ifdef DEBUG + +- (void)presentFirstThreadAsync +{ + dispatch_async(dispatch_get_main_queue(), ^{ + if ([self.tableView numberOfRowsInSection:HomeViewControllerSectionConversations] < 1) { + return; + } + TSThread *thread = + [self threadForIndexPath:[NSIndexPath indexPathForRow:0 inSection:HomeViewControllerSectionConversations]]; + [self presentThread:thread action:ConversationViewActionNone animated:YES]; + }); +} + +#endif + - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; diff --git a/SignalMessaging/Views/ImageEditor/ImageEditorModel.swift b/SignalMessaging/Views/ImageEditor/ImageEditorModel.swift index eb601470c..f7199b6dd 100644 --- a/SignalMessaging/Views/ImageEditor/ImageEditorModel.swift +++ b/SignalMessaging/Views/ImageEditor/ImageEditorModel.swift @@ -68,6 +68,8 @@ public class ImageEditorItem: NSObject { return ImageEditorItem(itemId: itemId, itemType: itemType) } + // The scale with which to render this item's content + // when rendering the "output" image for sending. public func outputScale() -> CGFloat { return 1.0 } @@ -161,6 +163,12 @@ public class ImageEditorTextItem: ImageEditorItem { public static let kDefaultUnitWidth: CGFloat = 0.9 // The max width of the text as a fraction of the image width. + // + // This provides continuity of text layout before/after cropping. + // + // NOTE: When you scale the text with with a pinch gesture, that + // affects _scaling_, not the _unit width_, since we don't want + // to change how the text wraps when scaling. @objc public let unitWidth: CGFloat @@ -176,12 +184,6 @@ public class ImageEditorTextItem: ImageEditorItem { @objc public let scaling: CGFloat - // This might be nil while the item is a "draft" item. - // Once the item has been "committed" to the model, it - // should always be non-nil, - @objc - public let imagePath: String? - @objc public init(color: UIColor, font: UIFont, @@ -189,8 +191,7 @@ public class ImageEditorTextItem: ImageEditorItem { unitCenter: ImageEditorSample = CGPoint(x: 0.5, y: 0.5), unitWidth: CGFloat = ImageEditorTextItem.kDefaultUnitWidth, rotationRadians: CGFloat = 0.0, - scaling: CGFloat = 1.0, - imagePath: String? = nil) { + scaling: CGFloat = 1.0) { self.color = color self.font = font self.text = text @@ -198,7 +199,6 @@ public class ImageEditorTextItem: ImageEditorItem { self.unitWidth = unitWidth self.rotationRadians = rotationRadians self.scaling = scaling - self.imagePath = imagePath super.init(itemType: .text) } @@ -210,8 +210,7 @@ public class ImageEditorTextItem: ImageEditorItem { unitCenter: ImageEditorSample, unitWidth: CGFloat, rotationRadians: CGFloat, - scaling: CGFloat, - imagePath: String?) { + scaling: CGFloat) { self.color = color self.font = font self.text = text @@ -219,7 +218,6 @@ public class ImageEditorTextItem: ImageEditorItem { self.unitWidth = unitWidth self.rotationRadians = rotationRadians self.scaling = scaling - self.imagePath = imagePath super.init(itemId: itemId, itemType: .text) } @@ -239,8 +237,7 @@ public class ImageEditorTextItem: ImageEditorItem { unitCenter: unitCenter, unitWidth: unitWidth, rotationRadians: rotationRadians, - scaling: scaling, - imagePath: imagePath) + scaling: scaling) } @objc @@ -252,8 +249,7 @@ public class ImageEditorTextItem: ImageEditorItem { unitCenter: newUnitCenter, unitWidth: unitWidth, rotationRadians: rotationRadians, - scaling: scaling, - imagePath: imagePath) + scaling: scaling) } @objc @@ -267,8 +263,7 @@ public class ImageEditorTextItem: ImageEditorItem { unitCenter: newUnitCenter, unitWidth: unitWidth, rotationRadians: newRotationRadians, - scaling: newScaling, - imagePath: imagePath) + scaling: newScaling) } public override func clone(withImageEditorConversion conversion: ImageEditorConversion) -> ImageEditorItem { @@ -282,8 +277,7 @@ public class ImageEditorTextItem: ImageEditorItem { unitCenter: convertedUnitCenter, unitWidth: convertedUnitWidth, rotationRadians: rotationRadians, - scaling: scaling, - imagePath: imagePath) + scaling: scaling) } public override func outputScale() -> CGFloat { diff --git a/SignalMessaging/Views/ImageEditor/ImageEditorPinchGestureRecognizer.swift b/SignalMessaging/Views/ImageEditor/ImageEditorPinchGestureRecognizer.swift index ae7042247..595d7b758 100644 --- a/SignalMessaging/Views/ImageEditor/ImageEditorPinchGestureRecognizer.swift +++ b/SignalMessaging/Views/ImageEditor/ImageEditorPinchGestureRecognizer.swift @@ -22,6 +22,11 @@ public struct ImageEditorPinchState { } } +// This GR: +// +// * Tries to fail quickly to avoid conflicts with other GRs, especially pans/swipes. +// * Captures a bunch of useful "pinch state" that makes using this GR much easier +// than UIPinchGestureRecognizer. public class ImageEditorPinchGestureRecognizer: UIGestureRecognizer { public var pinchStateStart = ImageEditorPinchState.empty() diff --git a/SignalMessaging/Views/ImageEditor/ImageEditorTextViewController.swift b/SignalMessaging/Views/ImageEditor/ImageEditorTextViewController.swift index 75a580646..aaac87099 100644 --- a/SignalMessaging/Views/ImageEditor/ImageEditorTextViewController.swift +++ b/SignalMessaging/Views/ImageEditor/ImageEditorTextViewController.swift @@ -171,8 +171,8 @@ class ImageEditorTextViewController: OWSViewController, VAlignTextViewDelegate { // We use a white cursor since we use a dark background. textView.tintColor = .white textView.returnKeyType = .done - // TODO: - // textView.delegate = self + // TODO: Limit the size of the text. + // textView.delegate = self textView.isScrollEnabled = true textView.scrollsToTop = false textView.isUserInteractionEnabled = true diff --git a/SignalServiceKit/src/Network/WebSockets/OWSWebSocket.m b/SignalServiceKit/src/Network/WebSockets/OWSWebSocket.m index 17d6b7c5a..c93a07d23 100644 --- a/SignalServiceKit/src/Network/WebSockets/OWSWebSocket.m +++ b/SignalServiceKit/src/Network/WebSockets/OWSWebSocket.m @@ -910,6 +910,8 @@ NSString *const kNSNotification_OWSWebSocketStateDidChange = @"kNSNotification_O { OWSAssertIsOnMainThread(); + return NO; + // Don't open socket in app extensions. if (!CurrentAppContext().isMainApp) { return NO;