-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21124 from adamgrzybowski/@swm/navigation-refacto…
…r-disable-keyboard-avoiding-view [navigation-refactor ] Disable KeyboardAvoidingView for the BaseSidebarScreen and fix KeyboardAvoidingView used with react-freeze
- Loading branch information
Showing
5 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
diff --git a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js | ||
index 2f48f9e..6418c76 100644 | ||
--- a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js | ||
+++ b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js | ||
@@ -65,6 +65,7 @@ class KeyboardAvoidingView extends React.Component<Props, State> { | ||
_subscriptions: Array<EventSubscription> = []; | ||
viewRef: {current: React.ElementRef<typeof View> | null, ...}; | ||
_initialFrameHeight: number = 0; | ||
+ _bottom: number = 0; | ||
|
||
constructor(props: Props) { | ||
super(props); | ||
@@ -107,18 +108,20 @@ class KeyboardAvoidingView extends React.Component<Props, State> { | ||
|
||
_onKeyboardChange = (event: ?KeyboardEvent) => { | ||
this._keyboardEvent = event; | ||
+ // $FlowFixMe[unused-promise] | ||
this._updateBottomIfNecessary(); | ||
}; | ||
|
||
_onLayout = async (event: ViewLayoutEvent) => { | ||
- const wasFrameNull = this._frame == null; | ||
+ const oldFrame = this._frame; | ||
this._frame = event.nativeEvent.layout; | ||
if (!this._initialFrameHeight) { | ||
// save the initial frame height, before the keyboard is visible | ||
this._initialFrameHeight = this._frame.height; | ||
} | ||
|
||
- if (wasFrameNull) { | ||
+ // update bottom height for the first time or when the height is changed | ||
+ if (!oldFrame || oldFrame.height !== this._frame.height) { | ||
await this._updateBottomIfNecessary(); | ||
} | ||
|
||
@@ -127,20 +130,31 @@ class KeyboardAvoidingView extends React.Component<Props, State> { | ||
} | ||
}; | ||
|
||
+ // Avoid unnecessary renders if the KeyboardAvoidingView is disabled. | ||
+ _setBottom = (value: number) => { | ||
+ const {enabled = true} = this.props; | ||
+ this._bottom = value; | ||
+ if (enabled) { | ||
+ this.setState({bottom: value}); | ||
+ } | ||
+ }; | ||
+ | ||
_updateBottomIfNecessary = async () => { | ||
if (this._keyboardEvent == null) { | ||
- this.setState({bottom: 0}); | ||
+ this._setBottom(0); | ||
return; | ||
} | ||
|
||
const {duration, easing, endCoordinates} = this._keyboardEvent; | ||
const height = await this._relativeKeyboardHeight(endCoordinates); | ||
|
||
- if (this.state.bottom === height) { | ||
+ if (this._bottom === height) { | ||
return; | ||
} | ||
|
||
- if (duration && easing) { | ||
+ this._setBottom(height); | ||
+ | ||
+ if (enabled && duration && easing) { | ||
LayoutAnimation.configureNext({ | ||
// We have to pass the duration equal to minimal accepted duration defined here: RCTLayoutAnimation.m | ||
duration: duration > 10 ? duration : 10, | ||
@@ -150,9 +164,15 @@ class KeyboardAvoidingView extends React.Component<Props, State> { | ||
}, | ||
}); | ||
} | ||
- this.setState({bottom: height}); | ||
}; | ||
|
||
+ componentDidUpdate(_: Props, prevState: State): void { | ||
+ const {enabled = true} = this.props; | ||
+ if (enabled && this._bottom !== prevState.bottom) { | ||
+ this.setState({bottom: this._bottom}); | ||
+ } | ||
+ } | ||
+ | ||
componentDidMount(): void { | ||
if (Platform.OS === 'ios') { | ||
this._subscriptions = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters