Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @format
*/

import SafeAreaView from '../../Components/SafeAreaView/SafeAreaView';
import SafeAreaView from '../../../src/private/components/safeareaview/SafeAreaView_INTERNAL_DO_NOT_USE';
import StyleSheet, {
type ColorValue,
type ViewStyleProp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @format
*/

import SafeAreaView from '../../Components/SafeAreaView/SafeAreaView';
import SafeAreaView from '../../../src/private/components/safeareaview/SafeAreaView_INTERNAL_DO_NOT_USE';
import View from '../../Components/View/View';
import StyleSheet from '../../StyleSheet/StyleSheet';
import Text from '../../Text/Text';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import type {ViewProps} from '../../Components/View/ViewPropTypes';
import type {LogLevel} from '../Data/LogBoxLog';

import SafeAreaView from '../../Components/SafeAreaView/SafeAreaView';
import SafeAreaView from '../../../src/private/components/safeareaview/SafeAreaView_INTERNAL_DO_NOT_USE';
import View from '../../Components/View/View';
import StyleSheet from '../../StyleSheet/StyleSheet';
import Text from '../../Text/Text';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`LogBoxNotificationContainer should render both an error and warning notification 1`] = `
<SafeAreaView
<View
experimental_onSafeAreaInsetsChange={[Function]}
style={
Object {
"alignItems": "center",
"bottom": 20,
"left": 10,
"pointerEvents": "box-none",
"position": "absolute",
"right": 10,
}
Array [
Object {
"alignItems": "center",
"bottom": 20,
"left": 10,
"pointerEvents": "box-none",
"position": "absolute",
"right": 10,
},
null,
]
}
>
<View
Expand Down Expand Up @@ -107,7 +111,7 @@ exports[`LogBoxNotificationContainer should render both an error and warning not
totalLogCount={1}
/>
</View>
</SafeAreaView>
</View>
`;

exports[`LogBoxNotificationContainer should render null with no logs 1`] = `null`;
Expand All @@ -119,16 +123,20 @@ exports[`LogBoxNotificationContainer should render selected fatal error even whe
exports[`LogBoxNotificationContainer should render selected syntax error even when disabled 1`] = `null`;

exports[`LogBoxNotificationContainer should render the latest error notification 1`] = `
<SafeAreaView
<View
experimental_onSafeAreaInsetsChange={[Function]}
style={
Object {
"alignItems": "center",
"bottom": 20,
"left": 10,
"pointerEvents": "box-none",
"position": "absolute",
"right": 10,
}
Array [
Object {
"alignItems": "center",
"bottom": 20,
"left": 10,
"pointerEvents": "box-none",
"position": "absolute",
"right": 10,
},
null,
]
}
>
<View
Expand Down Expand Up @@ -178,20 +186,24 @@ exports[`LogBoxNotificationContainer should render the latest error notification
totalLogCount={2}
/>
</View>
</SafeAreaView>
</View>
`;

exports[`LogBoxNotificationContainer should render the latest warning notification 1`] = `
<SafeAreaView
<View
experimental_onSafeAreaInsetsChange={[Function]}
style={
Object {
"alignItems": "center",
"bottom": 20,
"left": 10,
"pointerEvents": "box-none",
"position": "absolute",
"right": 10,
}
Array [
Object {
"alignItems": "center",
"bottom": 20,
"left": 10,
"pointerEvents": "box-none",
"position": "absolute",
"right": 10,
},
null,
]
}
>
<View
Expand Down Expand Up @@ -241,5 +253,5 @@ exports[`LogBoxNotificationContainer should render the latest warning notificati
totalLogCount={2}
/>
</View>
</SafeAreaView>
</View>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,66 @@
*/

import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
import type {
SafeAreaInsets,
SafeAreaInsetsChangeEvent,
} from '../../../../Libraries/Types/CoreEventTypes';
import type {HostInstance} from '../../types/HostInstance';

import View from '../../../../Libraries/Components/View/View';
import UIManager from '../../../../Libraries/ReactNative/UIManager';
import Platform from '../../../../Libraries/Utilities/Platform';
import I18nManager from '../../../../Libraries/ReactNative/I18nManager';
import * as React from 'react';
import {useCallback, useMemo, useState} from 'react';

const exported: component(
ref?: React.RefSetter<React.ElementRef<typeof View>>,
...ViewProps
) = Platform.select({
ios: require('../../../../src/private/components/safeareaview/specs/RCTSafeAreaViewNativeComponent')
.default,
android: UIManager.hasViewManagerConfig('RCTSafeAreaView')
? require('../../../../src/private/components/safeareaview/specs/RCTSafeAreaViewNativeComponent')
.default
: View,
default: View,
});
/**
* Renders its children within the safe area of the device, by applying the part
* of the view that is covered by the system UI as padding.
*
* This is the internal counterpart of `react-native-safe-area-context`, for the
* few surfaces React Native renders itself (LogBox, the element inspector, ...)
* which cannot take a dependency on it. Everything else should use the library.
*/
component SafeAreaView(
ref?: React.RefSetter<HostInstance>,
...props: ViewProps
) {
const {style, experimental_onSafeAreaInsetsChange, ...otherProps} = props;
const [insets, setInsets] = useState<?SafeAreaInsets>(null);

const handleSafeAreaInsetsChange = useCallback(
(event: SafeAreaInsetsChangeEvent) => {
setInsets(event.nativeEvent.insets);
experimental_onSafeAreaInsetsChange?.(event);
},
[experimental_onSafeAreaInsetsChange],
);

const paddingStyle = useMemo(() => {
if (insets == null) {
return null;
}
// Insets are physical edges, but Yoga remaps paddingLeft/paddingRight to
// start/end when I18nManager's swapLeftAndRightInRTL is on, which would
// pad the mirror-image edge in RTL. Swap the values so the physical edge
// keeps its inset.
const {isRTL, doLeftAndRightSwapInRTL} = I18nManager.getConstants();
const swap = isRTL && doLeftAndRightSwapInRTL;
return {
paddingTop: insets.top,
paddingRight: swap ? insets.left : insets.right,
paddingBottom: insets.bottom,
paddingLeft: swap ? insets.right : insets.left,
};
}, [insets]);

return (
<View
{...otherProps}
ref={ref}
experimental_onSafeAreaInsetsChange={handleSafeAreaInsetsChange}
style={[style, paddingStyle]}
/>
);
}

export default exported;
export default SafeAreaView;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import type {ElementsHierarchy, InspectedElement} from './Inspector';

import SafeAreaView from '../../../../../Libraries/Components/SafeAreaView/SafeAreaView';
import SafeAreaView from '../../../components/safeareaview/SafeAreaView_INTERNAL_DO_NOT_USE';
import * as React from 'react';

const ScrollView =
Expand Down
Loading