1
- import React , { useEffect , useRef , useState } from 'react' ;
1
+ import React , { useRef } from 'react' ;
2
2
import { View } from 'react-native' ;
3
3
import { withOnyx } from 'react-native-onyx' ;
4
4
import PropTypes from 'prop-types' ;
@@ -14,6 +14,7 @@ import TextInput from '../../components/TextInput';
14
14
import Permissions from '../../libs/Permissions' ;
15
15
import ROUTES from '../../ROUTES' ;
16
16
import * as TaskUtils from '../../libs/actions/Task' ;
17
+ import focusAndUpdateMultilineInputRange from '../../libs/focusAndUpdateMultilineInputRange' ;
17
18
18
19
const propTypes = {
19
20
/** Beta features list */
@@ -38,17 +39,6 @@ const defaultProps = {
38
39
function NewTaskDescriptionPage ( props ) {
39
40
const inputRef = useRef ( null ) ;
40
41
41
- // The selection will be used to place the cursor at the end if there is prior text in the text input area
42
- const [ selection , setSelection ] = useState ( { start : 0 , end : 0 } ) ;
43
-
44
- // eslint-disable-next-line rulesdir/prefer-early-return
45
- useEffect ( ( ) => {
46
- if ( props . task . description ) {
47
- const length = props . task . description . length ;
48
- setSelection ( { start : length , end : length } ) ;
49
- }
50
- } , [ props . task . description ] ) ;
51
-
52
42
// On submit, we want to call the assignTask function and wait to validate
53
43
// the response
54
44
const onSubmit = ( values ) => {
@@ -63,13 +53,7 @@ function NewTaskDescriptionPage(props) {
63
53
return (
64
54
< ScreenWrapper
65
55
includeSafeAreaPaddingBottom = { false }
66
- onEntryTransitionEnd = { ( ) => {
67
- if ( ! inputRef . current ) {
68
- return ;
69
- }
70
-
71
- inputRef . current . focus ( ) ;
72
- } }
56
+ onEntryTransitionEnd = { ( ) => focusAndUpdateMultilineInputRange ( inputRef . current ) }
73
57
>
74
58
< HeaderWithBackButton
75
59
title = { props . translate ( 'newTaskPage.description' ) }
@@ -93,10 +77,6 @@ function NewTaskDescriptionPage(props) {
93
77
submitOnEnter
94
78
containerStyles = { [ styles . autoGrowHeightMultilineInput ] }
95
79
textAlignVertical = "top"
96
- selection = { selection }
97
- onSelectionChange = { ( e ) => {
98
- setSelection ( e . nativeEvent . selection ) ;
99
- } }
100
80
/>
101
81
</ View >
102
82
</ Form >
0 commit comments