Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bd1965c
fix: Added component for Text with Ellipses
mananjadhav Jan 6, 2022
c3a9b29
fix: Replaced existing reporting typing logic with new component
mananjadhav Jan 6, 2022
89b1902
fix: Added subtitle component for Header
mananjadhav Jan 8, 2022
8837961
fix: Place subtitle component with filename
mananjadhav Jan 8, 2022
ce094d1
fix: Added subtitle text styling
mananjadhav Jan 8, 2022
86902b8
fix: fixed proptypes and moved function to component
mananjadhav Jan 8, 2022
8a1820c
fix: Code cleanup
mananjadhav Jan 8, 2022
b8249f6
fix: Renamed component to TextWithEllipsis
mananjadhav Jan 8, 2022
5c828cd
fix: Removed extra styling blocks and updated comments
mananjadhav Jan 8, 2022
7552b88
fix: Updated proptype for react comp
mananjadhav Jan 8, 2022
36b033f
fix: Code cleanup and update variable naames
mananjadhav Jan 8, 2022
5bc21a9
fix: Moved to style array handling to utils
mananjadhav Jan 8, 2022
6e48f8e
fix: Trim original filename and removed trim from props
mananjadhav Jan 8, 2022
db65a55
fix: Changed width to max-width
mananjadhav Jan 8, 2022
15b47e3
fix: Added space-wrap handling
mananjadhav Jan 9, 2022
042b7eb
fix: Changed Text with TextWithOverflow component to handle inline di…
mananjadhav Jan 9, 2022
20f897c
fix: Added TextWtihOverflow component to handle ellipsis with inline …
mananjadhav Jan 9, 2022
2ca4803
fix: Revert TextWithOverflow component changes
mananjadhav Jan 18, 2022
57d8ebb
Merge branch 'main' of https://github.com/mananjadhav/App into fix/fi…
mananjadhav Jan 18, 2022
2d6065f
fix: Removed ellipses extra styles
mananjadhav Jan 18, 2022
aa9e480
fix: Remove extra bindings
mananjadhav Jan 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/components/AttachmentModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import HeaderWithCloseButton from './HeaderWithCloseButton';
import fileDownload from '../libs/fileDownload';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import ConfirmModal from './ConfirmModal';
import TextWithEllipsis from './TextWithEllipsis';

/**
* Modal render prop component that exposes modal launching triggers that can be used
Expand Down Expand Up @@ -89,6 +90,18 @@ class AttachmentModal extends PureComponent {
return modalType;
}

/**
* Returns the filename split into fileName and fileExtension
* @returns {Object}
*/
splitExtensionFromFileName() {
const fullFileName = this.props.originalFileName ? this.props.originalFileName.trim() : lodashGet(this.state, 'file.name', '').trim();
const splittedFileName = fullFileName.split('.');
const fileExtension = splittedFileName.pop();
const fileName = splittedFileName.join('.');
return {fileName, fileExtension};
}

