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

Commit

Permalink
Fixing the text input not being interactive since iOS 11 (#624)
Browse files Browse the repository at this point in the history
* Fixed Xcode warnings + deprecating -shouldProcessTextForAutoCompletion:

* Making SLKTextInputbar a UIView subclass instead, with its own hairline layout.
This fixes #604 rendering SLKTVC useless in iOS 11 since UIToolBar's view hierarchy has drastically changed since, conflicting with the internal outlets of SLKTextInputbar

* Changelog
  • Loading branch information
Ignacio Romero Zurbuchen authored Sep 22, 2017
1 parent dfa1132 commit 46113e0
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 28 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## Version 1.9.6

##### Hot Fixes & Enhancements:
- Fixed the text input not being interactive on iOS. Making `SLKTextInputbar` a UIView subclass instead of `UIToolbar`.

##### Deprecation:
- Deprecated `-shouldProcessTextForAutoCompletion:` in favor of `-shouldProcessTextForAutoCompletion`


## [Version 1.9.5](https://github.com/slackhq/SlackTextViewController/releases/tag/v1.9.5)

##### Features:
Expand Down
4 changes: 2 additions & 2 deletions Examples/Messenger-Shared/MessageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,9 @@ - (BOOL)canShowTypingIndicator
#endif
}

- (BOOL)shouldProcessTextForAutoCompletion:(NSString *)text
- (BOOL)shouldProcessTextForAutoCompletion
{
return [super shouldProcessTextForAutoCompletion:text];
return [super shouldProcessTextForAutoCompletion];
}

