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

137
Views
React Native button onPressOut function call after 250 ms

I am working with a React Native button in which i am calling a function. But i want to call the function only after 250 ms and when the user leaves the button which means when the onPressOut is called. How can i do that. Currently it's like this:

const onChangeCurtain = () =>{
      setActive(!active);
      onPressItem();
}
const onLongPress = () => {
      setActive(false);
}

return (
  <Container
       onPress={onChangeCurtain}
       onPressOut={onLongPress}
  />
)

Now onChangeCurtain gets called immediately and onLongPress gets called when the user leaves the button. But i don't want onLongPress to be called if pressed for less than 250 ms. It should be called only if it gets pressed for more than 250 ms. How can i do that?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use event listeners on button like onKeyDown and onKeyUp.

In onKeyDown start setTimeout which will perform something after 250ms
And in onKeyUp clear this interval so it will not trigger if user did not pressed guver button long enough.

import * as React from 'react';

export default function App() {
  let downTimer = null;

  const onMouseDown = () => {
    clearTimeout(downTimer);
    downTimer = setTimeout(function() {
      alert('Mouse down > 250 ms');   
    }, 250);
  }

  const onMouseUp = () => {
    clearTimeout(downTimer);
  }

  return (
    <button onMouseUp={ onMouseUp } onMouseDown={ onMouseDown }>asd</button>
  );
}
about 4 years ago · Juan Pablo Isaza Report
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!