ExpoSelectableText is a custom React Native component that provides text selection functionality.
⚠️ Note: This component is currently supported only on Android.
For iOS, similar functionality can be achieved using a TextInput component combined with the onSelectionChange
and onTouchEnd
props. However, a dedicated iOS implementation written in Swift is part of the planned future development.
npm install expo-selectable-text
![Android Screenshot](https://private-user-images.githubusercontent.com/38195454/403483798-c81c0621-dbea-4fd5-ae06-e35d4df76830.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MDE4NjQsIm5iZiI6MTczOTYwMTU2NCwicGF0aCI6Ii8zODE5NTQ1NC80MDM0ODM3OTgtYzgxYzA2MjEtZGJlYS00ZmQ1LWFlMDYtZTM1ZDRkZjc2ODMwLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDA2MzkyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQzZDFjYTlkMGE4MTJmYzVjOTJmZGQ1YmNhYjgxZWIzM2Q0OWVhOTk5MGE1MTAzMjhiOTExN2FkYmRjYTAxMzYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.6orvmp-c2tl2jS7vvQdRZ50zqL1Adg1J6mMiwHuSvp4)
import { ExpoSelectableTextView } from "expo-selectable-text";
<ExpoSelectableTextView
style={{ flex:1 }}
onSelectionEnd={(event) => alert(JSON.stringify(event.nativeEvent))}
fontSize={18}
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa."
/>
Using FlatList:
<FlatList
data={[1, 2, 3, 4, 6]}
// You need to use this prop to avoid clipping the text
removeClippedSubviews={false}
renderItem={() => (
<ExpoSelectableTextView
style={{ height: 400 }}
onSelectionEnd={(event) => alert(JSON.stringify(event.nativeEvent))}
fontSize={18}
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa."
/>
)}
/>
To use a custom font family, you must configure it with Expo Fonts.
npx expo install expo-font
{
"expo": {
"plugins": [
[
"expo-font",
{
"fonts": ["./assets/fonts/Inter-Black.otf"]
}
]
]
}
}
<ExpoSelectableText
...
fontFamily={"Inter-Black"}
/>
Contributions are very welcome!