Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/libs/setSelection/index.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/libs/setSelection/index.native.js

This file was deleted.

13 changes: 13 additions & 0 deletions src/libs/setSelection/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import SetSelection from './types';

const setSelection: SetSelection = (textInput, start, end) => {
if (!textInput) {
return;
}

if ('setSelection' in textInput) {
textInput.setSelection(start, end);
}
};

export default setSelection;
13 changes: 13 additions & 0 deletions src/libs/setSelection/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import SetSelection from './types';

const setSelection: SetSelection = (textInput, start, end) => {
if (!textInput) {
return;
}

if ('setSelectionRange' in textInput) {
textInput.setSelectionRange(start, end);
}
};

export default setSelection;
5 changes: 5 additions & 0 deletions src/libs/setSelection/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {TextInput} from 'react-native';

type SetSelection = (textInput: TextInput | HTMLInputElement, start: number, end: number) => void;

export default SetSelection;
9 changes: 9 additions & 0 deletions src/types/modules/react-native.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import 'react-native';

declare module 'react-native' {
interface TextInput {
// Typescript type declaration is missing in React Native for setting text selection.
setSelection: (start: number, end: number) => void;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a temporary solution as setSelection is missing in react-native. I created a PR directly in react-native to add the type (check the PR description for more context).

}
}