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

feat: Create Choreographer #11

Merged
merged 13 commits into from
Feb 23, 2024
Merged

feat: Create Choreographer #11

merged 13 commits into from
Feb 23, 2024

Conversation

mrousavy
Copy link
Member

@mrousavy mrousavy commented Feb 23, 2024

Creates Choreographer, a platform specific instance that fires onFrame callbacks at the screen's refresh rate.

The Choreographer instance runs on the Thread that created it. We could create such instances on the UI Thread or any other arbitrary Thread using either react-native-reanimated or react-native-worklets-core.

Currently you can create a Choreographer using the FilamentProxy:

const choreographer = FilamentProxy.createChoreographer()
choreographer.addOnFrameCallback((timestamp: number) => {
  console.log(`onFrame at ${timestamp}`)
})
choreographer.start()
setTimeout(() => {
  choreographer.stop()
}, 1500)

Create on the UI Thread:

runOnUI(() => {
  'worklet'
  const choreographer = FilamentProxy.createChoreographer()
  choreographer.addOnFrameCallback((timestamp: number) => {
    'worklet'
    // TODO: This is currently not possible since we don't have a Worklets integration. This func cannot be called probably.
    // Reanimated did work on something pretty interesting where they abstract all of this on the JS side, meaning there's
    // no change required from our end - we just receive a jsi::Function as normal - but it's not yet public.
    // So to make that work, we need to integrate react-native-reanimated or react-native-worklets-core in RNF for now.
  })
})()

Note: You need to keep a strong reference on the Choreographer, otherwise it might get deleted by GC.

@mrousavy mrousavy merged commit da82108 into main Feb 23, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant