2021-08-14 01:18:22 +00:00
|
|
|
/* eslint-disable react/no-array-index-key */
|
2021-08-03 18:13:07 +00:00
|
|
|
import React from 'react';
|
2021-08-12 21:05:18 +00:00
|
|
|
import { Text } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-08-14 01:18:22 +00:00
|
|
|
|
|
|
|
import CodeLine from './CodeLine';
|
|
|
|
import styles from '../styles';
|
|
|
|
|
2021-08-03 18:13:07 +00:00
|
|
|
import { themes } from '../../../constants/colors';
|
|
|
|
import { useTheme } from '../../../theme';
|
|
|
|
|
|
|
|
const Code = ({
|
2021-08-14 01:18:22 +00:00
|
|
|
value, style
|
2021-08-03 18:13:07 +00:00
|
|
|
}) => {
|
2021-08-14 01:18:22 +00:00
|
|
|
const { theme } = useTheme();
|
|
|
|
|
2021-08-03 18:13:07 +00:00
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
{
|
2021-08-14 01:18:22 +00:00
|
|
|
...styles.codeBlock,
|
2021-08-03 18:13:07 +00:00
|
|
|
color: themes[theme].bodyText,
|
|
|
|
backgroundColor: themes[theme].bannerBackground,
|
2021-08-20 16:25:30 +00:00
|
|
|
borderColor: themes[theme].borderColor
|
2021-08-03 18:13:07 +00:00
|
|
|
},
|
|
|
|
...style
|
|
|
|
]}
|
|
|
|
>
|
2021-08-14 01:18:22 +00:00
|
|
|
{value.map((block, index) => {
|
|
|
|
switch (block.type) {
|
|
|
|
case 'CODE_LINE':
|
|
|
|
return <CodeLine key={index} value={block.value} />;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
})}
|
2021-08-03 18:13:07 +00:00
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Code.propTypes = {
|
2021-08-14 01:18:22 +00:00
|
|
|
value: PropTypes.array,
|
2021-08-03 18:13:07 +00:00
|
|
|
style: PropTypes.object
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Code;
|