2022-07-20 21:02:18 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { KaTeX as KaTeXProps } from '@rocket.chat/message-parser';
|
|
|
|
// eslint-disable-next-line import/no-unresolved
|
|
|
|
import MathView, { MathText } from 'react-native-math-view';
|
2023-08-16 12:02:53 +00:00
|
|
|
import Katex from 'react-native-katex';
|
2022-07-20 21:02:18 +00:00
|
|
|
|
|
|
|
import { useTheme } from '../../../theme';
|
2023-08-16 12:02:53 +00:00
|
|
|
import { DEFAULT_MESSAGE_HEIGHT } from '../../message/utils';
|
2022-07-20 21:02:18 +00:00
|
|
|
|
|
|
|
interface IKaTeXProps {
|
|
|
|
value: KaTeXProps['value'];
|
|
|
|
}
|
|
|
|
|
|
|
|
export const KaTeX = ({ value }: IKaTeXProps): React.ReactElement | null => {
|
|
|
|
const { colors } = useTheme();
|
2023-08-16 12:02:53 +00:00
|
|
|
return (
|
|
|
|
<MathView
|
|
|
|
math={value}
|
|
|
|
style={{ color: colors.bodyText }}
|
|
|
|
renderError={() => <Katex expression={value} style={{ flex: 1, height: DEFAULT_MESSAGE_HEIGHT }} />}
|
|
|
|
/>
|
|
|
|
);
|
2022-07-20 21:02:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const InlineKaTeX = ({ value }: IKaTeXProps): React.ReactElement | null => {
|
|
|
|
const { colors } = useTheme();
|
|
|
|
return <MathText color value={`$$${value}$$`} direction='ltr' style={{ color: colors.bodyText }} />;
|
|
|
|
};
|