Skip to content

Commit

Permalink
Fixed scrollview inset when RN view is embedded in another view
Browse files Browse the repository at this point in the history
This happened to me mainly in modal view controllers on iOS 13, where the view controller is floating and does not start from the top.
  • Loading branch information
danielgindi committed Apr 1, 2020
1 parent 227aa96 commit 30a9935
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 30a9935

Please sign in to comment.