Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow Request money 'Description' to accept multiline #21664

Merged
merged 18 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
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
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 : {}]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

styles.noWrap is not needed here #32555 (comment)

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 @@ -78,8 +78,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 @@ -357,6 +357,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]}>
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.unSubscribeToKeyboardShortcut();
}
}

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.unSubscribeToKeyboardShortcut();
}

/**
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,
);
}

unSubscribeToKeyboardShortcut() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unSubscribeToKeyboardShortcut() {
unSubscribeFromKeyboardShortcut() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed

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 @@ -256,7 +256,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 @@ -88,7 +90,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 @@ -110,6 +112,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
Loading