Skip to content

Commit 30f3ecc

Browse files
committed
Merge pull request slackhq#386 from slackhq/retain-cycle-fix
Retain Cycle Fixes
2 parents e2ca727 + 0c5c7d6 commit 30f3ecc

16 files changed

+237
-171
lines changed
Binary file not shown.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "icn_arrow_down.pdf",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "icn_arrow_up.pdf",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Examples/Messenger-Shared/MessageViewController.m

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ - (void)configureDataSource
158158

159159
- (void)configureActionItems
160160
{
161+
UIBarButtonItem *arrowItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icn_arrow_down"]
162+
style:UIBarButtonItemStylePlain
163+
target:self
164+
action:@selector(hideOrShowTextInputbar:)];
165+
161166
UIBarButtonItem *editItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icn_editing"]
162167
style:UIBarButtonItemStylePlain
163168
target:self
@@ -178,12 +183,23 @@ - (void)configureActionItems
178183
target:self
179184
action:@selector(togglePIPWindow:)];
180185

181-
self.navigationItem.rightBarButtonItems = @[pipItem, editItem, appendItem, typeItem];
186+
self.navigationItem.rightBarButtonItems = @[arrowItem, pipItem, editItem, appendItem, typeItem];
182187
}
183188

184189

185190
#pragma mark - Action Methods
186191

192+
- (void)hideOrShowTextInputbar:(id)sender
193+
{
194+
BOOL hide = !self.textInputbarHidden;
195+
196+
UIImage *image = hide ? [UIImage imageNamed:@"icn_arrow_up"] : [UIImage imageNamed:@"icn_arrow_down"];
197+
UIBarButtonItem *buttonItem = (UIBarButtonItem *)sender;
198+
199+
[self setTextInputbarHidden:hide animated:YES];
200+
[buttonItem setImage:image];
201+
}
202+
187203
- (void)fillWithText:(id)sender
188204
{
189205
if (self.textView.text.length == 0)
@@ -406,15 +422,14 @@ - (void)didPressRightButton:(id)sender
406422
[super didPressRightButton:sender];
407423
}
408424

