react-native-threads icon indicating copy to clipboard operation
react-native-threads copied to clipboard

How can I use third party packages in the working.thread.js?

Open neller1 opened this issue 5 years ago • 3 comments

When I import package to working.thread.js code to use it, I get the error "null is not an object (evaluating 'Package_Name')" So, how can I use packages in the threads?

import { self } from 'react-native-threads';
import './config';
import { start, stop } from "react-native-beep-tone";
  var g=false;
	self.onmessage = message => {
		for (let i = 1; i <= 30; i++){
		  setTimeout(function(){
			//console.tron.log(`THREAD: got message ${i}`);
				g=!g;
				if (g){
					start(50);     // Start playing the sound
					
				}
				else{
					stop();            // Stop playing the sound
					
				}
			
			//self.postMessage(`Message from worker thread!`);
		  }, i * 1000);
		}
	}
	

neller1 avatar Oct 01 '19 11:10 neller1

Probably this way - https://github.com/joltup/react-native-threads#android-1

Also note that only the official react native modules are available from your threads (vibration, fetch, etc...). To include additional native modules in your threads, pass them into the RNThreadPackage constructor after the mReactNativeHost like this: new RNThreadPackage(mReactNativeHost, new ExampleNativePackage(), new SQLitePackage())

minicuper avatar Oct 02 '19 14:10 minicuper

How can i archive this in ios ?

daominhsangvn avatar May 05 '20 15:05 daominhsangvn

what about if some want to import all the package.json modules to it?

RiteshJariwala avatar Oct 20 '23 16:10 RiteshJariwala