Skip to content

Commit

Permalink
fix: Fix events in bridgeless mode (#3240)
Browse files Browse the repository at this point in the history
* fix: events in bridgeless mode

* Update Events.kt

* Update package/android/src/main/java/com/mrousavy/camera/react/Events.kt

* Update package/android/src/main/java/com/mrousavy/camera/react/CameraViewManager.kt

---------

Co-authored-by: Hanno J. Gödecke <hanno@margelo.com>
Co-authored-by: Marc Rousavy <marcrousavy@hotmail.com>
  • Loading branch information
3 people authored Oct 16, 2024
1 parent 5037e79 commit e2d169a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class CameraViewManager : ViewGroupManager<CameraView>() {

override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? =
MapBuilder.builder<String, Any>()
.put("cameraViewReady", MapBuilder.of("registrationName", "onViewReady"))
.put("cameraInitialized", MapBuilder.of("registrationName", "onInitialized"))
.put("cameraStarted", MapBuilder.of("registrationName", "onStarted"))
.put("cameraStopped", MapBuilder.of("registrationName", "onStopped"))
.put("cameraPreviewStarted", MapBuilder.of("registrationName", "onPreviewStarted"))
.put("cameraPreviewStopped", MapBuilder.of("registrationName", "onPreviewStopped"))
.put("cameraShutter", MapBuilder.of("registrationName", "onShutter"))
.put("cameraOutputOrientationChanged", MapBuilder.of("registrationName", "onOutputOrientationChanged"))
.put("cameraPreviewOrientationChanged", MapBuilder.of("registrationName", "onPreviewOrientationChanged"))
.put("averageFpsChanged", MapBuilder.of("registrationName", "onAverageFpsChanged"))
.put("cameraError", MapBuilder.of("registrationName", "onError"))
.put("cameraCodeScanned", MapBuilder.of("registrationName", "onCodeScanned"))
.put(CameraViewReadyEvent.EVENT_NAME, MapBuilder.of("registrationName", "onViewReady"))
.put(CameraInitializedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onInitialized"))
.put(CameraStartedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onStarted"))
.put(CameraStoppedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onStopped"))
.put(CameraShutterEvent.EVENT_NAME, MapBuilder.of("registrationName", "onShutter"))
.put(CameraErrorEvent.EVENT_NAME, MapBuilder.of("registrationName", "onError"))
.put(CameraCodeScannedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onCodeScanned"))
.put(CameraPreviewStartedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onPreviewStarted"))
.put(CameraPreviewStoppedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onPreviewStopped"))
.put(CameraOutputOrientationChangedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onOutputOrientationChanged"))
.put(CameraPreviewOrientationChangedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onPreviewOrientationChanged"))
.put(AverageFpsChangedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onAverageFpsChanged"))
.build()

override fun getName(): String = TAG
Expand Down
60 changes: 48 additions & 12 deletions package/android/src/main/java/com/mrousavy/camera/react/Events.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,100 @@ import com.facebook.react.bridge.WritableMap
import com.facebook.react.uimanager.events.Event

class CameraInitializedEvent(surfaceId: Int, viewId: Int) : Event<CameraInitializedEvent>(surfaceId, viewId) {
override fun getEventName() = "cameraInitialized"
override fun getEventName() = EVENT_NAME
override fun getEventData(): WritableMap = Arguments.createMap()
companion object {
const val EVENT_NAME = "topCameraInitialized"
}
}

class CameraStartedEvent(surfaceId: Int, viewId: Int) : Event<CameraStartedEvent>(surfaceId, viewId) {
override fun getEventName() = "cameraStarted"
override fun getEventName() = EVENT_NAME
override fun getEventData(): WritableMap = Arguments.createMap()
companion object {
const val EVENT_NAME = "topCameraStarted"
}
}

class CameraStoppedEvent(surfaceId: Int, viewId: Int) : Event<CameraStoppedEvent>(surfaceId, viewId) {
override fun getEventName() = "cameraStopped"
override fun getEventName() = EVENT_NAME
override fun getEventData(): WritableMap = Arguments.createMap()
companion object {
const val EVENT_NAME = "topCameraStopped"
}
}

class CameraPreviewStartedEvent(surfaceId: Int, viewId: Int) : Event<CameraPreviewStartedEvent>(surfaceId, viewId) {
override fun getEventName() = "cameraPreviewStarted"
override fun getEventName() = EVENT_NAME
override fun getEventData(): WritableMap = Arguments.createMap()
companion object {
const val EVENT_NAME = "topCameraPreviewStarted"
}
}

class CameraPreviewStoppedEvent(surfaceId: Int, viewId: Int) : Event<CameraPreviewStoppedEvent>(surfaceId, viewId) {
override fun getEventName() = "cameraPreviewStopped"
override fun getEventName() = EVENT_NAME
override fun getEventData(): WritableMap = Arguments.createMap()
companion object {
const val EVENT_NAME = "topCameraPreviewStopped"
}
}

class CameraShutterEvent(surfaceId: Int, viewId: Int, private val data: WritableMap) : Event<CameraShutterEvent>(surfaceId, viewId) {
override fun getEventName() = "cameraShutter"
override fun getEventName() = EVENT_NAME
override fun getEventData() = data
companion object {
const val EVENT_NAME = "topCameraShutter"
}
}

class CameraOutputOrientationChangedEvent(surfaceId: Int, viewId: Int, private val data: WritableMap) :
Event<CameraOutputOrientationChangedEvent>(surfaceId, viewId) {
override fun getEventName() = "cameraOutputOrientationChanged"
override fun getEventName() = EVENT_NAME
override fun getEventData() = data
companion object {
const val EVENT_NAME = "topCameraOutputOrientationChanged"
}
}

class CameraPreviewOrientationChangedEvent(surfaceId: Int, viewId: Int, private val data: WritableMap) :
Event<CameraPreviewOrientationChangedEvent>(surfaceId, viewId) {
override fun getEventName() = "cameraPreviewOrientationChanged"
override fun getEventName() = EVENT_NAME
override fun getEventData() = data
companion object {
const val EVENT_NAME = "topCameraPreviewOrientationChanged"
}
}

class AverageFpsChangedEvent(surfaceId: Int, viewId: Int, private val data: WritableMap) : Event<CameraShutterEvent>(surfaceId, viewId) {
override fun getEventName() = "averageFpsChanged"
override fun getEventName() = EVENT_NAME
override fun getEventData() = data
companion object {
const val EVENT_NAME = "topCameraAverageFpsChanged"
}
}

class CameraErrorEvent(surfaceId: Int, viewId: Int, private val data: WritableMap) : Event<CameraErrorEvent>(surfaceId, viewId) {
override fun getEventName() = "cameraError"
override fun getEventName() = EVENT_NAME
override fun getEventData() = data
companion object {
const val EVENT_NAME = "topCameraError"
}
}

class CameraViewReadyEvent(surfaceId: Int, viewId: Int) : Event<CameraViewReadyEvent>(surfaceId, viewId) {
override fun getEventName() = "cameraViewReady"
override fun getEventName() = EVENT_NAME
override fun getEventData(): WritableMap = Arguments.createMap()
companion object {
const val EVENT_NAME = "topCameraViewReady"
}
}

class CameraCodeScannedEvent(surfaceId: Int, viewId: Int, private val data: WritableMap) :
Event<CameraCodeScannedEvent>(surfaceId, viewId) {
override fun getEventName() = "cameraCodeScanned"
override fun getEventName() = EVENT_NAME
override fun getEventData() = data
companion object {
const val EVENT_NAME = "topCameraCodeScanned"
}
}

0 comments on commit e2d169a

Please sign in to comment.