409-
- (void)didPressArrowKey:(id)sender
425+
- (void)didPressArrowKey:(UIKeyCommand *)keyCommand
410426
{
411-
[super didPressArrowKey:sender];
412-
413-
UIKeyCommand *keyCommand = (UIKeyCommand *)sender;
414-
415-
if ([keyCommand.input isEqualToString:UIKeyInputUpArrow]) {
427+
if ([keyCommand.input isEqualToString:UIKeyInputUpArrow] && self.textView.text.length == 0) {
416428
[self editLastMessage:nil];
417429
}
430+
else {
431+
[super didPressArrowKey:keyCommand];
432+
}
418433
}
419434

420435
- (NSString *)keyForTextCaching

Source/SLKTextInputbar.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#import <UIKit/UIKit.h>
1818

19-
@class SLKTextViewController;
2019
@class SLKTextView;
2120
@class SLKInputAccessoryView;
2221

@@ -35,9 +34,6 @@ typedef NS_ENUM(NSUInteger, SLKCounterPosition) {
3534
/** @name A custom tool bar encapsulating messaging controls. */
3635
@interface SLKTextInputbar : UIToolbar
3736

38-
/** A weak reference to the core view controller. */
39-
@property (nonatomic, weak) SLKTextViewController *controller;
40-
4137
/** The centered text input view.
4238
The maximum number of lines is configured by default, to best fit each devices dimensions.
4339
For iPhone 4 (<=480pts): 4 lines
@@ -58,6 +54,9 @@ typedef NS_ENUM(NSUInteger, SLKCounterPosition) {
5854
/** YES if the right button should be hidden animatedly in case the text view has no text in it. Default is YES. */
5955
@property (nonatomic, readwrite) BOOL autoHideRightButton;
6056

57+
/** YES if animations should have bouncy effects. Default is YES. */
58+
@property (nonatomic, assign) BOOL bounces;
59+
6160
/** The inner padding to use when laying out content in the view. Default is {5, 8, 5, 8}. */
6261
@property (nonatomic, assign) UIEdgeInsets contentInset;
6362

Source/SLKTextInputbar.m

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
//
1616

1717
#import "SLKTextInputbar.h"
18-
#import "SLKTextViewController.h"
1918
#import "SLKTextView.h"
2019
#import "SLKInputAccessoryView.h"
2120

@@ -45,9 +44,12 @@ @interface SLKTextInputbar ()
4544

4645
@property (nonatomic, strong) Class textViewClass;
4746

47+
@property (nonatomic, getter=isHidden) BOOL hidden; // Required override
48+
4849
@end
4950

5051
@implementation SLKTextInputbar
52+
@synthesize hidden = _hidden;
5153

5254
#pragma mark - Initialization
5355

@@ -281,6 +283,11 @@ - (UILabel *)charCountLabel
281283
return _charCountLabel;
282284
}
283285

286+
- (BOOL)isHidden
287+
{
288+
return _hidden;
289+
}
290+
284291
- (CGFloat)minimumInputbarHeight
285292
{
286293
CGFloat minimumTextViewHeight = self.textView.intrinsicContentSize.height;
@@ -425,6 +432,14 @@ - (void)setEditing:(BOOL)editing
425432
_editorContentView.hidden = !editing;
426433
}
427434

435+
- (void)setHidden:(BOOL)hidden
436+
{
437+
// We don't call super here, since we want to avoid to visually hide the view.
438+
// The hidden render state is handled by the view controller.
439+
440+
_hidden = hidden;
441+
}
442+
428443
- (void)setCounterPosition:(SLKCounterPosition)counterPosition
429444
{
430445
if (self.counterPosition == counterPosition && self.charCountLabelVCs) {
@@ -463,7 +478,7 @@ - (void)setCounterPosition:(SLKCounterPosition)counterPosition
463478

464479
- (BOOL)canEditText:(NSString *)text
465480
{
466-
if ((self.isEditing && [self.textView.text isEqualToString:text]) || self.controller.isTextInputbarHidden) {
481+
if ((self.isEditing && [self.textView.text isEqualToString:text]) || self.isHidden) {
467482
return NO;
468483
}
469484

@@ -472,7 +487,7 @@ - (BOOL)canEditText:(NSString *)text
472487

473488
- (void)beginTextEditing
474489
{
475-
if (self.isEditing || self.controller.isTextInputbarHidden) {
490+
if (self.isEditing || self.isHidden) {
476491
return;
477492
}
478493

@@ -487,7 +502,7 @@ - (void)beginTextEditing
487502

488503
- (void)endTextEdition
489504
{
490-
if (!self.isEditing || self.controller.isTextInputbarHidden) {
505+
if (!self.isEditing || self.isHidden) {
491506
return;
492507
}
493508

@@ -552,7 +567,7 @@ - (void)slk_didChangeTextViewText:(NSNotification *)notification
552567
self.rightMarginWC.constant = [self slk_appropriateRightButtonMargin];
553568
[self.rightButton layoutIfNeeded]; // Avoids the right button to stretch when animating the constraint changes
554569

555-
BOOL bounces = self.controller.bounces && [self.textView isFirstResponder];
570+
BOOL bounces = self.bounces && [self.textView isFirstResponder];
556571

557572
if (self.window) {
558573
[self slk_animateLayoutIfNeededWithBounce:bounces
@@ -704,7 +719,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
704719
}
705720

706721

707-
#pragma mark - NSNotificationCenter register/unregister
722+
#pragma mark - NSNotificationCenter registration
708723

709724
- (void)slk_registerNotifications
710725
{

Source/SLKTextView.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ typedef NS_OPTIONS(NSUInteger, SLKPastableMediaType) {
9999
/**
100100
Notifies the text view that the user pressed any arrow key. This is used to move the cursor up and down while having multiple lines.
101101
*/
102-
- (void)didPressAnyArrowKey:(id)sender;
102+
- (void)didPressArrowKey:(UIKeyCommand *)keyCommand;
103103

104104

105105
#pragma mark - Markdown Formatting
@@ -121,6 +121,20 @@ typedef NS_OPTIONS(NSUInteger, SLKPastableMediaType) {
121121
*/
122122
- (void)registerMarkdownFormattingSymbol:(NSString *)symbol withTitle:(NSString *)title;
123123

124+
125+
#pragma mark - External Keyboard Support
126+
127+
/**
128+
Registers and observes key commands' updates, when the text view is first responder.
129+
Instead of typically overriding UIResponder's -keyCommands method, it is better to use this API for easier and safer implementation of key input detection.
130+
131+
@param input The keys that must be pressed by the user. Required.
132+
@param modifiers The bit mask of modifier keys that must be pressed. Use 0 if none.
133+
@param title The title to display to the user. Optional.
134+
@param completion A completion block called whenever the key combination is detected. Required.
135+
*/
136+
- (void)observeKeyInput:(NSString *)input modifiers:(UIKeyModifierFlags)modifiers title:(NSString *)title completion:(void (^)(UIKeyCommand *keyCommand))completion;
137+
124138
@end
125139

126140

0 commit comments

Comments
 (0)