Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda