BlinkID / blinkid-react-native

ID scanning for cross-platform apps built with ReactNative.
172 stars 59 forks source link

Close camera programatically #207

Open feardarkness opened 1 year ago

feardarkness commented 1 year ago

I'm using blinkid-react-native 5.17.0 and I couldn't find a way to close the camera programatically. Is there any way to do it?

I would like to call something like BlinkIDReactNative.BlinkID.closeCamera()

somyaguptagit commented 1 year ago

Hello @feardarkness,

Thank you for reaching out!

Just to keep you informed, that we do not have exact solution in React-Native to close the camera programmatically, but you can customize our Java wrapper since it is an open-source.

I suggest that you fork the repository and make the change in the following file: BlinkID/src/android/src/main/java/com/microblink/reactnative/MicroblinkModule.java

In line 76, you can add a handler which, after 10 seconds, closes the scanning activity:

(new Handler(Looper.getMainLooper())).postDelayed(new Runnable() { @Override public void run() { getCurrentActivity().finishActivity(REQUEST_CODE); } }, 10000);

Let us know if you find this helpful.

feardarkness commented 1 year ago

Hi @somyaguptagit, thank you for the answer. I will test it tomorrow, but, what can I do on IOS?

somyaguptagit commented 1 year ago

Hello @feardarkness, Thank you for your response!

We will look into how can we implement it on iOS from our end and reach out once we we have gathered more information.

mparadina commented 1 year ago

Hi @feardarkness

Allow me to jump in.

You can, for instance, add an NSTimer in the MBBlinkIDModule.m in the path: _.../nodemodules/blinkid-react-native/src/ios/MicroblinkModule/MicroblinkModule/MBBlinkIDModule.m

Below line 99, you can add:

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10 repeats:NO block:^(NSTimer * _Nonnull timer) {
        [rootViewController dismissViewControllerAnimated:YES completion:nil];
}];

This will close the scanning controller in 10 seconds. Please test it out and let me know if it helps.