Skip to content

Commit 2d13fb6

Browse files
Keep safe area padding on physical edges in RTL layouts
Insets are reported for physical edges, but Yoga converts paddingLeft and paddingRight to start/end when I18nManager's swapLeftAndRightInRTL setting is on: in RTL the obstructed edge lost its inset and the opposite edge gained empty space. The removed native implementations set padding below Yoga and were unaffected, so this restores their behavior.
1 parent c25998b commit 2d13fb6

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

‎packages/react-native/src/private/components/safeareaview/SafeAreaView_INTERNAL_DO_NOT_USE.js‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
import type {HostInstance} from '../../types/HostInstance';
1717

1818
import View from '../../../../Libraries/Components/View/View';
19+
import I18nManager from '../../../../Libraries/ReactNative/I18nManager';
1920
import Dimensions from '../../../../Libraries/Utilities/Dimensions';
2021
import * as React from 'react';
2122
import {useCallback, useMemo, useState} from 'react';
@@ -49,18 +50,23 @@ component SafeAreaView(
4950
[experimental_onSafeAreaInsetsChange],
5051
);
5152

52-
const paddingStyle = useMemo(
53-
() =>
54-
insets == null
55-
? null
56-
: {
57-
paddingTop: insets.top,
58-
paddingRight: insets.right,
59-
paddingBottom: insets.bottom,
60-
paddingLeft: insets.left,
61-
},
62-
[insets],
63-
);
53+
const paddingStyle = useMemo(() => {
54+
if (insets == null) {
55+
return null;
56+
}
57+
// Insets are physical edges, but Yoga remaps paddingLeft/paddingRight to
58+
// start/end when I18nManager's swapLeftAndRightInRTL is on, which would
59+
// pad the mirror-image edge in RTL. Swap the values so the physical edge
60+
// keeps its inset.
61+
const {isRTL, doLeftAndRightSwapInRTL} = I18nManager.getConstants();
62+
const swap = isRTL && doLeftAndRightSwapInRTL;
63+
return {
64+
paddingTop: insets.top,
65+
paddingRight: swap ? insets.left : insets.right,
66+
paddingBottom: insets.bottom,
67+
paddingLeft: swap ? insets.right : insets.left,
68+
};
69+
}, [insets]);
6470

6571
return (
6672
<View

0 commit comments

Comments
 (0)