Skip to content

Commit 96120f0

Browse files
author
ignacio
committed
Deprecates shouldForceTextInputbarAdjustment. Replaced with -forceTextInputbarAdjustmentForResponder: to allow a more selective verification of when the text input bar should adjust even when it is not the first responder.
This uses an experimental API to detect the current first responder.
1 parent fb34497 commit 96120f0

File tree

6 files changed

+101
-4
lines changed

6 files changed

+101
-4
lines changed

Examples/Messenger/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Copyright 2014 Slack Technologies, Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#import <UIKit/UIKit.h>
18+
19+
/** @name UIResponder additional features used for SlackTextViewController. */
20+
@interface UIResponder (SLKAdditions)
21+
22+
/**
23+
Returns the current first responder object.
24+
@discussion This is an experimental API. Use it at your own risk.
25+
26+
@return A UIResponder instance.
27+
*/
28+
+ (instancetype)slk_currentFirstResponder;
29+
30+
@end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Copyright 2014 Slack Technologies, Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#import "UIResponder+SLKAdditions.h"
18+
19+
static __weak id ___currentFirstResponder;
20+
21+
@implementation UIResponder (SLKAdditions)
22+
23+
/**
24+
Based on Jakob Egger's answer in http://stackoverflow.com/a/14135456/590010
25+
*/
26+
+ (instancetype)slk_currentFirstResponder
27+
{
28+
___currentFirstResponder = nil;
29+
[[UIApplication sharedApplication] sendAction:@selector(slk_findFirstResponder:) to:nil from:nil forEvent:nil];
30+
return ___currentFirstResponder;
31+
}
32+
33+
- (void)slk_findFirstResponder:(id)sender
34+
{
35+
___currentFirstResponder = self;
36+
}
37+
38+
@end

Source/Additions/UIScrollView+SLKAdditions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828

2929
/**
3030
Sets the content offset to the top.
31+
3132
@param animated YES to animate the transition at a constant velocity to the new offset, NO to make the transition immediate.
3233
*/
3334
- (void)slk_scrollToTopAnimated:(BOOL)animated;
3435

3536
/**
3637
Sets the content offset to the bottom.
38+
3739
@param animated YES to animate the transition at a constant velocity to the new offset, NO to make the transition immediate.
3840
*/
3941
- (void)slk_scrollToBottomAnimated:(BOOL)animated;

Source/Classes/SLKTextViewController.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ NS_CLASS_AVAILABLE_IOS(7_0) @interface SLKTextViewController : UIViewController
8383
@property (nonatomic, assign) BOOL shouldClearTextAtRightButtonPress;
8484

8585
/** YES if the text input bar should still move up/down when other text inputs interacts with the keyboard. Default is NO. */
86-
@property (nonatomic, assign) BOOL shouldForceTextInputbarAdjustment;
86+
@property (nonatomic, assign) BOOL shouldForceTextInputbarAdjustment DEPRECATED_MSG_ATTRIBUTE("Use -forceTextInputbarAdjustmentForResponder:");
8787

8888
/** YES if the scrollView should scroll to bottom when the keyboard is shown. Default is NO.*/
8989
@property (nonatomic, assign) BOOL shouldScrollToBottomAfterKeyboardShows;
@@ -185,6 +185,15 @@ NS_CLASS_AVAILABLE_IOS(7_0) @interface SLKTextViewController : UIViewController
185185
*/
186186
- (void)dismissKeyboard:(BOOL)animated;
187187

188+
/**
189+
Verifies if the text input bar should still move up/down even if it is not first responder. Default is NO.
190+
You can override this method to perform additional tasks associated with presenting the view. You don't need call super since this method doesn't do anything.
191+
192+
@param responder The current first responder object.
193+
@return YES so the text input bar still move up/down.
194+
*/
195+
- (BOOL)forceTextInputbarAdjustmentForResponder:(UIResponder *)responder;
196+
188197
/**
189198
Notifies the view controller that the keyboard changed status.
190199
You can override this method to perform additional tasks associated with presenting the view. You don't need call super since this method doesn't do anything.

Source/Classes/SLKTextViewController.m

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

1717
#import "SLKTextViewController.h"
1818
#import "SLKInputAccessoryView.h"
19+
#import "UIResponder+SLKAdditions.h"
1920
#import "SLKUIConstants.h"
2021

2122
NSString * const SLKKeyboardWillShowNotification = @"SLKKeyboardWillShowNotification";
@@ -160,7 +161,6 @@ - (void)slk_commonInit
160161
self.shakeToClearEnabled = NO;
161162
self.keyboardPanningEnabled = YES;
162163
self.shouldClearTextAtRightButtonPress = YES;
163-
self.shouldForceTextInputbarAdjustment = NO;
164164
self.shouldScrollToBottomAfterKeyboardShows = NO;
165165
}
166166

@@ -666,6 +666,14 @@ - (void)dismissKeyboard:(BOOL)animated
666666
}
667667
}
668668

669+
- (BOOL)forceTextInputbarAdjustmentForResponder:(UIResponder *)responder
670+
{
671+
#pragma GCC diagnostic push
672+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
673+
return self.shouldForceTextInputbarAdjustment;
674+
#pragma GCC diagnostic pop
675+
}
676+
669677
- (void)didChangeKeyboardStatus:(SLKKeyboardStatus)status
670678
{
671679
// No implementation here. Meant to be overriden in subclass.
@@ -1124,9 +1132,11 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification
11241132
return;
11251133
}
11261134

1135+
NSLog(@"slk_currentFirstResponder : %@", [UIResponder slk_currentFirstResponder]);
1136+
11271137
// Skips this it's not the expected textView and shouldn't force adjustment of the text input bar.
11281138
// This will also dismiss the text input bar if it's visible, and exit auto-completion mode if enabled.
1129-
if (![self.textView isFirstResponder] && !self.shouldForceTextInputbarAdjustment) {
1139+
if (![self.textView isFirstResponder] && ![self forceTextInputbarAdjustmentForResponder:[UIResponder slk_currentFirstResponder]]) {
11301140
return [self slk_dismissTextInputbarIfNeeded];
11311141
}
11321142

0 commit comments

Comments
 (0)