Skip to content

Commit

Permalink
feat: implement onCameraReady event on Windows (react-native-camera#3324
Browse files Browse the repository at this point in the history
)

* add onCameraReady event to InitializeAsync

* changed null to nullptr

* treat onCameraReady as a native event

* register onCameraReady event constant

Co-authored-by: Burton Rodman <[email protected]>
Co-authored-by: Ethan <[email protected]>
  • Loading branch information
3 people authored Aug 24, 2021
1 parent 6e33553 commit 7b897b0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/RNCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
style={StyleSheet.absoluteFill}
ref={this._setReference}
onMountError={this._onMountError}
onCameraReady={this._onCameraReady}
onCameraReady={this._onObjectDetected(this._onCameraReady)}
onAudioInterrupted={this._onAudioInterrupted}
onAudioConnected={this._onAudioConnected}
onGoogleVisionBarcodesDetected={this._onObjectDetected(
Expand Down
1 change: 1 addition & 0 deletions windows/ReactNativeCameraCPP/ReactCameraConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "JSValue.h"

#define BarcodeReadEvent L"onBarCodeRead"
#define CameraReadyEvent L"onCameraReady"

namespace winrt::ReactNativeCameraCPP {
class ReactCameraConstants {
Expand Down
6 changes: 6 additions & 0 deletions windows/ReactNativeCameraCPP/ReactCameraView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,12 @@ IAsyncAction ReactCameraView::InitializeAsync() {
});

m_isInitialized = true;

auto control = this->get_strong().try_as<winrt::FrameworkElement>();
if (m_reactContext && control) {
m_reactContext.DispatchEvent(control, CameraReadyEvent, nullptr);
}

}
} catch (winrt::hresult_error const &) {
m_isInitialized = false;
Expand Down
5 changes: 5 additions & 0 deletions windows/ReactNativeCameraCPP/ReactCameraViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ ConstantProviderDelegate ReactCameraViewManager::ExportedCustomDirectEventTypeCo
constantWriter.WriteObjectBegin();
WriteProperty(constantWriter, L"registrationName", BarcodeReadEvent);
constantWriter.WriteObjectEnd();

constantWriter.WritePropertyName(CameraReadyEvent);
constantWriter.WriteObjectBegin();
WriteProperty(constantWriter, L"registrationName", CameraReadyEvent);
constantWriter.WriteObjectEnd();
};
}

Expand Down

0 comments on commit 7b897b0

Please sign in to comment.