Skip to content

Commit

Permalink
Merge pull request #21664 from ahmedGaber93/issue-19872
Browse files Browse the repository at this point in the history
allow Request money 'Description' to accept multiline
  • Loading branch information
stitesExpensify authored Aug 28, 2023
2 parents 5813ac9 + a9faa80 commit d42967a
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/components/DisplayNames/DisplayNamesWithTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function DisplayNamesWithToolTip(props) {
return (
// Tokenization of string only support prop numberOfLines on Web
<Text
style={[...props.textStyles, styles.pRelative]}
style={[...props.textStyles, styles.pRelative, props.numberOfLines === 1 ? styles.noWrap : {}]}
numberOfLines={props.numberOfLines || undefined}
ref={(el) => (containerRef.current = el)}
>
Expand Down
4 changes: 2 additions & 2 deletions src/components/LHNOptionsList/OptionRowLHN.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ function OptionRowLHN(props) {
const displayNameStyle = StyleUtils.combineStyles([styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, ...textUnreadStyle], props.style);
const alternateTextStyle = StyleUtils.combineStyles(
props.viewMode === CONST.OPTION_MODE.COMPACT
? [textStyle, styles.optionAlternateText, styles.pre, styles.textLabelSupporting, styles.optionAlternateTextCompact, styles.ml2]
: [textStyle, styles.optionAlternateText, styles.pre, styles.textLabelSupporting],
? [textStyle, styles.optionAlternateText, styles.noWrap, styles.textLabelSupporting, styles.optionAlternateTextCompact, styles.ml2]
: [textStyle, styles.optionAlternateText, styles.noWrap, styles.textLabelSupporting],
props.style,
);
const contentContainerStyles =
Expand Down
1 change: 1 addition & 0 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ function MoneyRequestConfirmationList(props) {
style={[styles.moneyRequestMenuItem, styles.mb2]}
titleStyle={styles.flex1}
disabled={didConfirm || props.isReadOnly}
numberOfLinesTitle={2}
/>
{!showAllFields && (
<View style={[styles.flexRow, styles.justifyContentBetween, styles.mh3, styles.alignItemsCenter, styles.mb2]}>
Expand Down
90 changes: 53 additions & 37 deletions src/components/OptionsSelector/BaseOptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,41 +64,20 @@ class BaseOptionsSelector extends Component {
}

componentDidMount() {
const enterConfig = CONST.KEYBOARD_SHORTCUTS.ENTER;
this.unsubscribeEnter = KeyboardShortcut.subscribe(
enterConfig.shortcutKey,
this.selectFocusedOption,
enterConfig.descriptionKey,
enterConfig.modifiers,
true,
() => !this.state.allOptions[this.state.focusedIndex],
);

const CTRLEnterConfig = CONST.KEYBOARD_SHORTCUTS.CTRL_ENTER;
this.unsubscribeCTRLEnter = KeyboardShortcut.subscribe(
CTRLEnterConfig.shortcutKey,
() => {
if (this.props.canSelectMultipleOptions) {
this.props.onConfirmSelection();
return;
}

const focusedOption = this.state.allOptions[this.state.focusedIndex];
if (!focusedOption) {
return;
}

this.selectRow(focusedOption);
},
CTRLEnterConfig.descriptionKey,
CTRLEnterConfig.modifiers,
true,
);
this.subscribeToKeyboardShortcut();

this.scrollToIndex(this.props.selectedOptions.length ? 0 : this.state.focusedIndex, false);
}

componentDidUpdate(prevProps) {
if (prevProps.isFocused !== this.props.isFocused) {
if (this.props.isFocused) {
this.subscribeToKeyboardShortcut();
} else {
this.unSubscribeFromKeyboardShortcut();
}
}

if (this.textInput && this.props.autoFocus && !prevProps.isFocused && this.props.isFocused) {
InteractionManager.runAfterInteractions(() => {
// If we automatically focus on a text input when mounting a component,
Expand Down Expand Up @@ -148,13 +127,7 @@ class BaseOptionsSelector extends Component {
clearTimeout(this.focusTimeout);
}

if (this.unsubscribeEnter) {
this.unsubscribeEnter();
}

if (this.unsubscribeCTRLEnter) {
this.unsubscribeCTRLEnter();
}
this.unSubscribeFromKeyboardShortcut();
}

/**
Expand All @@ -179,6 +152,49 @@ class BaseOptionsSelector extends Component {
return defaultIndex;
}

subscribeToKeyboardShortcut() {
const enterConfig = CONST.KEYBOARD_SHORTCUTS.ENTER;
this.unsubscribeEnter = KeyboardShortcut.subscribe(
enterConfig.shortcutKey,
this.selectFocusedOption,
enterConfig.descriptionKey,
enterConfig.modifiers,
true,
() => !this.state.allOptions[this.state.focusedIndex],
);

const CTRLEnterConfig = CONST.KEYBOARD_SHORTCUTS.CTRL_ENTER;
this.unsubscribeCTRLEnter = KeyboardShortcut.subscribe(
CTRLEnterConfig.shortcutKey,
() => {
if (this.props.canSelectMultipleOptions) {
this.props.onConfirmSelection();
return;
}

const focusedOption = this.state.allOptions[this.state.focusedIndex];
if (!focusedOption) {
return;
}

this.selectRow(focusedOption);
},
CTRLEnterConfig.descriptionKey,
CTRLEnterConfig.modifiers,
true,
);
}

unSubscribeFromKeyboardShortcut() {
if (this.unsubscribeEnter) {
this.unsubscribeEnter();
}

if (this.unsubscribeCTRLEnter) {
this.unsubscribeCTRLEnter();
}
}

selectFocusedOption() {
const focusedOption = this.state.allOptions[this.state.focusedIndex];

Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ function MoneyRequestPreview(props) {
</View>
{!props.isBillSplit && !_.isEmpty(requestMerchant) && (
<View style={[styles.flexRow]}>
<Text style={[styles.textLabelSupporting, styles.mb1, styles.lh16]}>{requestMerchant}</Text>
<Text style={[styles.textLabelSupporting, styles.mb1, styles.lh16, styles.breakWord]}>{requestMerchant}</Text>
</View>
)}
<View style={[styles.flexRow]}>
Expand Down
8 changes: 7 additions & 1 deletion src/pages/iou/MoneyRequestDescriptionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import * as IOU from '../../libs/actions/IOU';
import optionPropTypes from '../../components/optionPropTypes';
import CONST from '../../CONST';
import useLocalize from '../../hooks/useLocalize';
import focusAndUpdateMultilineInputRange from '../../libs/focusAndUpdateMultilineInputRange';
import * as Browser from '../../libs/Browser';

const propTypes = {
/** Onyx Props */
Expand Down Expand Up @@ -101,7 +103,7 @@ function MoneyRequestDescriptionPage({iou, route}) {
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldEnableMaxHeight
onEntryTransitionEnd={() => inputRef.current && inputRef.current.focus()}
onEntryTransitionEnd={() => focusAndUpdateMultilineInputRange(inputRef.current)}
>
<HeaderWithBackButton
title={translate('common.description')}
Expand All @@ -123,6 +125,10 @@ function MoneyRequestDescriptionPage({iou, route}) {
accessibilityLabel={translate('moneyRequestConfirmationList.whatsItFor')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
ref={(el) => (inputRef.current = el)}
autoGrowHeight
containerStyles={[styles.autoGrowHeightMultilineInput]}
textAlignVertical="top"
submitOnEnter={!Browser.isMobile()}
/>
</View>
</Form>
Expand Down

0 comments on commit d42967a

Please sign in to comment.