Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: events in bridgeless mode #3240

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", "onCodeScanned"))
.put(CameraPreviewStoppedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onCodeScanned"))
.put(CameraOutputOrientationChangedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onCodeScanned"))
.put(CameraPreviewOrientationChangedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onCodeScanned"))
.put(AverageFpsChangedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onCodeScanned"))
mrousavy marked this conversation as resolved.
Show resolved Hide resolved
mrousavy marked this conversation as resolved.
Show resolved Hide resolved
.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 = "topAverageFpsChanged"
mrousavy marked this conversation as resolved.
Show resolved Hide resolved
}
}

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"
}
}