Skip to content

Commit

Permalink
Fix infinite loop in KeyboardAvoidingView
Browse files Browse the repository at this point in the history
Summary:
Changelog: [General][Fixed] Fix stalling UI due to a bug in KeyboardAvoidingView

I introduced this bug in D22764192 (b08fff6).

The stalling was caused by onLayout in JavaScript triggering native layout which called onLayout in JavaScript without terminating condition.

The fix is to only cause native layout once from JavaScript's onLayout function. This makes sure both Fabric and Paper works correctly and UI stall isn't caused.

Resolves:
#30495
#30532

Reviewed By: TheSavior

Differential Revision: D25522362

fbshipit-source-id: 602e540bb1c40ae4f421b3e6ebc5a047cd920c17
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Dec 15, 2020
1 parent 7485208 commit 6730927
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Libraries/Components/Keyboard/KeyboardAvoidingView.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
};

_onLayout = (event: ViewLayoutEvent) => {
const wasFrameNull = this._frame == null;
this._frame = event.nativeEvent.layout;
if (!this._initialFrameHeight) {
// save the initial frame height, before the keyboard is visible
this._initialFrameHeight = this._frame.height;
}

this._updateBottomIfNecesarry();
if (wasFrameNull) {
this._updateBottomIfNecesarry();
}
};

_updateBottomIfNecesarry = () => {
Expand Down

0 comments on commit 6730927

Please sign in to comment.