Creating Web Worker in React Native Android app

2020-07-09 02:50发布

问题:

I am building a React Native android app. In app I want to download and parse huge amount of data from server. Since JavaScript is a single threaded language I don't want to execute this on same React Native JSC context. Is it possible to create a Web Worker inside React Native JSC context and do extensive background jobs?

I have tried to do the same, but it says function not available.

回答1:

There is a library exactly for that now. Check out https://github.com/devfd/react-native-workers



回答2:

AFAIK there is no WebWorker polyfill for React Native. You will probably have to write a Native Bridge Module. If you want to avoid that , check out this post where they use requestAnimationFrame to break heavy tasks. https://corbt.com/posts/2015/12/22/breaking-up-heavy-processing-in-react-native.html