2022-02-17 15:27:01 +00:00
|
|
|
import React from 'react';
|
2022-03-25 17:20:09 +00:00
|
|
|
import { Text, TextStyle } from 'react-native';
|
2022-02-17 15:27:01 +00:00
|
|
|
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-02-17 15:27:01 +00:00
|
|
|
import { useTheme } from '../../theme';
|
|
|
|
import styles from './styles';
|
2023-06-16 18:20:04 +00:00
|
|
|
import { previewFormatText } from './previewFormatText';
|
2022-02-17 15:27:01 +00:00
|
|
|
|
|
|
|
interface IMarkdownPreview {
|
|
|
|
msg?: string;
|
|
|
|
numberOfLines?: number;
|
|
|
|
testID?: string;
|
2022-03-25 17:20:09 +00:00
|
|
|
style?: TextStyle[];
|
2022-02-17 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 18:20:04 +00:00
|
|
|
const MarkdownPreview = ({ msg, numberOfLines = 1, style = [], testID }: IMarkdownPreview) => {
|
2022-04-11 18:01:43 +00:00
|
|
|
const { theme } = useTheme();
|
|
|
|
|
2022-02-17 15:27:01 +00:00
|
|
|
if (!msg) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-06-16 18:20:04 +00:00
|
|
|
const m = previewFormatText(msg);
|
2022-02-17 15:27:01 +00:00
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
accessibilityLabel={m}
|
|
|
|
style={[styles.text, { color: themes[theme].bodyText }, ...style]}
|
|
|
|
numberOfLines={numberOfLines}
|
2023-07-04 18:47:53 +00:00
|
|
|
testID={testID || `markdown-preview-${m}`}
|
|
|
|
>
|
2022-02-17 15:27:01 +00:00
|
|
|
{m}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default MarkdownPreview;
|