Commit 89f4dd2
fix(ios): avoid incorrectly updating caret position (#50680)
Summary:
Avoid incorrectly updating caret position
Pull Request resolved: #50641
The caret position is updated incorrectly when a user is first typing if an zero-length selection is set.
[IOS] [CHANGED] - Typing into TextInput now will not cause the caret position to update to the beginning when a zero-length selection is set.
Pull Request resolved: #50680
Test Plan:
Tested with the following code(a simplified version from the code in #50641)
```js
const [selection, setSelection] = useState({start: -1, end: -1});
const onSelectionChange = (
evt: NativeSyntheticEvent<TextInputSelectionChangeEventData>,
) => {
const {selection} = evt.nativeEvent;
const {start, end} = selection;
console.log('selection change: ', start, end);
setSelection(selection);
};
return (
<View style={{ position: 'absolute', top: 50, left: 30 }}>
<TextInput
placeholder="test"
selection={selection}
onSelectionChange={onSelectionChange}
/>
</View>
);
```
When using the main branch, the caret position will jump back to the beginning after the first typing.
It works fine after applying this commit.
Reviewed By: fabriziocucci
Differential Revision: D72957245
Pulled By: cipolleschi
fbshipit-source-id: 3586797332b35e86b17f386a35e7d192ff758f7e1 parent f3c2804 commit 89f4dd2
1 file changed
Lines changed: 22 additions & 13 deletions
File tree
- packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput
Lines changed: 22 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
698 | 698 | | |
699 | 699 | | |
700 | 700 | | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
701 | 706 | | |
702 | 707 | | |
703 | 708 | | |
| |||
707 | 712 | | |
708 | 713 | | |
709 | 714 | | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
710 | 718 | | |
711 | 719 | | |
712 | 720 | | |
| |||
721 | 729 | | |
722 | 730 | | |
723 | 731 | | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
737 | 746 | | |
738 | 747 | | |
739 | 748 | | |
| |||
0 commit comments