Skip to content
Merged
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 @@ -26,6 +26,7 @@ import {memo, useCallback, useMemo, useState} from 'react';
import {
Button,
FlatList,
I18nManager,
KeyboardAvoidingView,
Modal,
Platform,
Expand Down Expand Up @@ -241,6 +242,20 @@ export default function RNTesterPlatformTestResultView(
},
[],
);
const safeAreaPaddingStyle = useMemo(() => {
if (safeAreaInsets == null) {
return null;
}
// Insets are physical edges, but Yoga treats paddingLeft/paddingRight as
// start/end when swapLeftAndRightInRTL is on.
const swap = I18nManager.isRTL && I18nManager.doLeftAndRightSwapInRTL;
return {
paddingTop: safeAreaInsets.top,
paddingRight: swap ? safeAreaInsets.left : safeAreaInsets.right,
paddingBottom: safeAreaInsets.bottom,
paddingLeft: swap ? safeAreaInsets.right : safeAreaInsets.left,
};
}, [safeAreaInsets]);

const handleReset = useCallback(() => {
setFilterFailStatus(false);
Expand Down Expand Up @@ -285,12 +300,7 @@ export default function RNTesterPlatformTestResultView(
height: '100%',
flexDirection: 'column',
},
safeAreaInsets != null && {
paddingTop: safeAreaInsets.top,
paddingRight: safeAreaInsets.right,
paddingBottom: safeAreaInsets.bottom,
paddingLeft: safeAreaInsets.left,
},
safeAreaPaddingStyle,
]}>
<View style={styles.resultsHeader}>
<View style={styles.titleContainer}>
Expand Down
8 changes: 6 additions & 2 deletions private/helloworld/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import * as React from 'react';
import {useState} from 'react';
import {
I18nManager,
type SafeAreaInsets,
ScrollView,
StatusBar,
Expand All @@ -22,15 +23,18 @@ import {
function App(): React.ReactNode {
const isDarkMode = useColorScheme() === 'dark';
const [insets, setInsets] = useState<SafeAreaInsets | null>(null);
// Insets are physical edges, but Yoga treats paddingLeft/paddingRight as
// start/end when swapLeftAndRightInRTL is on.
const swap = I18nManager.isRTL && I18nManager.doLeftAndRightSwapInRTL;

return (
<View
style={
insets && {
paddingTop: insets.top,
paddingRight: insets.right,
paddingRight: swap ? insets.left : insets.right,
paddingBottom: insets.bottom,
paddingLeft: insets.left,
paddingLeft: swap ? insets.right : insets.left,
}
}
experimental_onSafeAreaInsetsChange={event =>
Expand Down
24 changes: 24 additions & 0 deletions private/helloworld/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,34 @@

import App from '../App';
import React from 'react';
import {I18nManager, View} from 'react-native';
import ReactTestRenderer from 'react-test-renderer';

test('renders correctly', async () => {
await ReactTestRenderer.act(() => {
ReactTestRenderer.create(<App />);
});
});

test('pads the physical edges with the safe area insets in RTL', async () => {
jest.replaceProperty(I18nManager, 'isRTL', true);

let renderer: ReactTestRenderer.ReactTestRenderer | undefined;
await ReactTestRenderer.act(() => {
renderer = ReactTestRenderer.create(<App />);
});
const getRootView = () => renderer!.root.findAllByType(View)[0];

await ReactTestRenderer.act(() => {
getRootView().props.experimental_onSafeAreaInsetsChange({
nativeEvent: {insets: {top: 44, right: 0, bottom: 34, left: 59}},
});
});

expect(getRootView().props.style).toEqual({
paddingTop: 44,
paddingRight: 59,
paddingBottom: 34,
paddingLeft: 0,
});
});
Loading