Skip to content

Commit

Permalink
Merge pull request #19377 from akinwale/task-19135
Browse files Browse the repository at this point in the history
feat: Allow adding newlines in description for tasks
  • Loading branch information
youssef-lr authored Jun 14, 2023
2 parents 862955c + 77a899f commit 9b94847
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
20 changes: 19 additions & 1 deletion src/pages/tasks/NewTaskDescriptionPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useRef} from 'react';
import React, {useEffect, useRef, useState} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -38,6 +38,17 @@ const defaultProps = {
function NewTaskDescriptionPage(props) {
const inputRef = useRef(null);

// The selection will be used to place the cursor at the end if there is prior text in the text input area
const [selection, setSelection] = useState({start: 0, end: 0});

// eslint-disable-next-line rulesdir/prefer-early-return
useEffect(() => {
if (props.task.description) {
const length = props.task.description.length;
setSelection({start: length, end: length});
}
}, [props.task.description]);

// On submit, we want to call the assignTask function and wait to validate
// the response
const onSubmit = (values) => {
Expand Down Expand Up @@ -78,6 +89,13 @@ function NewTaskDescriptionPage(props) {
inputID="taskDescription"
label={props.translate('newTaskPage.descriptionOptional')}
ref={(el) => (inputRef.current = el)}
autoGrowHeight
containerStyles={[styles.autoGrowHeightMultilineInput]}
textAlignVertical="top"
selection={selection}
onSelectionChange={(e) => {
setSelection(e.nativeEvent.selection);
}}
/>
</View>
</Form>
Expand Down
3 changes: 3 additions & 0 deletions src/pages/tasks/NewTaskDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ function NewTaskPage(props) {
<TextInput
inputID="taskDescription"
label={props.translate('newTaskPage.descriptionOptional')}
autoGrowHeight
containerStyles={[styles.autoGrowHeightMultilineInput]}
textAlignVertical="top"
value={taskDescription}
onValueChange={(value) => setTaskDescription(value)}
/>
Expand Down
20 changes: 19 additions & 1 deletion src/pages/tasks/TaskDescriptionPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useRef} from 'react';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -48,6 +48,17 @@ function TaskDescriptionPage(props) {

const inputRef = useRef(null);

// Same as NewtaskDescriptionPage, use the selection to place the cursor correctly if there is prior text
const [selection, setSelection] = useState({start: 0, end: 0});

// eslint-disable-next-line rulesdir/prefer-early-return
useEffect(() => {
if (props.task.report && props.task.report.description) {
const length = props.task.report.description.length;
setSelection({start: length, end: length});
}
}, [props.task.report]);

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand All @@ -69,6 +80,13 @@ function TaskDescriptionPage(props) {
label={props.translate('newTaskPage.descriptionOptional')}
defaultValue={(props.task.report && props.task.report.description) || ''}
ref={(el) => (inputRef.current = el)}
autoGrowHeight
containerStyles={[styles.autoGrowHeightMultilineInput]}
textAlignVertical="top"
selection={selection}
onSelectionChange={(e) => {
setSelection(e.nativeEvent.selection);
}}
/>
</View>
</Form>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceInviteMessagePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class WorkspaceInviteMessagePage extends React.Component {
autoCorrect={false}
autoGrowHeight
textAlignVertical="top"
containerStyles={[styles.workspaceInviteWelcome]}
containerStyles={[styles.autoGrowHeightMultilineInput]}
defaultValue={this.state.welcomeNote}
value={this.state.welcomeNote}
onChangeText={(text) => this.setState({welcomeNote: text})}
Expand Down
2 changes: 1 addition & 1 deletion src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2776,7 +2776,7 @@ const styles = {
width: 250,
},

workspaceInviteWelcome: {
autoGrowHeightMultilineInput: {
maxHeight: 115,
},

Expand Down

0 comments on commit 9b94847

Please sign in to comment.