Skip to content

Commit e43ee9a

Browse files
committed
Fixed problem with setEnableAutoToolbar:false
1 parent f234ca1 commit e43ee9a

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

ios/ReactNativeKeyboardManager/RCTTextInput+Hack.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
#import "RCTTextInput.h"
2424
#import <Foundation/Foundation.h>
25+
#import "IQKeyboardManager.h"
2526

2627
@interface RCTTextInput (Hack)
2728

28-
- (void)invalidateInputAccessoryView;
29+
- (void)invalidateInputAccessoryView_avoid;
30+
- (void)invalidateInputAccessoryView_backup;
2931

3032
@end

ios/ReactNativeKeyboardManager/RCTTextInput+Hack.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@
2222

2323
#import "RCTTextInput+Hack.h"
2424

25+
2526
@implementation RCTTextInput (Hack)
2627

27-
- (void)invalidateInputAccessoryView {
28-
NSLog(@"ignoring RCTTextInput.invalidateInputAccessoryView");
28+
- (void)invalidateInputAccessoryView_avoid {
29+
NSLog(@"avoiding RCTTextInput.invalidateInputAccessoryView");
30+
if (![[IQKeyboardManager sharedManager] isEnableAutoToolbar]) {
31+
[self invalidateInputAccessoryView_backup];
32+
}
33+
}
34+
35+
- (void)invalidateInputAccessoryView_backup {
36+
NSLog(@"backup RCTTextInput.invalidateInputAccessoryView");
2937
}
3038

3139
@end

ios/ReactNativeKeyboardManager/ReactNativeKeyboardManager.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,38 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
// THE SOFTWARE.
2222

23+
#import <objc/runtime.h>
24+
#import <objc/message.h>
25+
2326
#import "ReactNativeKeyboardManager.h"
2427
#import "IQKeyboardManager.h"
2528
#import <React/RCTLog.h>
2629
#import <React/RCTRootView.h>
2730

31+
#import "RCTTextInput.h"
32+
2833
@implementation ReactNativeKeyboardManager
2934

35+
- (instancetype)init
36+
{
37+
self = [super init];
38+
if (self) {
39+
Swizzle([RCTTextInput class], @selector(invalidateInputAccessoryView_backup), @selector(invalidateInputAccessoryView));
40+
Swizzle([RCTTextInput class], @selector(invalidateInputAccessoryView), @selector(invalidateInputAccessoryView_avoid));
41+
}
42+
return self;
43+
}
44+
45+
void Swizzle(Class c, SEL orig, SEL new)
46+
{
47+
Method origMethod = class_getInstanceMethod(c, orig);
48+
Method newMethod = class_getInstanceMethod(c, new);
49+
if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
50+
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
51+
else
52+
method_exchangeImplementations(origMethod, newMethod);
53+
}
54+
3055
RCT_EXPORT_MODULE(ReactNativeKeyboardManager);
3156

3257
RCT_EXPORT_METHOD(setEnableDebugging: (BOOL) enabled) {

0 commit comments

Comments
 (0)