import React from 'react';
import { I18nManager, StyleSheet, Text, TextProps } from 'react-native';

const styles = StyleSheet.create({
  defaultStyle: { writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr' },
});

export type WritingDirectionAwareTextProps = TextProps;

export const WritingDirectionAwareText = (props: WritingDirectionAwareTextProps) => {
  const { children, style, ...rest } = props;
  return (
    <Text {...rest} style={[style, styles.defaultStyle]}>
      {children}
    </Text>
  );
};
