First draft of image editor's text tool.

This commit is contained in:
Matthew Chen 2019-02-06 14:21:32 -05:00
parent 3f8ea271b4
commit 6ac2dd7ea1
8 changed files with 76 additions and 32 deletions

View file

@ -28,7 +28,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4D5E7522A33906C902399C86F0A95AA5"
BlueprintIdentifier = "EF7BE58B1F949AF31E4AF4FD37150A86"
BuildableName = "SignalServiceKit.framework"
BlueprintName = "SignalServiceKit"
ReferencedContainer = "container:Pods/Pods.xcodeproj">
@ -56,7 +56,7 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AB62203226FE5032747AA668B1E97176"
BlueprintIdentifier = "2349E04BB99C0118E8F578CCBEAAC665"
BuildableName = "SignalServiceKit-Unit-Tests.xctest"
BlueprintName = "SignalServiceKit-Unit-Tests"
ReferencedContainer = "container:Pods/Pods.xcodeproj">
@ -66,7 +66,7 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BC89BC6B06642C78EABF18B43FFB41DE"
BlueprintIdentifier = "3AC929F2E4978F42ED9E9EA232D7247B"
BuildableName = "SignalCoreKit-Unit-Tests.xctest"
BlueprintName = "SignalCoreKit-Unit-Tests"
ReferencedContainer = "container:Pods/Pods.xcodeproj">
@ -76,7 +76,7 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E012D804E31EC876E21973F300B46CCB"
BlueprintIdentifier = "5B34FB0B5ABA685EF33F1BA1C388F016"
BuildableName = "AxolotlKit-Unit-Tests.xctest"
BlueprintName = "AxolotlKit-Unit-Tests"
ReferencedContainer = "container:Pods/Pods.xcodeproj">
@ -86,7 +86,7 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B4A8ABAC14D962F8F42814238460DF44"
BlueprintIdentifier = "D85B45003BA81D72F606FDF3EB4B4E1C"
BuildableName = "Curve25519Kit-Unit-Tests.xctest"
BlueprintName = "Curve25519Kit-Unit-Tests"
ReferencedContainer = "container:Pods/Pods.xcodeproj">
@ -96,7 +96,7 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E5C44C64CDE3569B16010274DCD48BCC"
BlueprintIdentifier = "F9C2DA0BADF4F69559F0AA5BB4FC1E06"
BuildableName = "HKDFKit-Unit-Tests.xctest"
BlueprintName = "HKDFKit-Unit-Tests"
ReferencedContainer = "container:Pods/Pods.xcodeproj">
@ -106,7 +106,7 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "00649589DE58D9DECF419A3CC47D6924"
BlueprintIdentifier = "92057C418B970541FF6BE6E64A49D8C2"
BuildableName = "SignalMetadataKit-Unit-Tests.xctest"
BlueprintName = "SignalMetadataKit-Unit-Tests"
ReferencedContainer = "container:Pods/Pods.xcodeproj">
@ -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"

View file

@ -7,7 +7,7 @@
<key>CarthageVersion</key>
<string>0.31.2</string>
<key>OSXVersion</key>
<string>10.14.2</string>
<string>10.14.3</string>
<key>WebRTCCommit</key>
<string>55de5593cc261fa9368c5ccde98884ed1e278ba0 M72</string>
</dict>

View file

@ -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,

View file

@ -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];

View file

@ -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 {

View file

@ -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()

View file

@ -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

View file

@ -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;