Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda