3

How can I move object as function of time in React-Native?

In native iOS I do it like this:

CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(tick:)];
[link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];

Or, how can I track screen render in React-Native?

gran33
  • 12,421
  • 9
  • 48
  • 76

2 Answers2

2

Reactive native uses CADisplayLink internally to perform frame updates on the JS thread. So theoretically everything you do is in sync with the refresh rate of the screen.

You can use the Animated library (or maybe PanResponder if you wish to move object by dragging) and you can get to 60fps.

If this still doesn't answer your needs, you can always create a new native component and do your own rendering using your own display timers.

Artal
  • 8,933
  • 2
  • 27
  • 30
-1

Perhaps these timer functions will help...

Timers

  • setTimeout, clearTimeout
  • setInterval, clearInterval
  • setImmediate, clearImmediate
  • requestAnimationFrame, cancelAnimationFrame

requestAnimationFrame(fn) is not the same as setTimeout(fn, 0) - the former will fire after all the frame has flushed, whereas the latter will fire as quickly as possible (over 1000x per second on a iPhone 5S).

setImmediate is executed at the end of the current JavaScript execution block, right before sending the batched response back to native. Note that if you call setImmediate within a setImmediate callback, it will be executed right away, it won't yield back to native in between.

The Promise implementation uses setImmediate as its asynchronicity primitive.

Reference: https://facebook.github.io/react-native/docs/timers.html

Chris Geirman
  • 9,474
  • 5
  • 37
  • 70
  • However, if it's animations you're after... https://facebook.github.io/react-native/docs/animations.html#content – Chris Geirman Oct 31 '15 at 17:30
  • Thanks man, but timer is not reliable screen renderer. I want 60fps . – gran33 Oct 31 '15 at 17:41
  • what are you trying to do? the requestAnimationFrame() can get you 60fps... you just have to make sure whatever work you're doing between frames can be done in less than 16ms. If you're trying to animate, check out the animation library – Chris Geirman Oct 31 '15 at 19:53