diff --git a/Libraries/Components/SafeAreaView/SafeAreaView.js b/Libraries/Components/SafeAreaView/SafeAreaView.js index 916852aa42607d..ee6b57ad3db7c3 100644 --- a/Libraries/Components/SafeAreaView/SafeAreaView.js +++ b/Libraries/Components/SafeAreaView/SafeAreaView.js @@ -13,10 +13,12 @@ const React = require('React'); const View = require('View'); import type {ViewProps} from 'ViewPropTypes'; +import type {InsetsChangeEvent} from 'CoreEventTypes'; type Props = $ReadOnly<{| ...ViewProps, emulateUnlessSupported?: boolean, + onInsetsChange?: ?(event: InsetsChangeEvent) => Promise | void, |}>; let exported; @@ -33,7 +35,7 @@ let exported; if (Platform.OS === 'android') { exported = class SafeAreaView extends React.Component { render(): React.Node { - const {emulateUnlessSupported, ...props} = this.props; + const {emulateUnlessSupported, onInsetsChange, ...props} = this.props; return ; } }; diff --git a/Libraries/Types/CoreEventTypes.js b/Libraries/Types/CoreEventTypes.js index abe3ca172f0181..80d8017b28c100 100644 --- a/Libraries/Types/CoreEventTypes.js +++ b/Libraries/Types/CoreEventTypes.js @@ -28,7 +28,7 @@ export type SyntheticEvent = $ReadOnly<{| persist: () => void, target: ?number, timeStamp: number, - type: ?string, + type?: ?string, |}>; export type ResponderSyntheticEvent = $ReadOnly<{| @@ -135,3 +135,16 @@ export type SwitchChangeEvent = SyntheticEvent< value: boolean, |}>, >; + +export type Insets = $ReadOnly<{| + left: number, + top: number, + right: number, + bottom: number, +|}>; + +export type InsetsChangeEvent = SyntheticEvent< + $ReadOnly<{| + insets: Insets, + |}>, +>; diff --git a/RNTester/js/SafeAreaViewExample.js b/RNTester/js/SafeAreaViewExample.js index 0dbc79e0947601..e3983296d56b56 100644 --- a/RNTester/js/SafeAreaViewExample.js +++ b/RNTester/js/SafeAreaViewExample.js @@ -19,22 +19,30 @@ const Switch = require('Switch'); const Text = require('Text'); const View = require('View'); +import type {Insets} from 'CoreEventTypes'; + class SafeAreaViewExample extends React.Component< {}, {| modalVisible: boolean, emulateUnlessSupported: boolean, + insets: ?Insets, |}, > { state = { modalVisible: false, emulateUnlessSupported: true, + insets: undefined, }; _setModalVisible = visible => { this.setState({modalVisible: visible}); }; + _onSafeAreaViewInsetsChange = event => { + this.setState({insets: event.nativeEvent.insets}); + }; + render() { return ( @@ -46,8 +54,13 @@ class SafeAreaViewExample extends React.Component< + emulateUnlessSupported={this.state.emulateUnlessSupported} + onInsetsChange={this._onSafeAreaViewInsetsChange}> + + {this.state.insets && + `safeAreaViewInsets:\n${JSON.stringify(this.state.insets)}`} +