Commit Graph

296 Commits

Author SHA1 Message Date
cristianoccazinsp
47637774a1
fix(android): Fix camera parameters getting lost on setting focus. (#2946)
* Fix camera parameters getting lost on setting focus.

* merge error

Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
2020-08-21 08:18:55 -03:00
cristianoccazinsp
628c4162e1
feat(android): Document pictureSize and make sure Camera1 implementation uses it appropriately. (#2945)
Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
2020-08-21 08:18:34 -03:00
SimonErm
20c62fb972
feat(android): use FOCUS_MODE_MACRO if FOCUS_MODE_CONTINOUS_PICTURE is not available and device is scanning (#2912)
Co-authored-by: sermler <s.ermler@evosec.de>
2020-07-23 14:06:29 -03:00
Hendy Irawan
0df72c3114
feat(android): onBarCodeRead should also send raw photo bytes, fixed #2786 (#2923)
* feat: onBarCodeRead should also send raw photo bytes, fixed #2786

* docs: documentation to explain feature #2786
2020-07-23 14:04:18 -03:00
Pradeep S Asundi
360a5b0ce2
feat(android): Added pause and resume recording (#2911)
* Added pause and resume recording functionality for android version 24 onwards

* Added pause and resume recording functions to Camera1.java

Co-authored-by: Pradeep Asundi <pradeep@asundi.in>
2020-07-21 18:32:33 -03:00
fabriziobertoglio1987
04e6f0674c
feat(android): expose an ability to change the frames per second (#2834)
* feat(android): expose an ability to change the frames per second

adding ability to change the video recording
frame per second using [MediaRecorder.setVideoFrameRate][1].

[1]: https://developer.android.com/reference/android/media/MediaRecorder#setVideoFrameRate(int)

* feat(android): adding getSupportedPreviewFpsRange

adding getSupportedPreviewFpsRange method to retrieve
supported android devices frame rates for recording.

* feat(android): updating docs

* feat(android): fix api docs type

* feat(android): adding typescript promise type

* feat(android): log message for Camera2

* feat(android): iOS error if method invoked

Triggering error if android only method getSupportedPreviewFpsRange is invoked on iOS.

* feat(android): expose an ability to change the frames per second

adding ability to change the video recording
frame per second using [MediaRecorder.setVideoFrameRate][1].

[1]: https://developer.android.com/reference/android/media/MediaRecorder#setVideoFrameRate(int)

* feat(android): adding getSupportedPreviewFpsRange

adding getSupportedPreviewFpsRange method to retrieve
supported android devices frame rates for recording.

* feat(android): updating docs

* feat(android): fix api docs type

* feat(android): adding typescript promise type

* feat(android): log message for Camera2

* feat(android): iOS error if method invoked

Triggering error if android only method getSupportedPreviewFpsRange is invoked on iOS.
2020-05-14 08:47:16 -03:00
SimonErm
dc4f65702f
feat(touch): Feature/add on tap events (#2827)
* add TouchEvent on android

* add GestureHandler to detect touches on android

* add property to enable touchDetector on android

* add onTouch event to ios

* add GestureRecognizer to ios

* add onTouch property and js setup

* add missing semicolons

* fix literal notation

* add missing ":"

* fix copy-paste error (wrong var-name)

* pass the native event to the onTouch callback

* replace : with ;

* add onTouch type defs

* add documentation for onTouch property

* scale postion before emitting since the event coordinates are raw pixels

* migrate advanced example to native pinch zoom and onTouch

* split onTouch property into onTap and onDoubleTap
2020-05-12 17:56:42 -03:00
Frieder Bluemle
ce791350a4
feat(android): Update Gradle Wrapper and plugin, fix files (#2818)
* Update yarn.lock

* Remove executable bit from non-executable files

* Update Gradle Wrapper to 5.6.4

* Update Android Gradle plugin to 3.6.3
2020-05-05 16:01:20 -03:00
SimonErm
5b32936f00
feat(zoom): Feature/add native zoom (#2815)
* add native zoom on android

* add native zoom on ios

* add useNativeZoom property

* extract compution of maxZoomFactor to a method

* use optional maxZoomFactor for native zoom

* add useNativeZoom Property to typescript declaration

* add doc entry for useNativeZoom
2020-05-05 15:59:56 -03:00
cristianoccazinsp
baf6f9fd52
fix(android): Fix image path on Android, and add iOS implementation. (#2782)
Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
2020-04-08 17:51:48 -03:00
cristianoccazinsp
85b951ced1
fix(android): Fix Android Camera1 race condition crash (#2781)
* add synchronized to take pictures callback in case camera was already stopped.

This will also prevent a possible null camera object.

* use our mCamera variable instead of the one received in the callback so we know if it has been disposed.

Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
2020-04-08 17:51:27 -03:00
AsminBudha
3ee43d4acd
feat(android): Accept path while taking picture in android (#2769)
* Accept path while taking picture in android

* docs(context): change readme to add path option while taking picture
2020-04-05 11:53:03 -03:00
Cristiano Coelho
0111237eeb Crash fix when getCameraInfo fails 2020-03-26 14:43:14 -03:00
Cristiano Coelho
18d9347dfa improve camera2 to camera1 fallback on legacy devices. 2020-03-14 15:46:58 -03:00
Cristiano Coelho
0911852b53 Use same method to play sounds for consistency and so it works across multiple devices. 2020-03-14 13:43:11 -03:00
Cristiano Coelho
1f895481c9 move shutter sound to right location 2020-03-14 12:46:24 -03:00
Cristiano Coelho
4c757447cb prevent duplicated start calls (#2521) 2020-03-14 12:35:38 -03:00
Cristiano Coelho
886a3bb758 Fixes for Camera1 and Camera2 shutter sound.
Shutter sound should now be consistent with the `playSoundOnCapture` prop. Additionally, it should happen on successful capture as opposed to camera capture start (consistent with iOS and any camera app)

Lastly, added missing props to the docs.
2020-03-14 12:16:22 -03:00
James Wang
398ac120fc fix typo 2020-02-27 14:01:53 +11:00
James Wang
6cc8fefc6f add aupport for limiting scan area for Android 2020-02-27 13:50:32 +11:00
cristianoccazinsp
c7e92b29c8
feature(record): On recording start and end events (#2702)
* This update tries to improve audio recording interruptions on iOS due to phone calls or background music.

- Use a more generic event to handle session interruptions. This removes the need to listen to foreground/background events, and stopping the session this way was actually redundant/wrong (see https://forums.developer.apple.com/thread/61406). This also makes session stopping detection more reliable (calls, suspension due to a call or notification, etc., which would previously not set the recording interrupted flag on every case)

From the above docs: "No, incorrect. You _never_ need to stop your capture session. The capture session automatically stops itself when your app goes to the background and resumes itself when you come back to the foreground."

- Allow for `captureAudio` updates to also update the audio connections internally so the prop can be correctly updated on the fly without remounting.

- add onAudioInterrupted and onAudioConnected events so the UI can handle scenarios where audio is wanted but not available. This should also help in keeping the preview active even if audio is interrupted and we have captureAudio={true}. Lastly, it can be used to detect if we can record audio or not due to the dummy implementation of the audio permission on iOS always returning true.

- check, activate, and release audio sessions (if captureAudio) so we can detect early if audio is available before attempting to connect the input. This will also allow us to detect if we can record even if there was already a call before opening the camera.

- use proper observer for session error instead of of the strong self block. No benefit, but makes code more readable and allows access to instance variables

- getDeviceOrientationWithBlock might fire more than once under some circumstances, ending up taking a picture or video twice. Add a lock and additional check to prevent this.

* no need for change check,

* do not resume audio if we were hinted not to (e.g., music playback happening)

* Move heavy work to a dedicated background thread. Improves camera initial loading and resumes from background.

Details:

- Use a HandlerThread to delegate heavy tasks to background. The thread is managed by the view, and passed down to the implementation in case it also needs to use it. The view will fire start calls and other possibly heavy operations in this thread to avoid ANRs. Some code sent to this thread:
    - start calls: start is extremely heavy and will cause ANRs on some devices, especially when coming back from background
    - Camera1: some preset changes fire a stop/start sequence. These will now happen in the background thread
    - take picture and start recording (from view class) will also start in this thread

- Add some extra null checks

- View was not properly cleaning up itself on destroy (host destroy event was never fired)

* Fix for a possible crash when changing devices and changing focus. If the new device resets the focus, "defocusing" might not be possible if the new device does not support auto focus. For this reason, we need to do a different cleanup on the focus and exposed flags and events.

* start session here also on session queue.

* check for session running before trying to record or capture.
This should fix a possible race condition where both the session start call happens at the same time as the record call

* set preview orientation also in session queue

* no need to set orientation on constructor, and set it on session queue to prevent race conditions

* move device init and checks also to session queue. This prevents possible double initializations.

* catch possible errors when starting camera preview. This might still randomly fail on some devices for some reason.

* delay capture in progress until we have resumed/paused preview.

* do not crash the app if set texture setup failed

* more synchronized checks to prevent crashes due to concurrent camera updates

* remove unused imports

* Handle audio interruption in session queue. This prevents the session isRunning flag from getting corrupted due to concurrent updates to the session.

* Fix possible crash when attempting to retrieve camera parameters.

* Preserve exif/metadata on photo capture. Add a few comments to each step of the capture process

* orientation must be fixed before mirroring

* x/y dimensions are redundantly updated (storing the image sets them automatically). However, orientation must be reset on any image change since the final stored image is automatically rotated when it is modified in place.

* revert mirrorImage order, has to be first since forceUpOrientation adjusts the image afterwards.

* Minor change: also implement `onPictureTaken` for iOS in case anyone needs the early event.

* - Improve Android code so skipProcessing is not needed, the code is more in line with iOS, and is "fast" by default. This means that skipProcessing is no longer needed (nor used), and adding additional options will "slow down" the capture as expected, rather than having always a lot of processing. This shouldn't be a breaking change.

- document the writeExif option, and implement it for iOS as well.

* This is a fix for events possibly being fired not on the main thread, which could cause the whole app to freeze.

* Fire events on the right thread. No need to use UI thread, and fix the still works

* Release CF object which could cause a memleak

* Fix Objects.equals that is only available after API 19

* allow for audio session to be kept even after unmounts

* readme typo

* readme typo

* Make camera ready events to fire also on camera/device change to be consistent with Android. Fire unmount error when session or device fails to start.

* update example app to properly use camera ready event

* Make camera ready events to fire also on camera/device change to be consistent with Android. Fire unmount error when session or device fails to start. Update advanced example app to use camera ready event instead.

* Android crash fixes. Make sure no unsupported aspect ratio is used, and do not crash when there are no cameras available.

* stop/release camera in non-UI thread so we prevent ANRs and UI freezing.

Some phones may take up to a second to release the camera and preview.

* move codec, max duration, and max file size settings to the session queue.

This might prevent a race condition when changing presets/quality.

* android crash fix

* Add onRecordingStart and onRecordingEnd events

* fix for surface destroy and resume events.

* add missing types

* fix for surface destroy and resume events.

* add missing types

Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
2020-02-13 23:21:59 -03:00
cristianoccazinsp
ba0e427304
feat(android): stop/release camera in non-UI thread (#2685)
* stop/release camera in non-UI thread so we prevent ANRs and UI freezing.

Some phones may take up to a second to release the camera and preview.

* fix for surface destroy and resume events.

Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
2020-02-13 18:02:39 -03:00
cristianoccazinsp
7c2572dc7a
fix(record): android crash fix (#2697)
Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
2020-02-05 12:46:02 -03:00
cristianoccazinsp
dea33716aa fix(android): crash fix for android sdk < 18 (#2674)
Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
2020-01-13 14:41:29 -03:00
cristianoccazinsp
db7b9e4a98 fix(android): android crash fixes. Make sure no unsupported aspect ratio is used, and do not crash when there are no cameras available. (#2662) 2019-12-31 12:30:01 -03:00
cristianoccazinsp
8c6a26f289 fix(android): Fix Objects.equals that is only available after API 19 (#2635) 2019-12-10 11:02:16 -03:00
SaeedZhiany
d8cf6c9c10 feat(android): Load Android Gradle Plugin conditionally (#2623) 2019-12-03 16:09:23 -03:00
Märt Lõhmus
1f8b863947 feat(android): restore state when useCamera2api is enabled (#2603) 2019-12-02 09:28:13 -03:00
Stanimir
72c5624dd3 fix(example): fixes and updates in mlkit example (#2618) 2019-12-02 09:24:12 -03:00
Kyle Johnson
32355f4779 fix(android): barcode option passing to mlkit for Android (#2614)
* pass barcode options to mlkit

* rm doubled FORMAT_ALL_FORMATS
2019-12-01 20:50:57 -03:00
cristianoccazinsp
aa22fd1fff feat(exif): Implement writeExif for iOS, Android improvements (#2577)
* - Improve Android code so skipProcessing is not needed, the code is more in line with iOS, and is "fast" by default. This means that skipProcessing is no longer needed (nor used), and adding additional options will "slow down" the capture as expected, rather than having always a lot of processing. This shouldn't be a breaking change.

- document the writeExif option, and implement it for iOS as well.

* Release CF object which could cause a memleak
2019-11-20 00:22:08 -03:00
cristianoccazinsp
ad9d0840fd fix(android): Possible ANR due to events not fired on the main thread (#2591)
* This is a fix for events possibly being fired not on the main thread, which could cause the whole app to freeze.

* Fire events on the right thread. No need to use UI thread, and fix the still works
2019-11-18 09:52:35 -03:00
cristianoccazinsp
be8a08ce9c fix(android): fix possible crash when attempting to retrieve camera parameters. (#2570) 2019-11-11 11:30:06 -03:00
cristianoccazinsp
87774dd370 feat(android): Android ui thread (#2560)
* Move heavy work to a dedicated background thread. Improves camera initial loading and resumes from background.

Details:

- Use a HandlerThread to delegate heavy tasks to background. The thread is managed by the view, and passed down to the implementation in case it also needs to use it. The view will fire start calls and other possibly heavy operations in this thread to avoid ANRs. Some code sent to this thread:
    - start calls: start is extremely heavy and will cause ANRs on some devices, especially when coming back from background
    - Camera1: some preset changes fire a stop/start sequence. These will now happen in the background thread
    - take picture and start recording (from view class) will also start in this thread

- Add some extra null checks

- View was not properly cleaning up itself on destroy (host destroy event was never fired)

* catch possible errors when starting camera preview. This might still randomly fail on some devices for some reason.

* delay capture in progress until we have resumed/paused preview.

* do not crash the app if set texture setup failed

* more synchronized checks to prevent crashes due to concurrent camera updates

* remove unused imports
2019-11-04 14:53:42 -03:00
cristianoccazinsp
7abc7c2e01 feat(torch): Torch fixes for iOS and a few nil checks. (#2543)
* Torch fixes for iOS and a few nil checks.

- Torch turned on by default should work as expected (turned on after mounting and camera type switch)
- Torch maintained when video recording starts (it will flicked if preset has to change)
- Torch resumed when app comes back from background (it is disabled on session pause)

* Fix Torch mode while recording for Android as well.
2019-10-16 18:09:07 -03:00
cristianoccazinsp
686ed2bea8 fix(android): Add synchronized checks on some code that might cause issues if called concurrently. (#2526)
Add try catch on setDisplayOrientation

Should improve issues from https://github.com/react-native-community/react-native-camera/issues/2525
2019-10-09 11:37:00 -03:00
cristianoccazinsp
612cb65f2a feat(android): Support to enumerate and select Camera devices (#2492)
* Android only: Support to enumerate Camera devices and to select from one of them.

* No need to have the camera in running state if querying for IDs.

* Silly bug, not using string compare. Also, do not run any camera code if the actual camera doesn't change.

* Crash fix when focus coordinates are set to null/undefined not being handled. Notes about not supported flash/focus

* If a camera is not found, set the first available camera just like Camera2 does.

* missing semicolon

* Fixes to Camera2 API:

- First change is related to camera selection by ID. Some more code was required to correctly set the facing flag and characteristics
- Second change fixes a previous issue (unrelated to the PR) that was causing the preview of the camera to look upside down on rotated devices. Device rotation should not affect the display (nor set it). Device rotation should however be used for the final image (and not screen rotation). Some code was borrowed from Camera1.
2019-09-24 10:47:23 -03:00
cristianoccazinsp
702f60862e fix(android): Update Camera1 to not crash on invalid ratio (#2501)
Setting a property ends up with an unhandled exception that cannot be caught easily by RN. This should also make the behaviour consistent with camera startup and Camera2.
2019-09-24 09:32:47 -03:00
cristianoccazinsp
a20eb06139 feat(android): Improve Android Camera1 error and concurrency handling. (#2471)
These changes include the following:
- use atomic boolean for capturing photo flag just like video
- add more exception catching and checks
- raise error instead of failing silently if can't capture photo - improve error handling here
- synchronize stop to avoid race conditions and crashes
- delay params updates (surface) if capturing or recording to avoid bugs
- do not allow video or photo capture if already doing video or photo
2019-09-09 09:15:41 -03:00
luancurti
1d6a2ef945 chore(gradle): upgrade gradle version 2019-09-08 22:01:50 -03:00
cristianoccazinsp
57bf513d5b fix(android): Fix app freeze on app/host pause on Android. Fix is quite simple, recording has to be stopped before the camera preview. (#2467)
Fix taken from: https://stackoverflow.com/questions/8914454/mediarecorder-stop-hanging-with-android-4-0-ics/18876200

TODO: Review Camera2 implementation since it might have the same issue.
2019-09-05 17:59:57 -03:00
cristianoccazinsp
497e4a21d8 fix(android): Add an additional error check to avoid crashes on Android. This fix comes from testing on multiple devices, where for some unknown reason the decode process fails and returns null and the app crashes immediately due to a null pointer exception. This attempts to handle this issue more gracefully. (#2446) 2019-09-02 15:29:17 -03:00
joshslark
0323eaa47b fix(android): android-mlkit barcode bounds are inaccurate (#2462) 2019-09-02 09:42:59 -03:00
Dominik Schwarz
ccd6f0b57c feat(android): Add exposure (brightness) support for iOS and standardize exposure value (#2419)
* Use standardized exposure value between 0 and 1

* Add iOS native exposure control

* Delete logging

* Add documentation + spell fixes

* Update RNCamera.m

* Remove reset of exposure after tap-to-focus
2019-08-22 15:38:53 -03:00
cristianoccazinsp
3407533108 fix(android): This update does two things in order to fix #2420 and #2421. (#2427)
First, it updates the take picture call to capture right away instead of trying to focus again. This will match closer to what the native camera does, and also what the Camera2 does.

Secondly, it removes all calls to resetFocus after capturing and after a given timeout. This was causing issues when using autoFocusPointOfInterest, and it really didn't make sense to use an internal timeout to reset the focus. If anything, the user should do this from the JS side. A new method could also be exposed to do this.

Lastly, it adds some error catching logic to the autoFocus call. There was a chance on some devices that calling autoFocus while the device is capturing a photo that it would fail.

Tested on Google Pixel 2 (Android 9), Motorola G5 (Android 8), Samsung Grand Prime (Android 5?), and LG20 (android 6?). No issues so far.
2019-08-17 18:40:37 -03:00
TVMD
efb6b90036 feat(android): get format for android (#2410) 2019-08-07 17:54:10 -03:00
Dominik Schwarz
c93e92f602 fix(android): use initial exposure value (#2418) 2019-08-07 17:47:43 -03:00
Valentin
c748b4eccc fix(android): Support writing custom Exif tags to modified image file (#2402) 2019-08-02 11:10:10 -03:00
Hanno Fellmann
66e99d8027 fix(exif): writing EXIF data with correct data type (#2396) 2019-08-02 11:09:50 -03:00
Valentin
3786223db2 fix(android): prevent crash when using Camera2 with autoFocusPointOfInterest (#2401) 2019-08-02 11:08:38 -03:00