|
12 | 12 | @implementation RCTInputAccessoryViewContent
|
13 | 13 | {
|
14 | 14 | UIView *_safeAreaContainer;
|
| 15 | + NSLayoutConstraint *_heightConstraint; |
15 | 16 | }
|
16 | 17 |
|
17 | 18 | - (instancetype)init
|
18 | 19 | {
|
19 | 20 | if (self = [super init]) {
|
20 | 21 | _safeAreaContainer = [UIView new];
|
21 | 22 | [self addSubview:_safeAreaContainer];
|
22 |
| - } |
23 |
| - return self; |
24 |
| -} |
25 | 23 |
|
26 |
| -- (void)didMoveToSuperview |
27 |
| -{ |
| 24 | + // Use autolayout to position the view properly and take into account |
| 25 | + // safe area insets on iPhone X. |
| 26 | + // TODO: Support rotation, anchor to left and right without breaking frame x coordinate (T27974328). |
| 27 | + self.autoresizingMask = UIViewAutoresizingFlexibleHeight; |
| 28 | + _safeAreaContainer.translatesAutoresizingMaskIntoConstraints = NO; |
| 29 | + |
| 30 | + _heightConstraint = [_safeAreaContainer.heightAnchor constraintEqualToConstant:0]; |
| 31 | + _heightConstraint.active = YES; |
28 | 32 |
|
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) |
31 |
| - // TODO: Support rotation, anchor to left and right without breaking frame x coordinate (T27974328). |
32 |
| - if (@available(iOS 11.0, *)) { |
33 |
| - if (self.window) { |
34 |
| - [_safeAreaContainer.bottomAnchor |
35 |
| - constraintLessThanOrEqualToSystemSpacingBelowAnchor:self.window.safeAreaLayoutGuide.bottomAnchor |
36 |
| - multiplier:1.0f].active = YES; |
| 33 | + if (@available(iOS 11.0, *)) { |
| 34 | + [_safeAreaContainer.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor].active = YES; |
| 35 | + [_safeAreaContainer.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor].active = YES; |
| 36 | + [_safeAreaContainer.leadingAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.leadingAnchor].active = YES; |
| 37 | + [_safeAreaContainer.trailingAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.trailingAnchor].active = YES; |
| 38 | + } else { |
| 39 | + [_safeAreaContainer.bottomAnchor constraintEqualToAnchor:self.bottomAnchor].active = YES; |
| 40 | + [_safeAreaContainer.topAnchor constraintEqualToAnchor:self.topAnchor].active = YES; |
| 41 | + [_safeAreaContainer.leadingAnchor constraintEqualToAnchor:self.leadingAnchor].active = YES; |
| 42 | + [_safeAreaContainer.trailingAnchor constraintEqualToAnchor:self.trailingAnchor].active = YES; |
37 | 43 | }
|
38 | 44 | }
|
39 |
| -#endif |
| 45 | + return self; |
| 46 | +} |
40 | 47 |
|
| 48 | +- (CGSize)intrinsicContentSize |
| 49 | +{ |
| 50 | + // This is needed so the view size is based on autolayout constraints. |
| 51 | + return CGSizeZero; |
41 | 52 | }
|
42 | 53 |
|
43 |
| -- (void)setFrame:(CGRect)frame |
| 54 | +- (void)reactSetFrame:(CGRect)frame |
44 | 55 | {
|
45 |
| - [super setFrame:frame]; |
| 56 | + // We still need to set the frame here, otherwise it won't be |
| 57 | + // measured until moved to the window during the keyboard opening |
| 58 | + // animation. If this happens, the height will be animated from 0 to |
| 59 | + // its actual size and we don't want that. |
| 60 | + [self setFrame:frame]; |
46 | 61 | [_safeAreaContainer setFrame:frame];
|
| 62 | + |
| 63 | + _heightConstraint.constant = frame.size.height; |
| 64 | + [self layoutIfNeeded]; |
47 | 65 | }
|
48 | 66 |
|
49 | 67 | - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)index
|
|
0 commit comments