2022-07-20 21:02:18 +00:00
|
|
|
import { KaTeX as KaTeXProps } from '@rocket.chat/message-parser';
|
2024-02-19 15:06:09 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { StyleProp, ViewStyle } from 'react-native';
|
|
|
|
import Katex from 'react-native-katex';
|
2022-07-20 21:02:18 +00:00
|
|
|
// eslint-disable-next-line import/no-unresolved
|
|
|
|
import MathView, { MathText } from 'react-native-math-view';
|
|
|
|
|
2024-02-19 15:06:09 +00:00
|
|
|
import { isAndroid } from '../../../lib/methods/helpers';
|
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();
|
2024-02-19 15:06:09 +00:00
|
|
|
const fixAndroidWebviewCrashStyle: StyleProp<ViewStyle> = isAndroid ? { opacity: 0.99, overflow: 'hidden' } : {};
|
2023-08-16 12:02:53 +00:00
|
|
|
return (
|
|
|
|
<MathView
|
|
|
|
math={value}
|
|
|
|
style={{ color: colors.bodyText }}
|
2024-02-19 15:06:09 +00:00
|
|
|
renderError={() => (
|
|
|
|
<Katex expression={value} style={[{ flex: 1, height: DEFAULT_MESSAGE_HEIGHT }, fixAndroidWebviewCrashStyle]} />
|
|
|
|
)}
|
2023-08-16 12:02:53 +00:00
|
|
|
/>
|
|
|
|
);
|
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 }} />;
|
|
|
|
};
|