/**
* Execute the onConfirm callback and close the modal.
*/
Expand Down Expand Up @@ -129,6 +142,8 @@ class AttachmentModal extends PureComponent {
const attachmentViewStyles = this.props.isSmallScreenWidth
? [styles.imageModalImageCenterContainer]
: [styles.imageModalImageCenterContainer, styles.p5];

const {fileName, fileExtension} = this.splitExtensionFromFileName();
return (
<>
<Modal
Expand All @@ -148,7 +163,14 @@ class AttachmentModal extends PureComponent {
shouldShowDownloadButton={!this.props.isUploadingAttachment}
onDownloadButtonPress={() => fileDownload(sourceURL)}
onCloseButtonPress={() => this.setState({isModalOpen: false})}
subtitle={this.props.originalFileName ? this.props.originalFileName : lodashGet(this.state, 'file.name', '')}
subtitle={(
<TextWithEllipsis
leadingText={fileName}
trailingText={fileExtension ? `.${fileExtension}` : ''}
wrapperStyle={[styles.w100]}
textStyle={styles.mutedTextLabel}
/>
)}
/>
<View style={attachmentViewStyles}>
{this.state.sourceURL && (
Expand Down
9 changes: 6 additions & 3 deletions src/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import styles from '../styles/styles';
import Text from './Text';
import EnvironmentBadge from './EnvironmentBadge';
Expand All @@ -10,7 +11,7 @@ const propTypes = {
title: PropTypes.string.isRequired,

/** Subtitle of the header */
subtitle: PropTypes.string,
subtitle: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),

/** Should we show the environment badge (dev/stg)? */
shouldShowEnvironmentBadge: PropTypes.bool,
Expand All @@ -22,12 +23,14 @@ const defaultProps = {
};
const Header = props => (
<View style={[styles.flex1, styles.flexRow]}>
<View>
<View style={styles.mw100}>
<Text numberOfLines={2} style={[styles.headerText, styles.textLarge]}>
{props.title}
</Text>
{/* If there's no subtitle then display a fragment to avoid an empty space which moves the main title */}
{props.subtitle ? <Text style={[styles.mutedTextLabel]}>{props.subtitle}</Text> : <></> }
{_.isString(props.subtitle)
? <Text style={[styles.mutedTextLabel]}>{props.subtitle}</Text>
: props.subtitle}
</View>
{props.shouldShowEnvironmentBadge && (
<EnvironmentBadge />
Expand Down
2 changes: 1 addition & 1 deletion src/components/HeaderWithCloseButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const propTypes = {
title: PropTypes.string,

/** Subtitle of the header */
subtitle: PropTypes.string,
subtitle: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),

/** Method to trigger when pressing download button of the header */
onDownloadButtonPress: PropTypes.func,
Expand Down
51 changes: 51 additions & 0 deletions src/components/TextWithEllipsis/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import Text from '../Text';
import styles from '../../styles/styles';
import stylePropTypes from '../../styles/stylePropTypes';
import * as StyleUtils from '../../styles/StyleUtils';

const propTypes = {
/** Leading text before the ellipsis */
leadingText: PropTypes.string.isRequired,

/** Text after the ellipsis */
trailingText: PropTypes.string.isRequired,

/** Styles for leading and trailing text */
textStyle: stylePropTypes,

/** Styles for leading text View */
leadingTextParentStyle: stylePropTypes,

/** Styles for parent View */
wrapperStyle: stylePropTypes,
};

const defaultProps = {
textStyle: {},
leadingTextParentStyle: {},
wrapperStyle: {},
};

const TextWithEllipsis = props => (
<View style={[styles.flexRow, ...StyleUtils.parseStyleAsArray(props.wrapperStyle)]}>
<View style={[styles.flexShrink1, ...StyleUtils.parseStyleAsArray(props.leadingTextParentStyle)]}>
<Text style={[...StyleUtils.parseStyleAsArray(props.textStyle)]} numberOfLines={1}>
{props.leadingText}
</Text>
</View>
<View style={styles.flexShrink0}>
<Text style={props.textStyle}>
{props.trailingText}
</Text>
</View>
</View>
);

TextWithEllipsis.propTypes = propTypes;
TextWithEllipsis.defaultProps = defaultProps;
TextWithEllipsis.displayName = 'TextWithEllipsis';

export default TextWithEllipsis;
23 changes: 8 additions & 15 deletions src/pages/home/report/ReportTypingIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import styles from '../../../styles/styles';
import * as PersonalDetails from '../../../libs/actions/PersonalDetails';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import Text from '../../../components/Text';
import TextWithEllipsis from '../../../components/TextWithEllipsis';

const propTypes = {
/** Key-value pairs of user logins and whether or not they are typing. Keys are logins. */
Expand Down Expand Up @@ -52,21 +53,13 @@ class ReportTypingIndicator extends React.Component {
return <View style={[styles.chatItemComposeSecondaryRow]} />;
case 1:
return (
<View style={[styles.chatItemComposeSecondaryRow, styles.flexRow]}>
<View style={[styles.chatItemComposeSecondaryRowOffset, styles.flexShrink1]}>
<Text
style={[styles.chatItemComposeSecondaryRowSubText]}
numberOfLines={1}
>
{PersonalDetails.getDisplayName(this.state.usersTyping[0])}
</Text>
</View>
<View style={[styles.flexShrink0]}>
<Text style={[styles.chatItemComposeSecondaryRowSubText]}>
{` ${this.props.translate('reportTypingIndicator.isTyping')}`}
</Text>
</View>
</View>
<TextWithEllipsis
leadingText={PersonalDetails.getDisplayName(this.state.usersTyping[0])}
trailingText={` ${this.props.translate('reportTypingIndicator.isTyping')}`}
textStyle={[styles.chatItemComposeSecondaryRowSubText]}
wrapperStyle={styles.chatItemComposeSecondaryRow}
leadingTextParentStyle={styles.chatItemComposeSecondaryRowOffset}
/>
);
default:
return (
Expand Down
10 changes: 10 additions & 0 deletions src/styles/StyleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,15 @@ function getMiniReportActionContextMenuWrapperStyle(isReportActionItemGrouped) {
};
}

/**
* Parse styleParam and return Styles array
* @param {Object|Object[]} styleParam
* @returns {Object[]}
*/
function parseStyleAsArray(styleParam) {
return _.isArray(styleParam) ? styleParam : [styleParam];
}

export {
getSafeAreaPadding,
getSafeAreaMargins,
Expand All @@ -397,4 +406,5 @@ export {
getLoginPagePromoStyle,
getReportActionItemStyle,
getMiniReportActionContextMenuWrapperStyle,
parseStyleAsArray,
};