Skip to content

Commit

Permalink
TextInput - selection prop is not set on component creation
Browse files Browse the repository at this point in the history
Summary:
**Problem:**
`selection` prop is not being set on component creation.
Not quite sure which RN version this issue was introduced but fixing it on latest code.

Use playground for testing (refer to following diff)

**Proposed Solution:**

Added notes in comments but `viewCommands.setTextAndSelection()` is called only on text or selection update which relies on comparing data with `lastNativeSelection`. Problem is that `lastNativeSelection` is initially set to the props value that is passed in so does not send the command on component creation.

So assign a default selection value of `{start: -1, end: -1}` so it can be set on component creation.


**Changelog:**
[General][Fixed] - `selection` prop in `TextInput` was not being applied at component creation

Differential Revision: D56911712
  • Loading branch information
alanleedev authored and facebook-github-bot committed May 3, 2024
1 parent abb7070 commit 478bbfe
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1099,12 +1099,14 @@ function InternalTextInput(props: Props): React.Node {
};

const [mostRecentEventCount, setMostRecentEventCount] = useState<number>(0);

const [lastNativeText, setLastNativeText] = useState<?Stringish>(props.value);
const [lastNativeSelectionState, setLastNativeSelection] = useState<{|
selection: ?Selection,
selection: Selection,
mostRecentEventCount: number,
|}>({selection, mostRecentEventCount});
|}>({
selection: {start: -1, end: -1},
mostRecentEventCount: mostRecentEventCount,
});

const lastNativeSelection = lastNativeSelectionState.selection;

Expand Down

0 comments on commit 478bbfe

Please sign in to comment.