From 46113e08e411ff174793073e3d292c50b9d1964d Mon Sep 17 00:00:00 2001 From: Ignacio Romero Zurbuchen Date: Thu, 21 Sep 2017 17:13:23 -0700 Subject: [PATCH] Fixing the text input not being interactive since iOS 11 (#624) * Fixed Xcode warnings + deprecating -shouldProcessTextForAutoCompletion: * Making SLKTextInputbar a UIView subclass instead, with its own hairline layout. This fixes https://github.com/slackhq/SlackTextViewController/issues/604 rendering SLKTVC useless in iOS 11 since UIToolBar's view hierarchy has drastically changed since, conflicting with the internal outlets of SLKTextInputbar * Changelog --- CHANGELOG.md | 9 +++++ .../Messenger-Shared/MessageViewController.m | 4 +- Examples/Messenger.xcodeproj/project.pbxproj | 14 ++++++- .../contents.xcworkspacedata | 8 +++- Examples/Pods/Pods.xcodeproj/project.pbxproj | 39 ++++++++++++++----- Source/SLKTextInputbar.h | 2 +- Source/SLKTextInputbar.m | 23 +++++++++-- Source/SLKTextViewController.h | 1 - Source/SLKTextViewController.m | 13 ++----- 9 files changed, 85 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69dc6abf..1d7bd555 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/Examples/Messenger-Shared/MessageViewController.m b/Examples/Messenger-Shared/MessageViewController.m index 7b37371a..e1146f7c 100644 --- a/Examples/Messenger-Shared/MessageViewController.m +++ b/Examples/Messenger-Shared/MessageViewController.m @@ -522,9 +522,9 @@ - (BOOL)canShowTypingIndicator #endif } -- (BOOL)shouldProcessTextForAutoCompletion:(NSString *)text +- (BOOL)shouldProcessTextForAutoCompletion { - return [super shouldProcessTextForAutoCompletion:text]; + return [super shouldProcessTextForAutoCompletion]; } - (BOOL)shouldDisableTypingSuggestionForAutoCompletion diff --git a/Examples/Messenger.xcodeproj/project.pbxproj b/Examples/Messenger.xcodeproj/project.pbxproj index 6d68c32b..6b7851bf 100644 --- a/Examples/Messenger.xcodeproj/project.pbxproj +++ b/Examples/Messenger.xcodeproj/project.pbxproj @@ -422,7 +422,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Slack Technologies, Inc."; TargetAttributes = { 4F3EDB48199ED00F004C15D6 = { @@ -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; @@ -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; diff --git a/Examples/Messenger.xcworkspace/contents.xcworkspacedata b/Examples/Messenger.xcworkspace/contents.xcworkspacedata index 30f838d2..fce32a59 100644 --- a/Examples/Messenger.xcworkspace/contents.xcworkspacedata +++ b/Examples/Messenger.xcworkspace/contents.xcworkspacedata @@ -14,7 +14,13 @@ location = "group:../CHANGELOG.md"> + location = "group:../.github/CODE_OF_CONDUCT.md"> + + + + diff --git a/Examples/Pods/Pods.xcodeproj/project.pbxproj b/Examples/Pods/Pods.xcodeproj/project.pbxproj index 966eb5f3..eddac812 100644 --- a/Examples/Pods/Pods.xcodeproj/project.pbxproj +++ b/Examples/Pods/Pods.xcodeproj/project.pbxproj @@ -369,7 +369,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0900; }; buildConfigurationList = 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */; compatibilityVersion = "Xcode 3.2"; @@ -452,18 +452,28 @@ 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; 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; + 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; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_PREPROCESSOR_DEFINITIONS = "RELEASE=1"; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; @@ -471,7 +481,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; STRIP_INSTALLED_PRODUCT = NO; SYMROOT = "${SRCROOT}/../build"; VALIDATE_PRODUCT = YES; @@ -483,7 +493,7 @@ baseConfigurationReference = 98C98CDFB3F20F2925F6CD1F141BB14F /* Pods.release.xcconfig */; buildSettings = { ENABLE_STRICT_OBJC_MSGSEND = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACH_O_TYPE = staticlib; MTL_ENABLE_DEBUG_INFO = NO; OTHER_LDFLAGS = ""; @@ -501,7 +511,7 @@ buildSettings = { ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_PREFIX_HEADER = "Target Support Files/SlackTextViewController/SlackTextViewController-prefix.pch"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; OTHER_LDFLAGS = ""; OTHER_LIBTOOLFLAGS = ""; @@ -518,7 +528,7 @@ baseConfigurationReference = 4E762F23EC34ED4A6FF3312D84E33A40 /* Pods.debug.xcconfig */; buildSettings = { ENABLE_STRICT_OBJC_MSGSEND = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACH_O_TYPE = staticlib; MTL_ENABLE_DEBUG_INFO = YES; OTHER_LDFLAGS = ""; @@ -538,18 +548,29 @@ 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; 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; + 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; COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -562,7 +583,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; ONLY_ACTIVE_ARCH = YES; STRIP_INSTALLED_PRODUCT = NO; SYMROOT = "${SRCROOT}/../build"; @@ -575,7 +596,7 @@ buildSettings = { ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_PREFIX_HEADER = "Target Support Files/SlackTextViewController/SlackTextViewController-prefix.pch"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; OTHER_LDFLAGS = ""; OTHER_LIBTOOLFLAGS = ""; @@ -593,7 +614,7 @@ buildSettings = { ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_PREFIX_HEADER = "Target Support Files/LoremIpsum/LoremIpsum-prefix.pch"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; OTHER_LDFLAGS = ""; OTHER_LIBTOOLFLAGS = ""; @@ -611,7 +632,7 @@ buildSettings = { ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_PREFIX_HEADER = "Target Support Files/LoremIpsum/LoremIpsum-prefix.pch"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; OTHER_LDFLAGS = ""; OTHER_LIBTOOLFLAGS = ""; diff --git a/Source/SLKTextInputbar.h b/Source/SLKTextInputbar.h index 2ca5e0f6..74f21604 100644 --- a/Source/SLKTextInputbar.h +++ b/Source/SLKTextInputbar.h @@ -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. diff --git a/Source/SLKTextInputbar.m b/Source/SLKTextInputbar.m index d68a151b..83eaf99d 100644 --- a/Source/SLKTextInputbar.m +++ b/Source/SLKTextInputbar.m @@ -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; @@ -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]; @@ -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]; + } + return _hairlineView; +} + - (UIView *)contentView { if (!_contentView) { @@ -408,7 +422,8 @@ - (NSUInteger)slk_defaultNumberOfLines - (void)setBackgroundColor:(UIColor *)color { - self.barTintColor = color; + [super setBackgroundColor:color]; + self.editorContentView.backgroundColor = color; } @@ -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];; diff --git a/Source/SLKTextViewController.h b/Source/SLKTextViewController.h index ed77033f..aa66d0af 100644 --- a/Source/SLKTextViewController.h +++ b/Source/SLKTextViewController.h @@ -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. diff --git a/Source/SLKTextViewController.m b/Source/SLKTextViewController.m index b1eba07b..33d959bf 100644 --- a/Source/SLKTextViewController.m +++ b/Source/SLKTextViewController.m @@ -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; @@ -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; @@ -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) { @@ -1623,11 +1623,6 @@ - (void)registerPrefixesForAutoCompletion:(NSArray *)prefixes _registeredPrefixes = [NSSet setWithSet:set]; } -- (BOOL)shouldProcessTextForAutoCompletion:(NSString *)text -{ - return [self shouldProcessTextForAutoCompletion]; -} - - (BOOL)shouldProcessTextForAutoCompletion { if (!_registeredPrefixes || _registeredPrefixes.count == 0) { @@ -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; }