I implemented a native module which navigates to a camera activity. But while calling the camera from nativeModules, it takes 1500-2000ms to open(excluding ui updation in camera).
The native module class that extends ReactContextBaseJavaModule
is written like this:
@ReactModule(name = ImagePickerModule.NAME)
public class ImagePickerModule extends ReactContextBaseJavaModule
implements ActivityEventListener
{
....
// Calling this method
@ReactMethod
public void launchCamera(final ReadableMap options, final Callback callback) {
// this method opens camera after checking necessary permissions and applies UI changes which was set by the user previously
}
....
}
And this is nativeModules to JS mapping in the .ts
file
import {NativeModules} from 'react-native';
import {ImagePickerNativeModule} from './privateTypes';
const NativeInterface: ImagePickerNativeModule | undefined =
NativeModules.ImagePickerManager;
const DEFAULT_OPTIONS: ImagePickerOptions = {
// options here
}
class ImagePicker {
launchCamera(options: ImagePickerOptions, callback: Callback): void {
return NativeInterface.launchCamera(
{
...DEFAULT_OPTIONS,
...options,
tintColor: processColor(options.tintColor || DEFAULT_OPTIONS.tintColor),
},
callback,
);
}
}
I am calling the nativeModule from react-native code like this:
export const CustomCamera = (): Promise<{ uri: string }> => {
return new Promise((resolve, reject) => {
ImagePicker.launchCamera(***Camera options passed***)
.then(res => // Do something here)
.catch(err => // Do something here)
}
}
Is there any way I can open the activity faster while calling it from native modules? or keep the activity in the background so that the cameraActivity can load fast while calling it from react-native? Please suggest.