Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Merge pull request #386 from slackhq/retain-cycle-fix
Browse files Browse the repository at this point in the history
Retain Cycle Fixes
  • Loading branch information
sukeban committed Feb 16, 2016
2 parents e2ca727 + 0c5c7d6 commit 30f3ecc
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 171 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "icn_arrow_down.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "icn_arrow_up.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
29 changes: 22 additions & 7 deletions Examples/Messenger-Shared/MessageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ - (void)configureDataSource

- (void)configureActionItems
{
UIBarButtonItem *arrowItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icn_arrow_down"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(hideOrShowTextInputbar:)];

UIBarButtonItem *editItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icn_editing"]
style:UIBarButtonItemStylePlain
target:self
Expand All @@ -178,12 +183,23 @@ - (void)configureActionItems
target:self
action:@selector(togglePIPWindow:)];

self.navigationItem.rightBarButtonItems = @[pipItem, editItem, appendItem, typeItem];
self.navigationItem.rightBarButtonItems = @[arrowItem, pipItem, editItem, appendItem, typeItem];
}


#pragma mark - Action Methods

- (void)hideOrShowTextInputbar:(id)sender
{
BOOL hide = !self.textInputbarHidden;

UIImage *image = hide ? [UIImage imageNamed:@"icn_arrow_up"] : [UIImage imageNamed:@"icn_arrow_down"];
UIBarButtonItem *buttonItem = (UIBarButtonItem *)sender;

[self setTextInputbarHidden:hide animated:YES];
[buttonItem setImage:image];
}

- (void)fillWithText:(id)sender
{
if (self.textView.text.length == 0)
Expand Down Expand Up @@ -406,15 +422,14 @@ - (void)didPressRightButton:(id)sender
[super didPressRightButton:sender];
}

- (void)didPressArrowKey:(id)sender
- (void)didPressArrowKey:(UIKeyCommand *)keyCommand
{
[super didPressArrowKey:sender];

UIKeyCommand *keyCommand = (UIKeyCommand *)sender;

if ([keyCommand.input isEqualToString:UIKeyInputUpArrow]) {
if ([keyCommand.input isEqualToString:UIKeyInputUpArrow] && self.textView.text.length == 0) {
[self editLastMessage:nil];
}
else {
[super didPressArrowKey:keyCommand];
}
}

- (NSString *)keyForTextCaching
Expand Down
7 changes: 3 additions & 4 deletions Source/SLKTextInputbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#import <UIKit/UIKit.h>

@class SLKTextViewController;
@class SLKTextView;
@class SLKInputAccessoryView;

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

/** A weak reference to the core view controller. */
@property (nonatomic, weak) SLKTextViewController *controller;

/** The centered text input view.
The maximum number of lines is configured by default, to best fit each devices dimensions.
For iPhone 4 (<=480pts): 4 lines
Expand All @@ -58,6 +54,9 @@ typedef NS_ENUM(NSUInteger, SLKCounterPosition) {
/** YES if the right button should be hidden animatedly in case the text view has no text in it. Default is YES. */
@property (nonatomic, readwrite) BOOL autoHideRightButton;

/** YES if animations should have bouncy effects. Default is YES. */
@property (nonatomic, assign) BOOL bounces;

/** The inner padding to use when laying out content in the view. Default is {5, 8, 5, 8}. */
@property (nonatomic, assign) UIEdgeInsets contentInset;

Expand Down
27 changes: 21 additions & 6 deletions Source/SLKTextInputbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//

#import "SLKTextInputbar.h"
#import "SLKTextViewController.h"
#import "SLKTextView.h"
#import "SLKInputAccessoryView.h"

Expand Down Expand Up @@ -45,9 +44,12 @@ @interface SLKTextInputbar ()

@property (nonatomic, strong) Class textViewClass;

@property (nonatomic, getter=isHidden) BOOL hidden; // Required override

@end

@implementation SLKTextInputbar
@synthesize hidden = _hidden;

#pragma mark - Initialization

Expand Down Expand Up @@ -281,6 +283,11 @@ - (UILabel *)charCountLabel
return _charCountLabel;
}

- (BOOL)isHidden
{
return _hidden;
}

- (CGFloat)minimumInputbarHeight
{
CGFloat minimumTextViewHeight = self.textView.intrinsicContentSize.height;
Expand Down Expand Up @@ -425,6 +432,14 @@ - (void)setEditing:(BOOL)editing
_editorContentView.hidden = !editing;
}

- (void)setHidden:(BOOL)hidden
{
// We don't call super here, since we want to avoid to visually hide the view.
// The hidden render state is handled by the view controller.

_hidden = hidden;
}

- (void)setCounterPosition:(SLKCounterPosition)counterPosition
{
if (self.counterPosition == counterPosition && self.charCountLabelVCs) {
Expand Down Expand Up @@ -463,7 +478,7 @@ - (void)setCounterPosition:(SLKCounterPosition)counterPosition

- (BOOL)canEditText:(NSString *)text
{
if ((self.isEditing && [self.textView.text isEqualToString:text]) || self.controller.isTextInputbarHidden) {
if ((self.isEditing && [self.textView.text isEqualToString:text]) || self.isHidden) {
return NO;
}

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

- (void)beginTextEditing
{
if (self.isEditing || self.controller.isTextInputbarHidden) {
if (self.isEditing || self.isHidden) {
return;
}

Expand All @@ -487,7 +502,7 @@ - (void)beginTextEditing

- (void)endTextEdition
{
if (!self.isEditing || self.controller.isTextInputbarHidden) {
if (!self.isEditing || self.isHidden) {
return;
}

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

BOOL bounces = self.controller.bounces && [self.textView isFirstResponder];
BOOL bounces = self.bounces && [self.textView isFirstResponder];

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


#pragma mark - NSNotificationCenter register/unregister
#pragma mark - NSNotificationCenter registration

- (void)slk_registerNotifications
{
Expand Down
16 changes: 15 additions & 1 deletion Source/SLKTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ typedef NS_OPTIONS(NSUInteger, SLKPastableMediaType) {
/**
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.
*/
- (void)didPressAnyArrowKey:(id)sender;
- (void)didPressArrowKey:(UIKeyCommand *)keyCommand;


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


#pragma mark - External Keyboard Support

/**
Registers and observes key commands' updates, when the text view is first responder.
Instead of typically overriding UIResponder's -keyCommands method, it is better to use this API for easier and safer implementation of key input detection.
@param input The keys that must be pressed by the user. Required.
@param modifiers The bit mask of modifier keys that must be pressed. Use 0 if none.
@param title The title to display to the user. Optional.
@param completion A completion block called whenever the key combination is detected. Required.
*/
- (void)observeKeyInput:(NSString *)input modifiers:(UIKeyModifierFlags)modifiers title:(NSString *)title completion:(void (^)(UIKeyCommand *keyCommand))completion;

@end


Expand Down
Loading

0 comments on commit 30f3ecc

Please sign in to comment.