Skip to content

Commit ecf2ca8

Browse files
committed
Comments and newlines
1 parent 765cc7b commit ecf2ca8

4 files changed

Lines changed: 27 additions & 12 deletions

File tree

‎packages/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ class KeyboardAvoidingView extends React.Component<
286286
this._updateSubscriptions();
287287
}
288288

289-
// Only the JavaScript implementation uses keyboard events.
290289
_updateSubscriptions(): void {
291290
const shouldSubscribe = !shouldUseNative(this.props);
292291

@@ -298,12 +297,15 @@ class KeyboardAvoidingView extends React.Component<
298297
this._subscriptions.forEach(subscription => {
299298
subscription.remove();
300299
});
300+
301301
this._subscriptions = [];
302302
// The last event goes stale while unsubscribed.
303303
this._keyboardEvent = null;
304+
304305
if (this._bottom !== 0) {
305306
this._setBottom(0);
306307
}
308+
307309
return;
308310
}
309311

‎packages/react-native/React/Fabric/Mounting/ComponentViews/KeyboardAvoidingView/RCTKeyboardAvoidingViewComponentView.mm‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ @implementation RCTKeyboardAvoidingViewComponentView {
4040
// The window guide never updates, and the guide of this view moves on resize.
4141
__weak UIView *_guideOwnerView;
4242
BOOL _isUpdateScheduled;
43-
4443
CGFloat _minTrackingHeight;
4544
CGSize _guideOwnerSize;
4645
CGFloat _guideOwnerBottomSafeArea;
4746
BOOL _isTrackingViewLaidOut;
48-
4947
CGFloat _keyboardInset;
5048
// `height` shrinks this view, so measure it while the keyboard doesn't overlap.
5149
CGFloat _restingHeight;
@@ -80,20 +78,24 @@ - (void)didMoveToWindow
8078
_trackingView = nil;
8179

8280
UIWindow *window = self.window;
81+
8382
if (window == nil) {
8483
return;
8584
}
8685

8786
UIView *guideOwnerView = window.rootViewController.view;
87+
8888
for (UIResponder *responder = self.nextResponder; responder != nil; responder = responder.nextResponder) {
8989
if ([responder isKindOfClass:[UIViewController class]]) {
9090
guideOwnerView = ((UIViewController *)responder).view;
9191
break;
9292
}
9393
}
94+
9495
if (guideOwnerView == nil) {
9596
return;
9697
}
98+
9799
_guideOwnerView = guideOwnerView;
98100
_guideOwnerSize = CGSizeZero;
99101
_isTrackingViewLaidOut = NO;
@@ -107,14 +109,18 @@ - (void)didMoveToWindow
107109
_trackingView = [RCTKeyboardTrackingView new];
108110
_trackingView.translatesAutoresizingMaskIntoConstraints = NO;
109111
__weak __typeof(self) weakSelf = self;
112+
110113
_trackingView.onLayout = ^{
111114
__typeof(self) strongSelf = weakSelf;
115+
112116
if (strongSelf == nil) {
113117
return;
114118
}
119+
115120
strongSelf->_isTrackingViewLaidOut = YES;
116121
[strongSelf _updateKeyboardInset];
117122
};
123+
118124
[_trackingContainerView addSubview:_trackingView];
119125

120126
[NSLayoutConstraint activateConstraints:@[
@@ -133,13 +139,15 @@ - (void)didMoveToWindow
133139
- (void)_keyboardWillChangeFrame:(NSNotification *)notification
134140
{
135141
UIView *trackingContainerView = _trackingContainerView;
142+
136143
if (trackingContainerView == nil) {
137144
return;
138145
}
139146

140147
NSTimeInterval duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
141148
UIViewAnimationCurve curve =
142149
(UIViewAnimationCurve)[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
150+
143151
[UIView animateWithDuration:duration
144152
delay:0
145153
options:(UIViewAnimationOptions)curve << 16 | UIViewAnimationOptionBeginFromCurrentState
@@ -153,17 +161,21 @@ - (CGFloat)_hiddenKeyboardTrackingHeight
153161
{
154162
// Capped at the bottom safe area, for when the keyboard was never hidden.
155163
UIView *guideOwnerView = _guideOwnerView;
164+
156165
if (guideOwnerView == nil) {
157166
return 0;
158167
}
168+
159169
CGFloat bottomSafeArea =
160170
MAX(CGRectGetMaxY(guideOwnerView.bounds) - CGRectGetMaxY(guideOwnerView.safeAreaLayoutGuide.layoutFrame), 0);
171+
161172
// The hidden guide follows the bottom safe area, which can change without a resize.
162173
if (!CGSizeEqualToSize(guideOwnerView.bounds.size, _guideOwnerSize) || bottomSafeArea != _guideOwnerBottomSafeArea) {
163174
_guideOwnerSize = guideOwnerView.bounds.size;
164175
_guideOwnerBottomSafeArea = bottomSafeArea;
165176
_minTrackingHeight = CGFLOAT_MAX;
166177
}
178+
167179
_minTrackingHeight = MIN(_minTrackingHeight, _trackingView.bounds.size.height);
168180
return MIN(bottomSafeArea, _minTrackingHeight);
169181
}
@@ -173,13 +185,17 @@ - (void)_scheduleUpdate
173185
if (_isUpdateScheduled) {
174186
return;
175187
}
188+
176189
_isUpdateScheduled = YES;
177190
__weak __typeof(self) weakSelf = self;
191+
178192
dispatch_async(dispatch_get_main_queue(), ^{
179193
__typeof(self) strongSelf = weakSelf;
194+
180195
if (strongSelf == nil) {
181196
return;
182197
}
198+
183199
strongSelf->_isUpdateScheduled = NO;
184200
[strongSelf _updateKeyboardInset];
185201
});
@@ -199,6 +215,7 @@ - (void)_updateKeyboardInset
199215

200216
CGFloat inset = 0;
201217
BOOL isKeyboardVisible = _trackingView.bounds.size.height > [self _hiddenKeyboardTrackingHeight];
218+
202219
if (props.enabled && isKeyboardVisible) {
203220
CGFloat keyboardY = CGRectGetMinY(_trackingView.frame) - props.keyboardVerticalOffset;
204221
inset = MAX(_layoutMetrics.frame.origin.y + _restingHeight - keyboardY, 0);
@@ -207,9 +224,10 @@ - (void)_updateKeyboardInset
207224
if (inset == _keyboardInset) {
208225
return;
209226
}
210-
_keyboardInset = inset;
211227

228+
_keyboardInset = inset;
212229
CGFloat maxHeight = inset > 0 ? MAX(_restingHeight - inset, 0) : INFINITY;
230+
213231
// A `folly::dynamic` payload, which C++ Native Animated can read.
214232
_eventEmitter->dispatchUniqueEvent(
215233
"keyboardInsetChange", folly::dynamic::object("inset", inset)("maxHeight", maxHeight));

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/keyboardavoidingview/KeyboardInsetChangeEvent.kt‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import com.facebook.react.bridge.Arguments
1111
import com.facebook.react.bridge.WritableMap
1212
import com.facebook.react.uimanager.events.Event
1313

14-
/**
15-
* [Event] with the keyboard overlap and the matching `maxHeight`, in dp. `maxHeight` is infinite
16-
* when the keyboard doesn't overlap, which unsets it.
17-
*/
1814
internal class KeyboardInsetChangeEvent(
1915
surfaceId: Int,
2016
viewTag: Int,

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/keyboardavoidingview/ReactKeyboardAvoidingView.kt‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ import com.facebook.react.uimanager.PixelUtil.pxToDp
1818
import com.facebook.react.uimanager.UIManagerHelper
1919
import com.facebook.react.views.view.ReactViewGroup
2020

21-
/**
22-
* Sends the keyboard overlap from [WindowInsetsAnimationCompat] as an event. Before Android 11, the
23-
* compat animation runs on its own curve after the insets change, not with the keyboard.
24-
*/
2521
internal class ReactKeyboardAvoidingView(context: Context) : ReactViewGroup(context) {
2622

2723
internal var isAvoidanceEnabled: Boolean = true
@@ -135,6 +131,7 @@ internal class ReactKeyboardAvoidingView(context: Context) : ReactViewGroup(cont
135131
if (keyboardHeight <= 0f) {
136132
return 0f
137133
}
134+
138135
val frameY = top.toFloat().pxToDp()
139136
val keyboardY = rootView.height.toFloat().pxToDp() - keyboardHeight - keyboardVerticalOffset
140137
return maxOf(frameY + restingHeight - keyboardY, 0f)
@@ -147,6 +144,7 @@ internal class ReactKeyboardAvoidingView(context: Context) : ReactViewGroup(cont
147144
}
148145

149146
val inset = if (isAvoidanceEnabled) keyboardOverlap(keyboardHeight) else 0f
147+
150148
if (inset == keyboardInset) {
151149
return
152150
}
@@ -155,6 +153,7 @@ internal class ReactKeyboardAvoidingView(context: Context) : ReactViewGroup(cont
155153
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id) ?: return
156154
keyboardInset = inset
157155
val maxHeight = if (inset > 0f) maxOf(restingHeight - inset, 0f) else Float.POSITIVE_INFINITY
156+
158157
eventDispatcher.dispatchEvent(
159158
KeyboardInsetChangeEvent(UIManagerHelper.getSurfaceId(this), id, inset, maxHeight)
160159
)

0 commit comments

Comments
 (0)