Skip to content

Commit c162e76

Browse files
committed
Fix event emitter bug in iOS
1 parent b50399f commit c162e76

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ios/BgReactNativeTorch.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import React
55
class BgReactNativeTorch: RCTEventEmitter {
66
@objc dynamic var device: AVCaptureDevice? = AVCaptureDevice.default(for: AVMediaType.video)
77
var observer: BgReactNativeTorchObserver? = nil
8+
public static var sharedEmitter:BgReactNativeTorch?
89

910
/// Initialise the module, setting the device using AVCaptureDevice.default
1011
///
1112
/// - Returns: A BgReactNativeTorch object to control the torch
1213
override init() {
14+
super.init()
15+
BgReactNativeTorch.sharedEmitter = self
1316
self.device = AVCaptureDevice.default(for: AVMediaType.video)
1417
self.observer = nil
15-
super.init()
1618
}
1719

1820
/// Initialise the module, using the passed arguments to set device and observer
@@ -97,7 +99,7 @@ class BgReactNativeTorch: RCTEventEmitter {
9799

98100
/// Emit the current enabled and availability states of the torch
99101
func emitEvent() {
100-
sendEvent(
102+
BgReactNativeTorch.sharedEmitter?.sendEvent(
101103
withName: "TorchStateChange",
102104
body: [
103105
"available": checkAvailabilityState(),

0 commit comments

Comments
 (0)