- (BOOL)shouldDisableTypingSuggestionForAutoCompletion
Expand Down
14 changes: 13 additions & 1 deletion Examples/Messenger.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Slack Technologies, Inc.";
TargetAttributes = {
4F3EDB48199ED00F004C15D6 = {
Expand Down Expand Up @@ -743,14 +743,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -788,14 +794,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down
8 changes: 7 additions & 1 deletion Examples/Messenger.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 30 additions & 9 deletions Examples/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Source/SLKTextInputbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef NS_ENUM(NSUInteger, SLKCounterPosition) {
NS_ASSUME_NONNULL_BEGIN

/** @name A custom tool bar encapsulating messaging controls. */
@interface SLKTextInputbar : UIToolbar
@interface SLKTextInputbar : UIView

/** The centered text input view.
The maximum number of lines is configured by default, to best fit each devices dimensions.
Expand Down
23 changes: 19 additions & 4 deletions Source/SLKTextInputbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

@interface SLKTextInputbar ()

@property (nonatomic, strong) UIView *hairlineView;

@property (nonatomic, strong) NSLayoutConstraint *textViewBottomMarginC;
@property (nonatomic, strong) NSLayoutConstraint *contentViewHC;
@property (nonatomic, strong) NSLayoutConstraint *leftButtonWC;
Expand Down Expand Up @@ -83,14 +85,16 @@ - (void)slk_commonInit
self.autoHideRightButton = YES;
self.editorContentViewHeight = 38.0;
self.contentInset = UIEdgeInsetsMake(5.0, 8.0, 5.0, 8.0);

self.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:247.0/255.0 blue:247.0/255.0 alpha:1.0]; //UIToolbar native bar tint color

[self addSubview:self.editorContentView];
[self addSubview:self.leftButton];
[self addSubview:self.rightButton];
[self addSubview:self.textView];
[self addSubview:self.charCountLabel];
[self addSubview:self.contentView];

[self addSubview:self.hairlineView];

[self slk_setupViewConstraints];
[self slk_updateConstraintConstants];

Expand Down Expand Up @@ -152,6 +156,16 @@ - (SLKTextView *)textView
return _textView;
}

- (UIView *)hairlineView
{
if (!_hairlineView) {
_hairlineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, 0.5)];
_hairlineView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin;
_hairlineView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];

This comment has been minimized.

Copy link
@rromanchuk

rromanchuk Sep 24, 2017

how can we style this/remove this?

This comment has been minimized.

Copy link
@pchelnikov

pchelnikov Oct 10, 2017

}
return _hairlineView;
}

- (UIView *)contentView
{
if (!_contentView) {
Expand Down Expand Up @@ -408,7 +422,8 @@ - (NSUInteger)slk_defaultNumberOfLines

- (void)setBackgroundColor:(UIColor *)color
{
self.barTintColor = color;
[super setBackgroundColor:color];

self.editorContentView.backgroundColor = color;
}

Expand Down Expand Up @@ -662,7 +677,7 @@ - (void)slk_setupViewConstraints
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[editorContentView]|" options:0 metrics:metrics views:views]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contentView]|" options:0 metrics:metrics views:views]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[contentView(0)]|" options:0 metrics:metrics views:views]];

self.textViewBottomMarginC = [self slk_constraintForAttribute:NSLayoutAttributeBottom firstItem:self secondItem:self.textView];
self.editorContentViewHC = [self slk_constraintForAttribute:NSLayoutAttributeHeight firstItem:self.editorContentView secondItem:nil];
self.contentViewHC = [self slk_constraintForAttribute:NSLayoutAttributeHeight firstItem:self.contentView secondItem:nil];;
Expand Down
1 change: 0 additions & 1 deletion Source/SLKTextViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ NS_CLASS_AVAILABLE_IOS(7_0) @interface SLKTextViewController : UIViewController
@return YES if the controller is allowed to process the text for auto-completion.
*/
- (BOOL)shouldProcessTextForAutoCompletion;
- (BOOL)shouldProcessTextForAutoCompletion:(NSString *)text DEPRECATED_MSG_ATTRIBUTE("Use -shouldProcessTextForAutoCompletion instead.");

/**
During text autocompletion, by default, auto-correction and spell checking are disabled.
Expand Down
13 changes: 4 additions & 9 deletions Source/SLKTextViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ - (void)textSelectionDidChange
}

if (self.textView.selectedRange.length > 0) {
if (self.isAutoCompleting && [self shouldProcessTextForAutoCompletion:self.textView.text]) {
if (self.isAutoCompleting && [self shouldProcessTextForAutoCompletion]) {
[self cancelAutoCompletion];
}
return;
Expand Down Expand Up @@ -880,7 +880,7 @@ - (void)setTextInputbarHidden:(BOOL)hidden animated:(BOOL)animated

__weak typeof(self) weakSelf = self;

void (^animations)() = ^void(){
void (^animations)(void) = ^void(){

weakSelf.textInputbarHC.constant = hidden ? 0.0 : weakSelf.textInputbar.appropriateHeight;

Expand Down Expand Up @@ -1394,7 +1394,7 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification
CGRect beginFrame = [notification.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect endFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

void (^animations)() = ^void() {
void (^animations)(void) = ^void() {
// Scrolls to bottom only if the keyboard is about to show.
if (self.shouldScrollToBottomAfterKeyboardShows && self.keyboardStatus == SLKKeyboardStatusWillShow) {
if (self.isInverted) {
Expand Down Expand Up @@ -1623,11 +1623,6 @@ - (void)registerPrefixesForAutoCompletion:(NSArray <NSString *> *)prefixes
_registeredPrefixes = [NSSet setWithSet:set];
}

- (BOOL)shouldProcessTextForAutoCompletion:(NSString *)text
{
return [self shouldProcessTextForAutoCompletion];
}

- (BOOL)shouldProcessTextForAutoCompletion
{
if (!_registeredPrefixes || _registeredPrefixes.count == 0) {
Expand Down Expand Up @@ -1742,7 +1737,7 @@ - (void)slk_processTextForAutoCompletion
{
NSString *text = self.textView.text;

if ((!self.isAutoCompleting && text.length == 0) || self.isTransitioning || ![self shouldProcessTextForAutoCompletion:text]) {
if ((!self.isAutoCompleting && text.length == 0) || self.isTransitioning || ![self shouldProcessTextForAutoCompletion]) {
return;
}

Expand Down

2 comments on commit 46113e0

@pchelnikov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dzenbot please, make hairlineView optional or customizable

@diegoperini
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huge kudos to you @dzenbot for fixing the iOS11 textinput interraction bug. <3

Please sign in to comment.