Skip to content

feat: add direction to theme configs and remove I18nManager direct use in components #4735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 5 additions & 3 deletions src/components/Appbar/AppbarBackIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as React from 'react';
import { I18nManager, Image, Platform, StyleSheet, View } from 'react-native';
import { Image, Platform, StyleSheet, View } from 'react-native';

import { useTheme } from '../../core/theming';
import MaterialCommunityIcon from '../MaterialCommunityIcon';

const AppbarBackIcon = ({ size, color }: { size: number; color: string }) => {
const theme = useTheme();
const iosIconSize = size - 3;

return Platform.OS === 'ios' ? (
Expand All @@ -13,7 +15,7 @@ const AppbarBackIcon = ({ size, color }: { size: number; color: string }) => {
{
width: size,
height: size,
transform: [{ scaleX: I18nManager.getConstants().isRTL ? -1 : 1 }],
transform: [{ scaleX: theme.direction === 'rtl' ? -1 : 1 }],
},
]}
>
Expand All @@ -31,7 +33,7 @@ const AppbarBackIcon = ({ size, color }: { size: number; color: string }) => {
name="arrow-left"
color={color}
size={size}
direction={I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'}
direction={theme.direction}
/>
);
};
Expand Down
9 changes: 4 additions & 5 deletions src/components/DataTable/DataTablePagination.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import {
ColorValue,
I18nManager,
StyleProp,
StyleSheet,
View,
Expand Down Expand Up @@ -119,7 +118,7 @@ const PaginationControls = ({
name="page-first"
color={color}
size={size}
direction={I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'}
direction={theme.direction}
/>
)}
iconColor={textColor}
Expand All @@ -136,7 +135,7 @@ const PaginationControls = ({
name="chevron-left"
color={color}
size={size}
direction={I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'}
direction={theme.direction}
/>
)}
iconColor={textColor}
Expand All @@ -152,7 +151,7 @@ const PaginationControls = ({
name="chevron-right"
color={color}
size={size}
direction={I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'}
direction={theme.direction}
/>
)}
iconColor={textColor}
Expand All @@ -169,7 +168,7 @@ const PaginationControls = ({
name="page-last"
color={color}
size={size}
direction={I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'}
direction={theme.direction}
/>
)}
iconColor={textColor}
Expand Down
5 changes: 2 additions & 3 deletions src/components/DataTable/DataTableTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react';
import {
Animated,
GestureResponderEvent,
I18nManager,
PixelRatio,
Pressable,
StyleProp,
Expand Down Expand Up @@ -120,7 +119,7 @@ const DataTableTitle = ({
name="arrow-up"
size={16}
color={textColor}
direction={I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'}
direction={theme.direction}
/>
</Animated.View>
) : null;
Expand All @@ -142,7 +141,7 @@ const DataTableTitle = ({
// if numberOfLines causes wrap, center is lost. Align directly, sensitive to numeric and RTL
numberOfLines > 1
? numeric
? I18nManager.getConstants().isRTL
? theme.direction === 'rtl'
? styles.leftText
: styles.rightText
: styles.centerText
Expand Down
5 changes: 2 additions & 3 deletions src/components/FAB/AnimatedFAB.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Animated,
Easing,
GestureResponderEvent,
I18nManager,
Platform,
ScrollView,
StyleProp,
Expand Down Expand Up @@ -146,7 +145,6 @@ const SCALE = 0.9;
* ScrollView,
* Text,
* SafeAreaView,
* I18nManager,
* } from 'react-native';
* import { AnimatedFAB } from 'react-native-paper';
*
Expand Down Expand Up @@ -238,7 +236,7 @@ const AnimatedFAB = ({
const isWeb = Platform.OS === 'web';
const isAnimatedFromRight = animateFrom === 'right';
const isIconStatic = iconMode === 'static';
const { isRTL } = I18nManager;
const isRTL = theme.direction === 'rtl';
const labelRef = React.useRef<Text & HTMLElement>(null);
const { current: visibility } = React.useRef<Animated.Value>(
new Animated.Value(visible ? 1 : 0)
Expand Down Expand Up @@ -362,6 +360,7 @@ const AnimatedFAB = ({
isIconStatic,
distance,
animFAB,
isRTL: theme.direction === 'rtl',
});

const font = isV3 ? theme.fonts.labelLarge : theme.fonts.medium;
Expand Down
12 changes: 3 additions & 9 deletions src/components/FAB/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { MutableRefObject } from 'react';
import {
Animated,
ColorValue,
I18nManager,
Platform,
ViewStyle,
} from 'react-native';
import { Animated, ColorValue, Platform, ViewStyle } from 'react-native';

import color from 'color';

Expand All @@ -18,6 +12,7 @@ type GetCombinedStylesProps = {
isIconStatic: boolean;
distance: number;
animFAB: Animated.Value;
isRTL: boolean;
};

type CombinedStyles = {
Expand All @@ -39,9 +34,8 @@ export const getCombinedStyles = ({
isIconStatic,
distance,
animFAB,
isRTL,
}: GetCombinedStylesProps): CombinedStyles => {
const { isRTL } = I18nManager;

const defaultPositionStyles = { left: -distance, right: undefined };

const combinedStyles: CombinedStyles = {
Expand Down
11 changes: 2 additions & 9 deletions src/components/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import * as React from 'react';
import {
I18nManager,
Image,
ImageSourcePropType,
Platform,
} from 'react-native';
import { Image, ImageSourcePropType, Platform } from 'react-native';

import { accessibilityProps } from './MaterialCommunityIcon';
import { Consumer as SettingsConsumer } from '../core/settings';
Expand Down Expand Up @@ -112,9 +107,7 @@ const Icon = ({
const direction =
typeof source === 'object' && source.direction && source.source
? source.direction === 'auto'
? I18nManager.getConstants().isRTL
? 'rtl'
: 'ltr'
? theme.direction
: source.direction
: null;

Expand Down
3 changes: 1 addition & 2 deletions src/components/List/ListAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react';
import {
ColorValue,
GestureResponderEvent,
I18nManager,
NativeSyntheticEvent,
StyleProp,
StyleSheet,
Expand Down Expand Up @@ -331,7 +330,7 @@ const ListAccordion = ({
name={isExpanded ? 'chevron-up' : 'chevron-down'}
color={theme.isV3 ? descriptionColor : titleColor}
size={24}
direction={I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'}
direction={theme.direction}
/>
)}
</View>
Expand Down
3 changes: 1 addition & 2 deletions src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Dimensions,
Easing,
EmitterSubscription,
I18nManager,
Keyboard,
KeyboardEvent as RNKeyboardEvent,
LayoutRectangle,
Expand Down Expand Up @@ -620,7 +619,7 @@ const Menu = ({
top: isCoordinate(anchor)
? topTransformation
: topTransformation + additionalVerticalValue,
...(I18nManager.getConstants().isRTL
...(theme.direction === 'rtl'
? { right: leftTransformation }
: { left: leftTransformation }),
};
Expand Down
3 changes: 1 addition & 2 deletions src/components/ProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import {
Animated,
I18nManager,
LayoutChangeEvent,
Platform,
StyleProp,
Expand Down Expand Up @@ -55,7 +54,6 @@ export type Props = React.ComponentPropsWithRef<typeof View> & {

const INDETERMINATE_DURATION = 2000;
const INDETERMINATE_MAX_WIDTH = 0.6;
const { isRTL } = I18nManager;

/**
* Progress bar is an indicator used to present progress of some activity in the app.
Expand Down Expand Up @@ -99,6 +97,7 @@ const ProgressBar = ({
React.useRef<Animated.CompositeAnimation | null>(null);

const { scale } = theme.animation;
const isRTL = theme.direction === 'rtl';

React.useEffect(() => {
passedAnimatedValue.current = animatedValue;
Expand Down
7 changes: 3 additions & 4 deletions src/components/Searchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Animated,
ColorValue,
GestureResponderEvent,
I18nManager,
Platform,
StyleProp,
StyleSheet,
Expand Down Expand Up @@ -290,7 +289,7 @@ const Searchbar = forwardRef<TextInputHandles, Props>(
name="magnify"
color={color}
size={size}
direction={I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'}
direction={theme.direction}
/>
))
}
Expand All @@ -302,6 +301,7 @@ const Searchbar = forwardRef<TextInputHandles, Props>(
style={[
styles.input,
{
textAlign: theme.direction === 'rtl' ? 'right' : 'left',
color: textColor,
...font,
...Platform.select({ web: { outline: 'none' } }),
Expand Down Expand Up @@ -352,7 +352,7 @@ const Searchbar = forwardRef<TextInputHandles, Props>(
name={isV3 ? 'close' : 'close-circle-outline'}
color={color}
size={size}
direction={I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'}
direction={theme.direction}
/>
))
}
Expand Down Expand Up @@ -403,7 +403,6 @@ const styles = StyleSheet.create({
fontSize: 18,
paddingLeft: 8,
alignSelf: 'stretch',
textAlign: I18nManager.getConstants().isRTL ? 'right' : 'left',
minWidth: 0,
},
barModeInput: {
Expand Down
5 changes: 1 addition & 4 deletions src/components/Snackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Animated,
ColorValue,
Easing,
I18nManager,
StyleProp,
StyleSheet,
View,
Expand Down Expand Up @@ -360,9 +359,7 @@ const Snackbar = ({
name="close"
color={color}
size={size}
direction={
I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'
}
direction={theme.direction}
/>
);
})
Expand Down
13 changes: 5 additions & 8 deletions src/components/TextInput/TextInputFlat.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import {
I18nManager,
Platform,
StyleSheet,
TextInput as NativeTextInput,
Expand Down Expand Up @@ -170,11 +169,9 @@ const TextInputFlat = ({
const labelHalfHeight = labelHeight / 2;

const baseLabelTranslateX =
(I18nManager.getConstants().isRTL ? 1 : -1) *
(theme.direction === 'rtl' ? 1 : -1) *
(labelHalfWidth - (labelScale * labelWidth) / 2) +
(1 - labelScale) *
(I18nManager.getConstants().isRTL ? -1 : 1) *
paddingLeft;
(1 - labelScale) * (theme.direction === 'rtl' ? -1 : 1) * paddingLeft;

const minInputHeight = dense
? (label ? MIN_DENSE_HEIGHT_WL : MIN_DENSE_HEIGHT) - LABEL_PADDING_TOP_DENSE
Expand Down Expand Up @@ -279,12 +276,12 @@ const TextInputFlat = ({
wiggleOffsetX: LABEL_WIGGLE_X_OFFSET,
topPosition,
paddingLeft: isAndroid
? I18nManager.isRTL
? theme.direction === 'rtl'
? paddingRight
: paddingLeft
: paddingLeft,
paddingRight: isAndroid
? I18nManager.isRTL
? theme.direction === 'rtl'
? paddingLeft
: paddingRight
: paddingRight,
Expand Down Expand Up @@ -420,7 +417,7 @@ const TextInputFlat = ({
textAlignVertical: multiline ? 'top' : 'center',
textAlign: textAlign
? textAlign
: I18nManager.getConstants().isRTL
: theme.direction === 'rtl'
? 'right'
: 'left',
minWidth: Math.min(
Expand Down
7 changes: 3 additions & 4 deletions src/components/TextInput/TextInputOutlined.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
View,
TextInput as NativeTextInput,
StyleSheet,
I18nManager,
Platform,
TextStyle,
ColorValue,
Expand Down Expand Up @@ -131,7 +130,7 @@ const TextInputOutlined = ({
const labelHalfHeight = labelHeight / 2;

const baseLabelTranslateX =
(I18nManager.getConstants().isRTL ? 1 : -1) *
(theme.direction === 'rtl' ? 1 : -1) *
(labelHalfWidth -
(labelScale * labelWidth) / 2 -
(fontSize - MINIMIZED_LABEL_FONT_SIZE) * labelScale);
Expand All @@ -148,7 +147,7 @@ const TextInputOutlined = ({

if (isAdornmentLeftIcon) {
labelTranslationXOffset =
(I18nManager.getConstants().isRTL ? -1 : 1) *
(theme.direction === 'rtl' ? -1 : 1) *
(ADORNMENT_SIZE + ADORNMENT_OFFSET - (isV3 ? 0 : 8));
}

Expand Down Expand Up @@ -406,7 +405,7 @@ const TextInputOutlined = ({
textAlignVertical: multiline ? 'top' : 'center',
textAlign: textAlign
? textAlign
: I18nManager.getConstants().isRTL
: theme.direction === 'rtl'
? 'right'
: 'left',
paddingHorizontal: INPUT_PADDING_HORIZONTAL,
Expand Down
Loading