Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
React Native: Touch events locations in nested views

I am trying to design a slider component in React Native with the following (minimal example) code:

import React from 'react'
import {GestureResponderEvent, View} from 'react-native'

const Slider = (): JSX.Element => {
    const [value, setValue] = React.useState()

    const onTouch = React.useCallback(
        (e: GestureResponderEvent) => setValue(e.nativeEvent.locationX),
        [setValue],
    )

    return (
        <View key="base" style={{flex: 1, flexDirection: 'row'}} onTouchStart={onTouch} onTouchMove={onTouch}>
            <View key="track" style={{width: value, backgroundColor: 'white'}}/>
            <View key="toggle" style={{width: 16, height: 16, borderRadius: 16 / 2, backgroundColor: 'red'}}/>
        </View>
    )
}

I am having issues because the following code works fine if I touch the track View, but not if I touch the toggle View.

This seems to be due to the fact e.nativeEvent.locationX is a relative number inside the toggle view, not the base view.

Any suggestions?

EDIT: I can get the absolute position of the touch events using the e.nativeEvent.pageX and e.nativeEvent.pageY properties, but how can I get the absolute position of the base view? The onLayout callback only gives me the relative one ...

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!