Skip to main content
not looking for modal based solutions
Source Link
Nauman Zafar
  • 1.1k
  • 2
  • 16
  • 42

I am looking to find the top/left position of each Text component. This will sound a bit odd but I tried this and it was giving me left & top keys for each Text component. I was testing it on a Snack.

A few hours later, I try this again & now the top & left are missing from this. Checked the documentation as well. They don't mention top & left for onLayout callback.

Actually I need to show a tooltip & need to position it. Any pointers, please

Edit Not looking for a Modal based implementation for my usecase

<View style={{ flexDirection: 'row', flexWrap: 'wrap'}}>
 {textArr.map((text, idx) => {
   return (
    <Text
      onLayout={event => {
        // this was giving me x,y,width,height,top,left values
        console.log(event.nativeLayout.layout);
      }}
    >
      {text}
    </Text>
   );
 })}
</View>

I am looking to find the top/left position of each Text component. This will sound a bit odd but I tried this and it was giving me left & top keys for each Text component. I was testing it on a Snack.

A few hours later, I try this again & now the top & left are missing from this. Checked the documentation as well. They don't mention top & left for onLayout callback.

Actually I need to show a tooltip & need to position it. Any pointers, please

<View style={{ flexDirection: 'row', flexWrap: 'wrap'}}>
 {textArr.map((text, idx) => {
   return (
    <Text
      onLayout={event => {
        // this was giving me x,y,width,height,top,left values
        console.log(event.nativeLayout.layout);
      }}
    >
      {text}
    </Text>
   );
 })}
</View>

I am looking to find the top/left position of each Text component. This will sound a bit odd but I tried this and it was giving me left & top keys for each Text component. I was testing it on a Snack.

A few hours later, I try this again & now the top & left are missing from this. Checked the documentation as well. They don't mention top & left for onLayout callback.

Actually I need to show a tooltip & need to position it. Any pointers, please

Edit Not looking for a Modal based implementation for my usecase

<View style={{ flexDirection: 'row', flexWrap: 'wrap'}}>
 {textArr.map((text, idx) => {
   return (
    <Text
      onLayout={event => {
        // this was giving me x,y,width,height,top,left values
        console.log(event.nativeLayout.layout);
      }}
    >
      {text}
    </Text>
   );
 })}
</View>

Source Link
Nauman Zafar
  • 1.1k
  • 2
  • 16
  • 42

Getting Top/Left of a Text Component

I am looking to find the top/left position of each Text component. This will sound a bit odd but I tried this and it was giving me left & top keys for each Text component. I was testing it on a Snack.

A few hours later, I try this again & now the top & left are missing from this. Checked the documentation as well. They don't mention top & left for onLayout callback.

Actually I need to show a tooltip & need to position it. Any pointers, please

<View style={{ flexDirection: 'row', flexWrap: 'wrap'}}>
 {textArr.map((text, idx) => {
   return (
    <Text
      onLayout={event => {
        // this was giving me x,y,width,height,top,left values
        console.log(event.nativeLayout.layout);
      }}
    >
      {text}
    </Text>
   );
 })}
</View>