Skip to content

Commit

Permalink
Fixed scrollview inset when RN view is embedded in another view (#27607)
Browse files Browse the repository at this point in the history
Summary:
I'm using RNN, which embeds RN view inside native view controllers.

On iOS 13, a modal view controller is "floating" and is offset from the top of the screen.

This causes the calculation of inset in `KeyboardAvoidingView` incorrect as it mixes local view controller coordinate space, with keyboard's screen coordinate space.

## Changelog

[iOS] [Fixed] - Fixed `KeyboardAvoidingView` inset in embedded views (i.e modal view controllers on iOS 13)
Pull Request resolved: #27607

Test Plan:
1. Tested before and after in a simple view controller (should stay the same)
2. Tested before and after in a modal view controller (should be offset before, and fixed after)
3. Repeated no. 2 with each device rotation (upsideDown, landscapeLeft, landscapeRight)

Reviewed By: cpojer

Differential Revision: D20812231

Pulled By: TheSavior

fbshipit-source-id: fbd72739fb7152655028730e284ad26ff4a5da73
  • Loading branch information
danielgindi authored and facebook-github-bot committed Apr 3, 2020
1 parent 5c4425a commit fb2900e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Libraries/Components/Keyboard/KeyboardAvoidingView.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,28 @@ class KeyboardAvoidingView extends React.Component<Props, State> {

_onLayout = (event: ViewLayoutEvent) => {
this._frame = event.nativeEvent.layout;
if (!this._initialFrameHeight) {

let isInitial = !this._initialFrameHeight;

if (this.viewRef.current !== null) {
// Try to measure inside the window, not the view controller
this.viewRef.current.measureInWindow((x, y, width, height) => {
const frame: ViewLayout = {
x: x,
y: y,
width: width,
height: height,
};
this._frame = frame;

if (isInitial) {
// save the initial frame height, before the keyboard is visible
this._initialFrameHeight = frame.height;
}
});
}

if (isInitial) {
// save the initial frame height, before the keyboard is visible
this._initialFrameHeight = this._frame.height;
}
Expand Down

0 comments on commit fb2900e

Please sign in to comment.