// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React from 'react'; import {StyleProp, Text, TextStyle, View, ViewStyle} from 'react-native'; import Markdown from '@components/markdown'; import {makeStyleSheetFromTheme} from '@utils/theme'; import {Theme} from '@mm-redux/types/preferences'; import {MessageAttachmentField} from '@mm-redux/types/message_attachments'; import {PostMetadata} from '@mm-redux/types/posts'; type Props = { baseTextStyle: StyleProp, blockStyles?: StyleProp[], fields?: MessageAttachmentField[], metadata?: PostMetadata, onPermalinkPress?: () => void, textStyles?: StyleProp[], theme: Theme, } export default function AttachmentFields(props: Props) { const { baseTextStyle, blockStyles, fields, metadata, onPermalinkPress, textStyles, theme, } = props; if (!fields?.length) { return null; } const style = getStyleSheet(theme); const fieldTables = []; let fieldInfos = [] as React.ReactNode[]; let rowPos = 0; let lastWasLong = false; let nrTables = 0; fields.forEach((field, i) => { if (rowPos === 2 || !(field.short === true) || lastWasLong) { fieldTables.push( {fieldInfos} , ); fieldInfos = []; rowPos = 0; nrTables += 1; lastWasLong = false; } fieldInfos.push( {Boolean(field.title) && ( {field.title} )} , ); rowPos += 1; lastWasLong = !(field.short === true); }); if (fieldInfos.length > 0) { // Flush last fields fieldTables.push( {fieldInfos} , ); } return ( {fieldTables} ); } const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => { return { field: { alignSelf: 'stretch', flexDirection: 'row', }, flex: { flex: 1, }, headingContainer: { alignSelf: 'stretch', flexDirection: 'row', marginBottom: 5, marginTop: 10, }, heading: { color: theme.centerChannelColor, fontWeight: '600', }, table: { flex: 1, flexDirection: 'row', }, }; });