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

252
Visualizações
How can I pass a touch through a view in React Native but trigger the onPress?

I am trying to create a full screen touchable view that gets its onPress triggered but also passes the touch down to the view behind it. In the example below, I'd like to have the onPress function get called when the user scrolls on the scrollview. I'm able to get the scrollview to respond with pointerEvents="none" on the Pressable, but doing that makes the onPress not get triggered. Is there any way to get both of these working together?

const styles = StyleSheet.create({
  containingTouchable: {
    position: 'absolute',
    top: 0,
    right: 0,
    left: 0,
    bottom: 0,
    backgroundColor: 'rgba(100,100,100,0.3)',
  },
});

const Component = () => {
  <Pressable
      style={styles.containingTouchable}
      onPress={() => {
        console.warn('pressed me');
      }}
  >
    <View></View>
  </Pressable>
  <ScrollView> ... </ScrollView>
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I would solve this using react-native-gesture-handler. Instead of Pressable, use TapGestureHandler. And import ScrollView from react-native-gesture-handler.

Rngh provides a prop called simultaneousHandlers so you can listen to multiple touch event at once.

So you could do something like this:

const tapGestureHandlerRef = useRef(null);

<TapGestureHandler
    ref={tapGestureHandlerRef}
    onActivated={handleOnPress}
    onHandlerStateChange={handleOnPress}
>
    <ScrollView
     simultaneousHandlers={tapGestureHandlerRef}
    > 
        {content}
    </ScrollView>
  </TapGestureHandler
>

Both onActivated and onHandlerStateChange can trigger an onPress event, but they behave differently. Take a look at the docs to see what fits your use case the best: https://docs.swmansion.com/react-native-gesture-handler/docs/api/gesture-handlers/tap-gh

about 4 years ago · Juan Pablo Isaza Relatório
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