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

124
Visualizações
Handling touch in React Native with time

I am working on an onPress event in React Native. I have added two different actions onPress, onLongPress. I have two different functions associated with each of them. Now i have also added delayLongPress={250} and it's working with onLongPress. But when i try to call the onLongPress, it calls the onPress too. I don't want that to happen. I want to call the onpress when it's pressed just once and onLongPress when it's pressed for 250ms at least. How can i seperate those function calls.

Here's what i have right now:

const onLongPress = () =>{
    console.log('Pressed long')
}
const onChange = () =>{
    console.log('Pressed')
}

return(
<Container
     onPress={onChange}
     onLongPress={onLongPress}
     delayLongPress={250}
>
</Container>
)

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

0

Try to wrap it with the TouchableHighlight.

export default function App() {
  const onLongPress = () => {
    console.log('Pressed long');
  };
  const onChange = () => {
    console.log('Pressed');
  };
  return (
    <TouchableHighlight
      onPress={onChange}
      onLongPress={onLongPress}
      delayLongPress={250}
    >
      <Text>Press</Text> // Your child components goes here
    </TouchableHighlight>
  );
}

See the snack here

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