mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-19 19:05:45 +08:00
Support Input Accessory View (iOS Only) [1/N]
Reviewed By: mmmulani Differential Revision: D6886573 fbshipit-source-id: 71e1f812b1cc1698e4380211a6cedd59011b5495
This commit is contained in:
committed by
Facebook Github Bot
parent
c87d03a8b2
commit
38197c8230
@@ -15,6 +15,8 @@
|
||||
#import <React/RCTUtils.h>
|
||||
#import <React/UIView+React.h>
|
||||
|
||||
#import "RCTInputAccessoryView.h"
|
||||
#import "RCTInputAccessoryViewContent.h"
|
||||
#import "RCTTextAttributes.h"
|
||||
#import "RCTTextSelection.h"
|
||||
|
||||
@@ -400,12 +402,33 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
||||
|
||||
- (void)didSetProps:(NSArray<NSString *> *)changedProps
|
||||
{
|
||||
[self invalidateInputAccessoryView];
|
||||
#if !TARGET_OS_TV
|
||||
if ([changedProps containsObject:@"inputAccessoryViewID"] && self.inputAccessoryViewID) {
|
||||
[self setCustomInputAccessoryViewWithNativeID:self.inputAccessoryViewID];
|
||||
} else if (!self.inputAccessoryViewID) {
|
||||
[self setDefaultInputAccessoryView];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)invalidateInputAccessoryView
|
||||
- (void)setCustomInputAccessoryViewWithNativeID:(NSString *)nativeID
|
||||
{
|
||||
__weak RCTBaseTextInputView *weakSelf = self;
|
||||
[_bridge.uiManager rootViewForReactTag:self.reactTag withCompletion:^(UIView *rootView) {
|
||||
RCTBaseTextInputView *strongSelf = weakSelf;
|
||||
if (rootView) {
|
||||
UIView *accessoryView = [strongSelf->_bridge.uiManager viewForNativeID:nativeID
|
||||
withRootTag:rootView.reactTag];
|
||||
if (accessoryView && [accessoryView isKindOfClass:[RCTInputAccessoryView class]]) {
|
||||
strongSelf.backedTextInputView.inputAccessoryView = ((RCTInputAccessoryView *)accessoryView).content.inputAccessoryView;
|
||||
[strongSelf reloadInputViewsIfNecessary];
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setDefaultInputAccessoryView
|
||||
{
|
||||
#if !TARGET_OS_TV
|
||||
UIView<RCTBackedTextInputViewProtocol> *textInputView = self.backedTextInputView;
|
||||
UIKeyboardType keyboardType = textInputView.keyboardType;
|
||||
|
||||
@@ -443,12 +466,15 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
||||
else {
|
||||
textInputView.inputAccessoryView = nil;
|
||||
}
|
||||
[self reloadInputViewsIfNecessary];
|
||||
}
|
||||
|
||||
- (void)reloadInputViewsIfNecessary
|
||||
{
|
||||
// We have to call `reloadInputViews` for focused text inputs to update an accessory view.
|
||||
if (textInputView.isFirstResponder) {
|
||||
[textInputView reloadInputViews];
|
||||
if (self.backedTextInputView.isFirstResponder) {
|
||||
[self.backedTextInputView reloadInputViews];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)handleInputAccessoryDoneButton
|
||||
|
||||
Reference in New Issue
Block a user