Clean up ahead of PR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 8ecdc8a2eb
commit bf6d8ec141

@ -263,25 +263,31 @@ typedef enum : NSUInteger {
case UIGestureRecognizerStateCancelled: case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateFailed: case UIGestureRecognizerStateFailed:
if (self.isRecordingVoiceMemo) { if (self.isRecordingVoiceMemo) {
// Cancel voice memo if necessary.
self.isRecordingVoiceMemo = NO; self.isRecordingVoiceMemo = NO;
[self.delegate voiceMemoGestureDidCancel]; [self.delegate voiceMemoGestureDidCancel];
} }
break; break;
case UIGestureRecognizerStateBegan: case UIGestureRecognizerStateBegan:
if (self.isRecordingVoiceMemo) { if (self.isRecordingVoiceMemo) {
// Cancel voice memo if necessary.
self.isRecordingVoiceMemo = NO; self.isRecordingVoiceMemo = NO;
[self.delegate voiceMemoGestureDidCancel]; [self.delegate voiceMemoGestureDidCancel];
} }
[self resignFirstResponder]; // Start voice memo.
[self.textView resignFirstResponder];
self.isRecordingVoiceMemo = YES; self.isRecordingVoiceMemo = YES;
self.voiceMemoGestureStartLocation = [sender locationInView:self]; self.voiceMemoGestureStartLocation = [sender locationInView:self];
[self.delegate voiceMemoGestureDidStart]; [self.delegate voiceMemoGestureDidStart];
break; break;
case UIGestureRecognizerStateChanged: case UIGestureRecognizerStateChanged:
if (self.isRecordingVoiceMemo) { if (self.isRecordingVoiceMemo) {
// Check for "slide to cancel" gesture.
CGPoint location = [sender locationInView:self]; CGPoint location = [sender locationInView:self];
CGFloat offset = MAX(0, self.voiceMemoGestureStartLocation.x - location.x); CGFloat offset = MAX(0, self.voiceMemoGestureStartLocation.x - location.x);
const CGFloat kCancelOffsetPoints = 60.f; // The lower this value, the easier it is to cancel by accident.
// The higher this value, the harder it is to cancel.
const CGFloat kCancelOffsetPoints = 100.f;
CGFloat cancelAlpha = offset / kCancelOffsetPoints; CGFloat cancelAlpha = offset / kCancelOffsetPoints;
BOOL isCancelled = cancelAlpha >= 1.f; BOOL isCancelled = cancelAlpha >= 1.f;
if (isCancelled) { if (isCancelled) {
@ -294,6 +300,7 @@ typedef enum : NSUInteger {
break; break;
case UIGestureRecognizerStateEnded: case UIGestureRecognizerStateEnded:
if (self.isRecordingVoiceMemo) { if (self.isRecordingVoiceMemo) {
// End voice memo.
self.isRecordingVoiceMemo = NO; self.isRecordingVoiceMemo = NO;
[self.delegate voiceMemoGestureDidEnd]; [self.delegate voiceMemoGestureDidEnd];
} }
@ -3484,6 +3491,8 @@ typedef enum : NSUInteger {
- (void)textViewDidChange:(UITextView *)textView - (void)textViewDidChange:(UITextView *)textView
{ {
// We want to show the "voice memo" button if the text input is empty
// and the "send" button if it isn't.
[((OWSMessagesToolbarContentView *)self.inputToolbar.contentView)ensureEnabling]; [((OWSMessagesToolbarContentView *)self.inputToolbar.contentView)ensureEnabling];
} }

Loading…
Cancel
Save