Skip to content
Open
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
6 changes: 6 additions & 0 deletions docs/6.x/docs/guides/rtl.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ The `direction` prop of `PaperProvider` informs React Native Paper about the tex

On the web, `Text` aligns to the start of the writing direction, so it aligns right when `direction` is `rtl`. On Android and iOS, React Native already aligns `left` text to the right in a right-to-left layout. A `textAlign` in `style` still wins.

:::note
Paper's components use logical spacing (`marginStart`, `paddingStart`, `paddingEnd`) so they mirror in RTL. React Native Web resolves these from its own locale context, which comes from a `dir` prop or `LocaleProvider`, not from the `dir` attribute on `html`. On the Web, wrap the app (or the RTL part of it) in `LocaleProvider` for the spacing to mirror.

On Android and iOS, `paddingStart`/`marginStart` take precedence over `paddingLeft`/`marginLeft` in Yoga. To override the spacing of a Paper component, use the logical props (for example `contentStyle={{ paddingStart: 80 }}`) instead of the physical ones.
:::

## Setting direction for the whole app

Pass the `direction` prop to `PaperProvider`. Defaults to `'rtl'` when `I18nManager.getConstants().isRTL` returns `true`, otherwise `'ltr'`.
Expand Down
2 changes: 1 addition & 1 deletion src/components/Appbar/AppbarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ AppbarContent.displayName = 'Appbar.Content';
const styles = StyleSheet.create({
container: {
flex: 1,
marginLeft: 12,
marginStart: 12,
},
centerAligned: {
flex: 1,
Expand Down
4 changes: 2 additions & 2 deletions src/components/List/ListAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,11 @@ const styles = StyleSheet.create({
flexDirection: 'row',
},
contentItem: {
paddingLeft: ListTokens.leadingSpace,
paddingStart: ListTokens.leadingSpace,
},
trailingItem: {
alignSelf: 'center',
paddingLeft: ListTokens.leadingSpace,
paddingStart: ListTokens.leadingSpace,
},
transitioningClip: {
overflow: 'hidden',
Expand Down
4 changes: 2 additions & 2 deletions src/components/List/ListImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ const styles = StyleSheet.create({
video: {
width: 114,
height: 64,
marginLeft: 0,
marginStart: 0,
},
videoInLeadingSlot: {
marginLeft: -ListTokens.leadingSpace,
marginStart: -ListTokens.leadingSpace,
},
});

Expand Down
4 changes: 2 additions & 2 deletions src/components/List/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,14 @@ ListItem.displayName = 'List.Item';

const styles = StyleSheet.create({
indent: {
paddingLeft: 40,
paddingStart: 40,
},
row: {
width: '100%',
flexDirection: 'row',
},
item: {
paddingLeft: ListTokens.leadingSpace,
paddingStart: ListTokens.leadingSpace,
},
Comment on lines 376 to 378

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · ListAccordion and List accessory styles still use physical padding after ListItem went logical

In RTL, ListAccordion's header title and trailingItem keep paddingLeft (ListAccordion.tsx:508, 512) while ListItem children now use paddingStart, so the header pins to the physical left while content pads on the inline start; getAccessoryStyles (utils.ts:42) also still sets marginLeft: ListTokens.leadingSpace. Only one side of the matched pair was converted to logical properties.

⚠️ Check this patch before you commit it: the review doubted it would be right as written.

Suggested change
item: {
paddingLeft: ListTokens.leadingSpace,
paddingStart: ListTokens.leadingSpace,
},
item: {
paddingStart: ListTokens.leadingSpace,
},
Details

persona: react-native-paper

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

Comment on lines 376 to 378

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · RTL List.Item now stacks 32dp at the start and leaves the trailing icon flush

In RTL on web, a List.Item with a trailing icon now renders 32dp of padding at the start and 0 at the trailing edge, so the icon touches the row's edge. styles.item switched to paddingStart but rowStyles.container in utils.ts still uses the physical paddingRight, so in RTL both paddings land on the start side.

Suggested change
item: {
paddingLeft: ListTokens.leadingSpace,
paddingStart: ListTokens.leadingSpace,
},
item: {
paddingEnd: ListTokens.leadingSpace,
},

Suggested change

Change paddingRight: ListTokens.trailingSpace to paddingEnd: ListTokens.trailingSpace in rowStyles.container in src/components/List/utils.ts.

Details

persona: javascript

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

content: {
flexShrink: 1,
Expand Down
10 changes: 5 additions & 5 deletions src/components/List/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export type ListChildProps = {
};

export type Style = {
marginLeft?: number;
marginRight?: number;
marginStart?: number;
marginEnd?: number;
marginVertical?: number;
alignSelf?: 'flex-start' | 'center';
};
Expand All @@ -39,8 +39,8 @@ export const getAccessoryStyles = (
description: Description
): Style => {
const style: Style = {
marginLeft: ListTokens.leadingSpace,
marginRight: 0,
marginStart: ListTokens.leadingSpace,
marginEnd: 0,
alignSelf: alignToTop ? 'flex-start' : 'center',
};

Expand Down Expand Up @@ -176,7 +176,7 @@ export const getRowContentStyle = (disabled?: boolean) =>
const rowStyles = StyleSheet.create({
container: {
paddingVertical: ListTokens.verticalPadding,
paddingRight: ListTokens.trailingSpace,
paddingEnd: ListTokens.trailingSpace,
justifyContent: 'center',
},
containerOneLine: {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ const styles = StyleSheet.create({
justifyContent: 'center',
},
md3LeadingIcon: {
marginLeft: 12,
marginStart: 12,
},
md3WithoutLeadingIcon: {
marginLeft: 4,
marginStart: 4,
},
});

Expand Down
2 changes: 0 additions & 2 deletions src/components/TextInput/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ export const styles = StyleSheet.create({
paddingHorizontal: TEXT_INPUT_INPUT_WRAPPER_PADDING_HORIZONTAL,
fontSize: SUPPORTING_TEXT_FONT_SIZE,
fontWeight: bodySmall.fontWeight,
textAlign: 'left',
},
counter: {
marginTop: SUPPORTING_TEXT_MARGIN_TOP,
marginStart: 'auto',
paddingHorizontal: TEXT_INPUT_INPUT_WRAPPER_PADDING_HORIZONTAL,
fontSize: SUPPORTING_TEXT_FONT_SIZE,
fontWeight: bodySmall.fontWeight,
textAlign: 'right',
},
trailingAccessory: {
width: ACCESSORY_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
[
{
"flex": 1,
"marginLeft": 12,
"marginStart": 12,
},
undefined,
]
Expand Down
2 changes: 1 addition & 1 deletion src/components/__tests__/ListAccordion.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ it('indents expanded accordion children without their own left/right when the ac
);

expect(screen.getByTestId('accordion-child')).toHaveStyle({
paddingLeft: 40,
paddingStart: 40,
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/components/__tests__/ListItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,10 @@ it('puts a video thumbnail in the leading slot flush with the start edge', async

// The slot adds 16dp of leading space and the video takes it back
expect(screen.getByTestId('video-thumbnail').parent).toHaveStyle({
marginLeft: 16,
marginStart: 16,
});
expect(screen.getByTestId('video-thumbnail')).toHaveStyle({
marginLeft: -16,
marginStart: -16,
});
});

Expand All @@ -516,7 +516,7 @@ it('keeps a video thumbnail from the left render prop flush with the start edge'
/>
);

expect(screen.getByTestId('video-thumbnail')).toHaveStyle({ marginLeft: 0 });
expect(screen.getByTestId('video-thumbnail')).toHaveStyle({ marginStart: 0 });
});

it.each([
Expand Down
4 changes: 2 additions & 2 deletions src/components/__tests__/ListUtils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { getAccessoryStyles, getListColors } from '../List/utils';
import Text from '../Typography/Text';

const accessoryStyle = {
marginLeft: 16,
marginRight: 0,
marginStart: 16,
marginEnd: 0,
alignSelf: 'center',
};

Expand Down
42 changes: 21 additions & 21 deletions src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports[`renders expanded accordion 1`] = `
[
{
"justifyContent": "center",
"paddingRight": 16,
"paddingEnd": 16,
"paddingVertical": 8,
},
{
Expand Down Expand Up @@ -78,7 +78,7 @@ exports[`renders expanded accordion 1`] = `
style={
[
{
"paddingLeft": 16,
"paddingStart": 16,
},
{
"flex": 1,
Expand Down Expand Up @@ -125,7 +125,7 @@ exports[`renders expanded accordion 1`] = `
style={
{
"alignSelf": "center",
"paddingLeft": 16,
"paddingStart": 16,
}
}
>
Expand Down Expand Up @@ -214,7 +214,7 @@ exports[`renders expanded accordion 1`] = `
[
{
"justifyContent": "center",
"paddingRight": 16,
"paddingEnd": 16,
"paddingVertical": 8,
},
{
Expand Down Expand Up @@ -247,7 +247,7 @@ exports[`renders expanded accordion 1`] = `
style={
[
{
"paddingLeft": 16,
"paddingStart": 16,
},
{
"flexGrow": 1,
Expand Down Expand Up @@ -347,7 +347,7 @@ exports[`renders list accordion with children 1`] = `
[
{
"justifyContent": "center",
"paddingRight": 16,
"paddingEnd": 16,
"paddingVertical": 8,
},
{
Expand Down Expand Up @@ -382,8 +382,8 @@ exports[`renders list accordion with children 1`] = `
},
{
"alignSelf": "center",
"marginLeft": 16,
"marginRight": 0,
"marginEnd": 0,
"marginStart": 16,
"marginVertical": 0,
},
]
Expand Down Expand Up @@ -423,7 +423,7 @@ exports[`renders list accordion with children 1`] = `
style={
[
{
"paddingLeft": 16,
"paddingStart": 16,
},
{
"flex": 1,
Expand Down Expand Up @@ -470,7 +470,7 @@ exports[`renders list accordion with children 1`] = `
style={
{
"alignSelf": "center",
"paddingLeft": 16,
"paddingStart": 16,
}
}
>
Expand Down Expand Up @@ -574,7 +574,7 @@ exports[`renders list accordion with custom title and description styles 1`] = `
[
{
"justifyContent": "center",
"paddingRight": 16,
"paddingEnd": 16,
"paddingVertical": 8,
},
{
Expand Down Expand Up @@ -603,7 +603,7 @@ exports[`renders list accordion with custom title and description styles 1`] = `
style={
[
{
"paddingLeft": 16,
"paddingStart": 16,
},
{
"flex": 1,
Expand Down Expand Up @@ -687,7 +687,7 @@ exports[`renders list accordion with custom title and description styles 1`] = `
style={
{
"alignSelf": "center",
"paddingLeft": 16,
"paddingStart": 16,
}
}
>
Expand Down Expand Up @@ -791,7 +791,7 @@ exports[`renders list accordion with left items 1`] = `
[
{
"justifyContent": "center",
"paddingRight": 16,
"paddingEnd": 16,
"paddingVertical": 8,
},
{
Expand Down Expand Up @@ -826,8 +826,8 @@ exports[`renders list accordion with left items 1`] = `
},
{
"alignSelf": "center",
"marginLeft": 16,
"marginRight": 0,
"marginEnd": 0,
"marginStart": 16,
"marginVertical": 0,
},
]
Expand Down Expand Up @@ -867,7 +867,7 @@ exports[`renders list accordion with left items 1`] = `
style={
[
{
"paddingLeft": 16,
"paddingStart": 16,
},
{
"flex": 1,
Expand Down Expand Up @@ -914,7 +914,7 @@ exports[`renders list accordion with left items 1`] = `
style={
{
"alignSelf": "center",
"paddingLeft": 16,
"paddingStart": 16,
}
}
>
Expand Down Expand Up @@ -1018,7 +1018,7 @@ exports[`renders multiline list accordion 1`] = `
[
{
"justifyContent": "center",
"paddingRight": 16,
"paddingEnd": 16,
"paddingVertical": 8,
},
{
Expand Down Expand Up @@ -1047,7 +1047,7 @@ exports[`renders multiline list accordion 1`] = `
style={
[
{
"paddingLeft": 16,
"paddingStart": 16,
},
{
"flex": 1,
Expand Down Expand Up @@ -1127,7 +1127,7 @@ exports[`renders multiline list accordion 1`] = `
style={
{
"alignSelf": "center",
"paddingLeft": 16,
"paddingStart": 16,
}
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports[`renders ListImage with \`video\` variant 1`] = `
undefined,
{
"height": 64,
"marginLeft": 0,
"marginStart": 0,
"width": 114,
},
{
Expand Down
Loading
Loading