scandit-react-native-datacapture-core 7.2.0-beta.1 → 7.2.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,26 +9,36 @@ import React
9
9
  import ScanditFrameworksCore
10
10
 
11
11
  class RNTSDCDataCaptureViewWrapper: UIView {
12
- weak var viewManager: RNTSDCDataCaptureViewManager?
13
-
14
12
  override func removeFromSuperview() {
15
- if let viewManager = viewManager,
16
- let index = RNTSDCDataCaptureViewManager.containers.firstIndex(of: self) {
13
+ if let index = RNTSDCDataCaptureViewManager.containers.firstIndex(of: self) {
17
14
  dispatchMain {
18
15
  RNTSDCDataCaptureViewManager.containers.remove(at: index)
19
16
  }
20
-
21
- if let droppedView = RNTSDCDataCaptureViewManager.dataCaptureView {
22
- RNTSDCDataCaptureViewManager.dataCaptureView = nil
23
- // on iOS we don't have a callback like the android onDropViewInstance where we can remove the dropped instance.
24
- // here we just override the willRemoveSubview of the wrapper and notify the core module that the dcview has been removed.
25
- DeserializationLifeCycleDispatcher.shared.dispatchDataCaptureViewRemoved(view: droppedView)
26
- }
27
-
28
- viewManager.addCaptureViewToLastContainer()
17
+ }
18
+ if let droppedView = self.findFirstSubview(ofType: DataCaptureView.self) {
19
+ // on iOS we don't have a callback like the android onDropViewInstance where we can remove the dropped instance.
20
+ // here we just override the willRemoveSubview of the wrapper and notify the core module that the dcview has been removed.
21
+ DeserializationLifeCycleDispatcher.shared.dispatchDataCaptureViewRemoved(view: droppedView)
29
22
  }
30
23
  super.removeFromSuperview()
31
24
  }
25
+
26
+ public func findFirstSubview<T: UIView>(ofType type: T.Type) -> T? {
27
+ return self.subviews.first { $0 is T } as? T
28
+ }
29
+
30
+ override func didMoveToSuperview() {
31
+ // When the container is added to the RN stack, we need to check if the container has a DCView or not
32
+ if self.findFirstSubview(ofType: DataCaptureView.self) == nil {
33
+ // In case no DCView was still added to the container, we need to check whether a DCView was already
34
+ // created for this container and in case add the view here.
35
+ if let dcView = DataCaptureViewHandler.shared.getViewById(self.reactTag.intValue) {
36
+ dcView.frame = dcView.bounds
37
+ dcView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
38
+ self.addSubview(dcView)
39
+ }
40
+ }
41
+ }
32
42
  }
33
43
 
34
44
  @objc(RNTSDCDataCaptureViewManager)
@@ -36,68 +46,14 @@ class RNTSDCDataCaptureViewManager: RCTViewManager, DeserializationLifeCycleObse
36
46
 
37
47
  static var containers: [RNTSDCDataCaptureViewWrapper] = []
38
48
 
39
- static var dataCaptureView: DataCaptureView? {
40
- didSet {
41
- guard let container = containers.last else {
42
- return
43
- }
44
-
45
- guard let dcView = dataCaptureView else {
46
- return
47
- }
48
-
49
- if dcView.superview != nil && dcView.superview == container {
50
- // if attached to the same container do nothing. Removing and adding
51
- // it again might trigger something in the DataCaptureView that we don't
52
- // want. (overlay re-drawn, black screen, etc.)
53
- return
54
- }
55
-
56
- if dcView.superview != nil {
57
- dcView.removeFromSuperview()
58
- }
59
- dcView.frame = container.bounds
60
- dcView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
61
- container.addSubview(dcView)
62
- }
63
- }
64
-
65
49
  override class func requiresMainQueueSetup() -> Bool {
66
50
  true
67
51
  }
68
52
 
69
- var isObserving = false
70
-
71
- func addCaptureViewToLastContainer() {
72
- guard let container = RNTSDCDataCaptureViewManager.containers.last,
73
- let captureView = DataCaptureViewHandler.shared.topmostDataCaptureView else {
74
- return
75
- }
76
-
77
- RNTSDCDataCaptureViewManager.dataCaptureView = captureView
78
- }
79
-
80
53
  override func view() -> UIView! {
81
-
82
- if !isObserving {
83
- isObserving = true
84
- }
85
-
86
54
  let container = RNTSDCDataCaptureViewWrapper()
87
55
 
88
- if let dataCaptureview = RNTSDCDataCaptureViewManager.dataCaptureView {
89
- if dataCaptureview.superview != nil {
90
- dataCaptureview.removeFromSuperview()
91
- }
92
- dataCaptureview.frame = container.bounds
93
- dataCaptureview.autoresizingMask = [.flexibleWidth, .flexibleHeight]
94
- container.addSubview(dataCaptureview)
95
- }
96
- container.viewManager = self
97
-
98
- dispatchMain {
99
- RNTSDCDataCaptureViewManager.containers.append(container)
100
- }
56
+ RNTSDCDataCaptureViewManager.containers.append(container)
101
57
 
102
58
  return container
103
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scandit-react-native-datacapture-core",
3
- "version": "7.2.0-beta.1",
3
+ "version": "7.2.0-beta.2",
4
4
  "description": "Scandit Data Capture SDK for React Native",
5
5
  "homepage": "https://github.com/Scandit/scandit-react-native-datacapture-core",
6
6
  "main": "dist/index.js",
@@ -49,6 +49,6 @@
49
49
  "typescript": "4.9.5"
50
50
  },
51
51
  "dependencies": {
52
- "scandit-datacapture-frameworks-core": "7.2.0-beta.1"
52
+ "scandit-datacapture-frameworks-core": "7.2.0-beta.2"
53
53
  }
54
54
  }
@@ -18,6 +18,6 @@ Pod::Spec.new do |s|
18
18
  s.module_name = "ScanditDataCaptureCore"
19
19
  s.header_dir = "ScanditDataCaptureCore"
20
20
 
21
- s.dependency "scandit-datacapture-frameworks-core", '= 7.2.0-beta.1'
21
+ s.dependency "scandit-datacapture-frameworks-core", '= 7.2.0-beta.2'
22
22
  s.dependency "React"
23
23
  end