|
9 | 9 |
|
10 | 10 | #import <React/UIView+React.h> |
11 | 11 |
|
12 | | -@interface RCTInputAccessoryViewContent() |
13 | | - |
14 | | -// Overriding `inputAccessoryView` to `readwrite`. |
15 | | -@property (nonatomic, readwrite, retain) UIView *inputAccessoryView; |
16 | | - |
17 | | -@end |
18 | | - |
19 | 12 | @implementation RCTInputAccessoryViewContent |
| 13 | +{ |
| 14 | + UIView *_safeAreaContainer; |
| 15 | +} |
20 | 16 |
|
21 | | -- (BOOL)canBecomeFirstResponder |
| 17 | +- (instancetype)init |
22 | 18 | { |
23 | | - return true; |
| 19 | + if (self = [super init]) { |
| 20 | + _safeAreaContainer = [UIView new]; |
| 21 | + [self addSubview:_safeAreaContainer]; |
| 22 | + } |
| 23 | + return self; |
24 | 24 | } |
25 | 25 |
|
26 | | -- (BOOL)becomeFirstResponder |
| 26 | +- (void)didMoveToSuperview |
27 | 27 | { |
28 | | - const BOOL becameFirstResponder = [super becomeFirstResponder]; |
29 | 28 |
|
30 | | - #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ |
31 | | - // Avoiding the home pill and notch (landscape mode) on iphoneX. |
32 | | - if (becameFirstResponder) { |
33 | | - if (@available(iOS 11.0, *)) { |
34 | | - [_contentView.bottomAnchor |
35 | | - constraintLessThanOrEqualToSystemSpacingBelowAnchor:_contentView.window.safeAreaLayoutGuide.bottomAnchor |
| 29 | +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ |
| 30 | + // Avoid the home pill (in portrait mode) and notch (in landscape mode) on iPhoneX. |
| 31 | + if (@available(iOS 11.0, *)) { |
| 32 | + if (self.window) { |
| 33 | + [_safeAreaContainer.bottomAnchor |
| 34 | + constraintLessThanOrEqualToSystemSpacingBelowAnchor:self.window.safeAreaLayoutGuide.bottomAnchor |
36 | 35 | multiplier:1.0f].active = YES; |
37 | | - [_contentView.leftAnchor |
38 | | - constraintLessThanOrEqualToSystemSpacingAfterAnchor:_contentView.window.safeAreaLayoutGuide.leftAnchor |
| 36 | + [_safeAreaContainer.leftAnchor |
| 37 | + constraintGreaterThanOrEqualToSystemSpacingAfterAnchor:self.window.safeAreaLayoutGuide.leftAnchor |
39 | 38 | multiplier:1.0f].active = YES; |
40 | | - [_contentView.rightAnchor |
41 | | - constraintLessThanOrEqualToSystemSpacingAfterAnchor:_contentView.window.safeAreaLayoutGuide.rightAnchor |
| 39 | + [_safeAreaContainer.rightAnchor |
| 40 | + constraintLessThanOrEqualToSystemSpacingAfterAnchor:self.window.safeAreaLayoutGuide.rightAnchor |
42 | 41 | multiplier:1.0f].active = YES; |
43 | 42 | } |
44 | 43 | } |
45 | | - #endif |
| 44 | +#endif |
46 | 45 |
|
47 | | - return becameFirstResponder; |
48 | 46 | } |
49 | 47 |
|
50 | | -- (UIView *)inputAccessoryView |
| 48 | +- (void)setFrame:(CGRect)frame |
51 | 49 | { |
52 | | - if (!_inputAccessoryView) { |
53 | | - _inputAccessoryView = [UIView new]; |
54 | | - _contentView = [UIView new]; |
55 | | - [_inputAccessoryView addSubview:_contentView]; |
56 | | - } |
57 | | - return _inputAccessoryView; |
| 50 | + [super setFrame:frame]; |
| 51 | + [_safeAreaContainer setFrame:frame]; |
58 | 52 | } |
59 | 53 |
|
60 | 54 | - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)index |
61 | 55 | { |
62 | 56 | [super insertReactSubview:subview atIndex:index]; |
63 | | - [_contentView insertSubview:subview atIndex:index]; |
| 57 | + [_safeAreaContainer insertSubview:subview atIndex:index]; |
64 | 58 | } |
65 | 59 |
|
66 | 60 | - (void)removeReactSubview:(UIView *)subview |
67 | 61 | { |
68 | 62 | [super removeReactSubview:subview]; |
69 | 63 | [subview removeFromSuperview]; |
70 | | - if ([[_inputAccessoryView subviews] count] == 0 && [self isFirstResponder]) { |
| 64 | + if ([[_safeAreaContainer subviews] count] == 0 && [self isFirstResponder]) { |
71 | 65 | [self resignFirstResponder]; |
72 | 66 | } |
73 | 67 | } |
|
0 commit comments