-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
composer set correct numberOfLines on intitial render #15296
Changes from 8 commits
c83ba5b
d5b7971
95dfa4d
41b781c
e5d805c
7723e56
8a3371a
56eec55
610bc2c
6caefe4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,12 @@ const propTypes = { | |
/** The value of the comment box */ | ||
value: PropTypes.string, | ||
|
||
/** Number of lines for the comment */ | ||
numberOfLines: PropTypes.number, | ||
|
||
/** Callback method to update number of lines for the comment */ | ||
onNumberOfLinesChange: PropTypes.func, | ||
|
||
/** Callback method to handle pasting a file */ | ||
onPasteFile: PropTypes.func, | ||
|
||
|
@@ -75,6 +81,8 @@ const propTypes = { | |
const defaultProps = { | ||
defaultValue: undefined, | ||
value: undefined, | ||
numberOfLines: 1, | ||
onNumberOfLinesChange: () => {}, | ||
maxLines: -1, | ||
onPasteFile: () => {}, | ||
shouldClear: false, | ||
|
@@ -116,7 +124,7 @@ class Composer extends React.Component { | |
: `${props.value || ''}`; | ||
|
||
this.state = { | ||
numberOfLines: 1, | ||
numberOfLines: props.numberOfLines || 1, | ||
selection: { | ||
start: initialValue.length, | ||
end: initialValue.length, | ||
|
@@ -162,7 +170,8 @@ class Composer extends React.Component { | |
if (prevProps.value !== this.props.value | ||
|| prevProps.defaultValue !== this.props.defaultValue | ||
|| prevProps.isComposerFullSize !== this.props.isComposerFullSize | ||
|| prevProps.windowWidth !== this.props.windowWidth) { | ||
|| prevProps.windowWidth !== this.props.windowWidth | ||
|| prevProps.numberOfLines !== this.props.numberOfLines) { | ||
this.updateNumberOfLines(); | ||
} | ||
|
||
|
@@ -334,11 +343,13 @@ class Composer extends React.Component { | |
const lineHeight = parseInt(computedStyle.lineHeight, 10) || 20; | ||
const paddingTopAndBottom = parseInt(computedStyle.paddingBottom, 10) | ||
+ parseInt(computedStyle.paddingTop, 10); | ||
const numberOfLines = getNumberOfLines(this.props.maxLines, lineHeight, paddingTopAndBottom, this.textInput.scrollHeight); | ||
const computedNumberOfLines = getNumberOfLines(this.props.maxLines, lineHeight, paddingTopAndBottom, this.textInput.scrollHeight); | ||
const numberOfLines = computedNumberOfLines === 0 ? Math.max(this.props.numberOfLines, 1) : computedNumberOfLines; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need |
||
updateIsFullComposerAvailable(this.props, numberOfLines); | ||
this.setState({ | ||
numberOfLines, | ||
}); | ||
this.props.onNumberOfLinesChange(numberOfLines); | ||
}); | ||
} | ||
|
||
|
@@ -357,7 +368,6 @@ class Composer extends React.Component { | |
selection={this.state.selection} | ||
onChange={this.shouldCallUpdateNumberOfLines} | ||
onSelectionChange={this.onSelectionChange} | ||
numberOfLines={this.state.numberOfLines} | ||
style={[ | ||
propStyles, | ||
|
||
|
@@ -367,6 +377,7 @@ class Composer extends React.Component { | |
]} | ||
/* eslint-disable-next-line react/jsx-props-no-spreading */ | ||
{...propsWithoutStyles} | ||
numberOfLines={this.state.numberOfLines} | ||
disabled={this.props.isDisabled} | ||
/> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,9 @@ const propTypes = { | |
/** The comment left by the user */ | ||
comment: PropTypes.string, | ||
|
||
/** Number of lines for the comment */ | ||
numberOfLines: PropTypes.number, | ||
|
||
/** The ID of the report actions will be created for */ | ||
reportID: PropTypes.string.isRequired, | ||
|
||
|
@@ -107,6 +110,7 @@ const propTypes = { | |
const defaultProps = { | ||
betas: [], | ||
comment: '', | ||
numberOfLines: 1, | ||
modal: {}, | ||
report: {}, | ||
reportActions: [], | ||
|
@@ -550,6 +554,14 @@ class ReportActionCompose extends React.Component { | |
} | ||
} | ||
|
||
/** | ||
* Update the number of lines for a comment in Onyx | ||
* @param {Number} numberOfLines | ||
*/ | ||
updateNumberOfLines(numberOfLines) { | ||
Report.saveReportCommentNumberOfLines(this.props.reportID, numberOfLines); | ||
} | ||
|
||
/** | ||
* Listens for keyboard shortcuts and applies the action | ||
* | ||
|
@@ -823,6 +835,8 @@ class ReportActionCompose extends React.Component { | |
setIsFullComposerAvailable={this.setIsFullComposerAvailable} | ||
isComposerFullSize={this.props.isComposerFullSize} | ||
value={this.state.value} | ||
numberOfLines={this.props.numberOfLines} | ||
onNumberOfLinesChange={numberOfLines => this.updateNumberOfLines(numberOfLines)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's bind |
||
onLayout={(e) => { | ||
const composerHeight = e.nativeEvent.layout.height; | ||
if (this.state.composerHeight === composerHeight) { | ||
|
@@ -925,6 +939,9 @@ export default compose( | |
comment: { | ||
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, | ||
}, | ||
numberOfLines: { | ||
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT_NUMBER_OF_LINES}${reportID}`, | ||
}, | ||
modal: { | ||
key: ONYXKEYS.MODAL, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import {InteractionManager, Keyboard, View} from 'react-native'; | |
import PropTypes from 'prop-types'; | ||
import _ from 'underscore'; | ||
import ExpensiMark from 'expensify-common/lib/ExpensiMark'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import reportActionPropTypes from './reportActionPropTypes'; | ||
import styles from '../../../styles/styles'; | ||
import Composer from '../../../components/Composer'; | ||
|
@@ -24,6 +25,7 @@ import CONST from '../../../CONST'; | |
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; | ||
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; | ||
import withKeyboardState, {keyboardStatePropTypes} from '../../../components/withKeyboardState'; | ||
import ONYXKEYS from '../../../ONYXKEYS'; | ||
|
||
const propTypes = { | ||
/** All the data of the action */ | ||
|
@@ -32,6 +34,9 @@ const propTypes = { | |
/** Draft message */ | ||
draftMessage: PropTypes.string.isRequired, | ||
|
||
/** Number of lines for the draft message */ | ||
numberOfLines: PropTypes.number, | ||
|
||
/** ReportID that holds the comment we're editing */ | ||
reportID: PropTypes.string.isRequired, | ||
|
||
|
@@ -57,6 +62,7 @@ const defaultProps = { | |
forwardedRef: () => {}, | ||
report: {}, | ||
shouldDisableEmojiPicker: false, | ||
numberOfLines: 1, | ||
}; | ||
|
||
class ReportActionItemMessageEdit extends React.Component { | ||
|
@@ -136,6 +142,14 @@ class ReportActionItemMessageEdit extends React.Component { | |
} | ||
} | ||
|
||
/** | ||
* Update the number of lines for a draft in Onyx | ||
* @param {Number} numberOfLines | ||
*/ | ||
updateNumberOfLines(numberOfLines) { | ||
Report.saveReportActionDraftNumberOfLines(this.props.reportID, this.props.action.reportActionID, numberOfLines); | ||
} | ||
|
||
/** | ||
* Delete the draft of the comment being edited. This will take the comment out of "edit mode" with the old content. | ||
*/ | ||
|
@@ -273,6 +287,8 @@ class ReportActionItemMessageEdit extends React.Component { | |
}} | ||
selection={this.state.selection} | ||
onSelectionChange={this.onSelectionChange} | ||
numberOfLines={this.props.numberOfLines} | ||
onNumberOfLinesChange={numberOfLines => this.updateNumberOfLines(numberOfLines)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
/> | ||
<View style={styles.editChatItemEmojiWrapper}> | ||
<EmojiPickerButton | ||
|
@@ -314,6 +330,12 @@ export default compose( | |
withLocalize, | ||
withWindowDimensions, | ||
withKeyboardState, | ||
withOnyx({ | ||
numberOfLines: { | ||
key: ({reportID, action}) => `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT_NUMBER_OF_LINES}${reportID}_${action.reportActionID}`, | ||
initWithStoredValues: false, | ||
}, | ||
}), | ||
)(React.forwardRef((props, ref) => ( | ||
/* eslint-disable-next-line react/jsx-props-no-spreading */ | ||
<ReportActionItemMessageEdit {...props} forwardedRef={ref} /> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe only using
props.numberOfLines
will do the job? We are already using 1 fornumberOfLines
in default props.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks.