Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setInterval callback is not fired while touch events are being processed #2116

Closed
speigg opened this issue May 15, 2016 · 11 comments · Fixed by #3289
Closed

setInterval callback is not fired while touch events are being processed #2116

speigg opened this issue May 15, 2016 · 11 comments · Fixed by #3289

Comments

@speigg
Copy link
Contributor

speigg commented May 15, 2016

Did you verify this is a real problem

Yes

Tell us about the problem

setInterval callbacks are essentially paused during a touch interaction. This includes touches that happen via a scrollview, or gestures (like a pan gensture).

Which platform(s) does your issue occur on?

iOS

Please provide the following version numbers that your issue occurs with:

  • CLI: 1.7.0
  • Cross-platform modules: 1.7.1
  • Runtime(s): 1.7.0
  • Plugin(s): n/a

Please tell us how to recreate the issue in as much detail as possible.

Create a callback that fires with setInterval, say, every 20 milliseconds (frequently enough for doing a dynamic animation, like with physicsjs). Create a scrollview or add a gesture recognizer to a view, and note that when the app is processing touch events, the setInterval callback does not fire. Once the touch interaction is done processing, the setInterval callback resumes.

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

setInterval(()=>console.log(Date.now()));
// scrollview or something that handles touches. 
@tsonevn tsonevn self-assigned this May 16, 2016
@tsonevn
Copy link
Contributor

tsonevn commented May 16, 2016

Hi @speigg,
Thank you for reporting this issue.

I tested your scenario and confirm this is real issue for iOS. I found that the only way to fire setInterval callback is to press some of the ListView items and then to press Button. I am attaching my sample project.

https://github.com/tsonevn/setIntervalNativeScript.git

Regards,
@tsonevn

@speigg
Copy link
Contributor Author

speigg commented May 17, 2016

Your test case seems a bit more complicated than necessary since you are calling setInterval in response to touch events. If you simply call setInterval(()=>console.log(Date.now()), 20) once when the app starts, then try scrolling a view, you should see that the interval is paused while scrolling happens.

@hamorphis hamorphis removed the backlog label Jul 20, 2016
@tsonevn tsonevn removed their assignment Nov 1, 2016
@tsonevn tsonevn added this to the 2.6.0 (TBD) milestone Dec 5, 2016
@hshristov hshristov modified the milestones: 2.5.0, 2.6.0 (TBD) Dec 5, 2016
@hshristov
Copy link
Contributor

@jasssonpet Could you please check if UI is getting higher priority than setInterval?
If so can we fix it somehow?

@jasssonpet
Copy link
Contributor

jasssonpet commented Dec 6, 2016

This looks familiar to this issue here: https://stackoverflow.com/questions/9090658/

The created timer should be added to the NSRunLoopCommonModes mode if it should have such high priority.

@hamorphis hamorphis self-assigned this Dec 13, 2016
@hamorphis
Copy link
Contributor

@jasssonpet I can add the timer to the NSRunLoopCommonModes by default after it is created in our code. Do you see any potential danger (i.e. UI performance) in doing this or should present a public API for the developer to do this only if he considers it safe and let him be the one responsible for this decision.

@jasssonpet
Copy link
Contributor

My thinking is that there could be UI performance issues depending on the frequency and complexity of the user callbacks. I believe that's why Apple chose to make it an opt-in for a higher priority and in my opinion we should follow this way.

@hamorphis
Copy link
Contributor

hamorphis commented Dec 13, 2016

@jasssonpet Interesting. I added the timer to the current loop with the common modes and initially it was very responsive while scrolling. But after some scrolling it stopped printing again. Not much we can do I guess. Maybe console logging each 20 ms is insane anyway.

@jasssonpet
Copy link
Contributor

jasssonpet commented Dec 13, 2016

I am testing with the following snippet:

setInterval(function() {
    console.log(new Date() / 1000);
    sleep(2); // Simulating some potentially heavy work
}, 1000);
<ScrollView>
    <StackLayout>
        <Label text="Label 1" />
        <!-- ... -->
        <Label text="Label 99" />
    </StackLayout>
</ScrollView>

and the UI can freeze for 2 seconds while scrolling which is unpleasant.

@hamorphis
Copy link
Contributor

Isn't the sleep freezing it?

@hamorphis
Copy link
Contributor

Anyway, we have decided to add it to our code by default.

@lock
Copy link

lock bot commented Aug 29, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Aug 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants