I need to find the location (x and y offset from origin of the component) of specific characters in my multiline text component. I've tried using the onLayout prop of my nested text components, but that function is never called for nested text. Is there a method for calculating the x and y of specific characters (based on index) within a string that are being rendered in a <Text> component with a defined width and height?
import React from 'react'; import {View, Text} from 'react-native'; const renderString = ` Here is a multiline string that I am rendering. I would like a method for finding the x and y position of specific characters within this string when rendered in a text component. ` const height = 400; const width = 400; function findCharacterPosition() { // How do I write this function? } function Comp() { return ( <View style=> <Text> {renderString} </Text> </View> ) } https://stackoverflow.com/questions/66718420/find-character-location-in-text-component-react-native March 20, 2021 at 01:06PM
没有评论:
发表评论