Files
react-native/Libraries/Components/SafeAreaView/SafeAreaView.js
T
zhongwuzw cc2b3d0ebf Add setNativeProps support for SafeAreaView (#24589)
Summary:
Fixes #24576 .
cc. cpojer .

[iOS] [Fixed] - Add setNativeProps support for SafeAreaView
Pull Request resolved: https://github.com/facebook/react-native/pull/24589

Differential Revision: D15099303

Pulled By: cpojer

fbshipit-source-id: f694f19fd932236c001056f38cc976db38db68a6
2019-04-26 08:47:09 -07:00

68 lines
1.9 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
const Platform = require('Platform');
const React = require('React');
const View = require('View');
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'ReactNative';
type Props = $ReadOnly<{|
...ViewProps,
emulateUnlessSupported?: boolean,
|}>;
let exported;
/**
* Renders nested content and automatically applies paddings reflect the portion
* of the view that is not covered by navigation bars, tab bars, toolbars, and
* other ancestor views.
*
* Moreover, and most importantly, Safe Area's paddings reflect physical
* limitation of the screen, such as rounded corners or camera notches (aka
* sensor housing area on iPhone X).
*/
if (Platform.OS === 'android') {
const SafeAreaView = (
props: Props,
forwardedRef?: ?React.Ref<typeof View>,
) => {
const {emulateUnlessSupported, ...localProps} = props;
return <View {...localProps} ref={forwardedRef} />;
};
const SafeAreaViewRef = React.forwardRef(SafeAreaView);
SafeAreaViewRef.displayName = 'SafeAreaView';
exported = ((SafeAreaViewRef: any): Class<React.Component<Props>>);
} else {
const RCTSafeAreaViewNativeComponent = require('RCTSafeAreaViewNativeComponent');
const SafeAreaView = (
props: Props,
forwardedRef?: ?React.Ref<typeof RCTSafeAreaViewNativeComponent>,
) => {
return (
<RCTSafeAreaViewNativeComponent
emulateUnlessSupported={true}
{...props}
ref={forwardedRef}
/>
);
};
const SafeAreaViewRef = React.forwardRef(SafeAreaView);
SafeAreaViewRef.displayName = 'SafeAreaView';
exported = ((SafeAreaViewRef: any): Class<NativeComponent<Props>>);
}
module.exports = exported;