diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index d9c47ff16311d4..65885a4882a686 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -419,7 +419,7 @@ - (void)setCustomInputAccessoryViewWithNativeID:(NSString *)nativeID UIView *accessoryView = [strongSelf->_bridge.uiManager viewForNativeID:nativeID withRootTag:rootView.reactTag]; if (accessoryView && [accessoryView isKindOfClass:[RCTInputAccessoryView class]]) { - strongSelf.backedTextInputView.inputAccessoryView = ((RCTInputAccessoryView *)accessoryView).content.inputAccessoryView; + strongSelf.backedTextInputView.inputAccessoryView = ((RCTInputAccessoryView *)accessoryView).inputAccessoryView; [strongSelf reloadInputViewsIfNecessary]; } } diff --git a/Libraries/Text/TextInput/RCTInputAccessoryView.h b/Libraries/Text/TextInput/RCTInputAccessoryView.h index b2517534baf3bb..207203fc22321e 100644 --- a/Libraries/Text/TextInput/RCTInputAccessoryView.h +++ b/Libraries/Text/TextInput/RCTInputAccessoryView.h @@ -14,6 +14,4 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge; -@property (nonatomic, readonly, strong) RCTInputAccessoryViewContent *content; - @end diff --git a/Libraries/Text/TextInput/RCTInputAccessoryView.m b/Libraries/Text/TextInput/RCTInputAccessoryView.m index a1902a80ea5fd4..1f66e473966c06 100644 --- a/Libraries/Text/TextInput/RCTInputAccessoryView.m +++ b/Libraries/Text/TextInput/RCTInputAccessoryView.m @@ -13,56 +13,66 @@ #import "RCTInputAccessoryViewContent.h" +@interface RCTInputAccessoryView() + +// Overriding `inputAccessoryView` to `readwrite`. +@property (nonatomic, readwrite, retain) UIView *inputAccessoryView; + +@end + @implementation RCTInputAccessoryView { - BOOL _contentShouldBeFirstResponder; + BOOL _shouldBecomeFirstResponder; } - (instancetype)initWithBridge:(RCTBridge *)bridge { if (self = [super init]) { - _content = [RCTInputAccessoryViewContent new]; + _inputAccessoryView = [RCTInputAccessoryViewContent new]; RCTTouchHandler *const touchHandler = [[RCTTouchHandler alloc] initWithBridge:bridge]; - [touchHandler attachToView:_content.inputAccessoryView]; - [self addSubview:_content]; + [touchHandler attachToView:_inputAccessoryView]; } return self; } +- (BOOL)canBecomeFirstResponder +{ + return true; +} + - (void)reactSetFrame:(CGRect)frame { - [_content.inputAccessoryView setFrame:frame]; - [_content.contentView setFrame:frame]; + [_inputAccessoryView setFrame:frame]; - if (_contentShouldBeFirstResponder) { - _contentShouldBeFirstResponder = NO; - [_content becomeFirstResponder]; + if (_shouldBecomeFirstResponder) { + _shouldBecomeFirstResponder = NO; + [self becomeFirstResponder]; } } - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)index { [super insertReactSubview:subview atIndex:index]; - [_content insertReactSubview:subview atIndex:index]; + [_inputAccessoryView insertReactSubview:subview atIndex:index]; } - (void)removeReactSubview:(UIView *)subview { [super removeReactSubview:subview]; - [_content removeReactSubview:subview]; + [_inputAccessoryView removeReactSubview:subview]; } - (void)didUpdateReactSubviews { - // Do nothing, as subviews are managed by `insertReactSubview:atIndex:` + // Do nothing, as subviews are managed by `insertReactSubview:atIndex:`. } - (void)didSetProps:(NSArray *)changedProps { // If the accessory view is not linked to a text input via nativeID, assume it is - // a standalone component that should get focus whenever it is rendered + // a standalone component that should get focus whenever it is rendered. if (![changedProps containsObject:@"nativeID"] && !self.nativeID) { - _contentShouldBeFirstResponder = YES; + _shouldBecomeFirstResponder = YES; } } diff --git a/Libraries/Text/TextInput/RCTInputAccessoryViewContent.h b/Libraries/Text/TextInput/RCTInputAccessoryViewContent.h index 7c24d010e2d270..7dca711a648d83 100644 --- a/Libraries/Text/TextInput/RCTInputAccessoryViewContent.h +++ b/Libraries/Text/TextInput/RCTInputAccessoryViewContent.h @@ -9,6 +9,4 @@ @interface RCTInputAccessoryViewContent : UIView -@property (nonatomic, readwrite, retain) UIView *contentView; - @end diff --git a/Libraries/Text/TextInput/RCTInputAccessoryViewContent.m b/Libraries/Text/TextInput/RCTInputAccessoryViewContent.m index 3fb7fca715c608..73ec648ad8e128 100644 --- a/Libraries/Text/TextInput/RCTInputAccessoryViewContent.m +++ b/Libraries/Text/TextInput/RCTInputAccessoryViewContent.m @@ -9,65 +9,59 @@ #import -@interface RCTInputAccessoryViewContent() - -// Overriding `inputAccessoryView` to `readwrite`. -@property (nonatomic, readwrite, retain) UIView *inputAccessoryView; - -@end - @implementation RCTInputAccessoryViewContent +{ + UIView *_safeAreaContainer; +} -- (BOOL)canBecomeFirstResponder +- (instancetype)init { - return true; + if (self = [super init]) { + _safeAreaContainer = [UIView new]; + [self addSubview:_safeAreaContainer]; + } + return self; } -- (BOOL)becomeFirstResponder +- (void)didMoveToSuperview { - const BOOL becameFirstResponder = [super becomeFirstResponder]; - #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ - // Avoiding the home pill and notch (landscape mode) on iphoneX. - if (becameFirstResponder) { - if (@available(iOS 11.0, *)) { - [_contentView.bottomAnchor - constraintLessThanOrEqualToSystemSpacingBelowAnchor:_contentView.window.safeAreaLayoutGuide.bottomAnchor +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ + // Avoid the home pill (in portrait mode) and notch (in landscape mode) on iPhoneX. + if (@available(iOS 11.0, *)) { + if (self.window) { + [_safeAreaContainer.bottomAnchor + constraintLessThanOrEqualToSystemSpacingBelowAnchor:self.window.safeAreaLayoutGuide.bottomAnchor multiplier:1.0f].active = YES; - [_contentView.leftAnchor - constraintLessThanOrEqualToSystemSpacingAfterAnchor:_contentView.window.safeAreaLayoutGuide.leftAnchor + [_safeAreaContainer.leftAnchor + constraintGreaterThanOrEqualToSystemSpacingAfterAnchor:self.window.safeAreaLayoutGuide.leftAnchor multiplier:1.0f].active = YES; - [_contentView.rightAnchor - constraintLessThanOrEqualToSystemSpacingAfterAnchor:_contentView.window.safeAreaLayoutGuide.rightAnchor + [_safeAreaContainer.rightAnchor + constraintLessThanOrEqualToSystemSpacingAfterAnchor:self.window.safeAreaLayoutGuide.rightAnchor multiplier:1.0f].active = YES; } } - #endif +#endif - return becameFirstResponder; } -- (UIView *)inputAccessoryView +- (void)setFrame:(CGRect)frame { - if (!_inputAccessoryView) { - _inputAccessoryView = [UIView new]; - _contentView = [UIView new]; - [_inputAccessoryView addSubview:_contentView]; - } - return _inputAccessoryView; + [super setFrame:frame]; + [_safeAreaContainer setFrame:frame]; } - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)index { [super insertReactSubview:subview atIndex:index]; - [_contentView insertSubview:subview atIndex:index]; + [_safeAreaContainer insertSubview:subview atIndex:index]; } - (void)removeReactSubview:(UIView *)subview { [super removeReactSubview:subview]; [subview removeFromSuperview]; - if ([[_inputAccessoryView subviews] count] == 0 && [self isFirstResponder]) { + if ([[_safeAreaContainer subviews] count] == 0 && [self isFirstResponder]) { [self resignFirstResponder]; } } diff --git a/Libraries/Text/TextInput/RCTInputAccessoryViewManager.m b/Libraries/Text/TextInput/RCTInputAccessoryViewManager.m index b293889eb6de84..aeeff835e844b4 100644 --- a/Libraries/Text/TextInput/RCTInputAccessoryViewManager.m +++ b/Libraries/Text/TextInput/RCTInputAccessoryViewManager.m @@ -23,6 +23,6 @@ - (UIView *)view return [[RCTInputAccessoryView alloc] initWithBridge:self.bridge]; } -RCT_REMAP_VIEW_PROPERTY(backgroundColor, content.inputAccessoryView.backgroundColor, UIColor) +RCT_REMAP_VIEW_PROPERTY(backgroundColor, inputAccessoryView.backgroundColor, UIColor) @end