mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix asynchronous access to KeyboardAvoidingEvent event in onLayout handler (#47798)
Summary: The `onLayout` handler of the `KeyboardAvoidingView` view is async due to the `await AccessibilityInfo.prefersCrossFadeTransitions` in `_relativeKeyboardHeight`. A connected `onLayout` handler will be unable to access the event. Call `persist()` on the event so that it can be accessed asynchronously. ## Changelog: [GENERAL] [FIXED] - Accessing KeyboardAvoidingEvent event in onLayout handler Pull Request resolved: https://github.com/facebook/react-native/pull/47798 Test Plan: The following should not produce an error: ``` import * as React from 'react'; import { KeyboardAvoidingView, SafeAreaView, TextInput } from 'react-native'; export default function() { return ( <SafeAreaView> <KeyboardAvoidingView onLayout={(event) => console.log(event)} behavior="padding"> <TextInput /> </KeyboardAvoidingView> </SafeAreaView> ); } ``` Reviewed By: cipolleschi Differential Revision: D66306085 Pulled By: dmytrorykun fbshipit-source-id: 9ccf00db79947670ddc7de74a47cc6dc27455fc0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5da7ebf99a
commit
68db74205a
@@ -116,6 +116,8 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
|
||||
};
|
||||
|
||||
_onLayout = async (event: ViewLayoutEvent) => {
|
||||
event.persist();
|
||||
|
||||
const oldFrame = this._frame;
|
||||
this._frame = event.nativeEvent.layout;
|
||||
if (!this._initialFrameHeight) {
|
||||
|
||||
Reference in New Issue
Block a user