cordova-plugin-mserviceinterface-2.0 1.0.81 → 1.0.82

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-mserviceinterface-2.0",
3
- "version": "1.0.81",
3
+ "version": "1.0.82",
4
4
  "description": "This plugin establishes the connection to the native interface and performs the requested task.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
3
- xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-mserviceinterface-2.0" version="1.0.81">
3
+ xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-mserviceinterface-2.0" version="1.0.82">
4
4
  <name>mserviceinterface-2.0</name>
5
5
  <description>This plugin establishes the connection to the native interface and performs the requested task.</description>
6
6
  <author>selfservit@gmail.com</author>
@@ -72,6 +72,20 @@
72
72
  // Retain reference to the layer
73
73
  objc_setAssociatedObject(self, @selector(previewLayer), previewLayer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
74
74
  [self.viewController.view.layer addSublayer:previewLayer];
75
+
76
+ // Add an "X" close button
77
+ UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
78
+ closeButton.frame = CGRectMake(self.viewController.view.frame.size.width - 50, 50, 40, 40); // Position: Top-right corner
79
+ [closeButton setTitle:@"✕" forState:UIControlStateNormal]; // Unicode "X"
80
+ closeButton.titleLabel.font = [UIFont boldSystemFontOfSize:24];
81
+ [closeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
82
+ closeButton.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
83
+ closeButton.layer.cornerRadius = 20;
84
+ closeButton.clipsToBounds = YES;
85
+ [closeButton addTarget:self action:@selector(closeScanner) forControlEvents:UIControlEventTouchUpInside];
86
+
87
+ [self.viewController.view addSubview:closeButton];
88
+ objc_setAssociatedObject(self, @selector(closeScanner), closeButton, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
75
89
  });
76
90
 
77
91
  // Start scanning on a background thread
@@ -79,7 +93,23 @@
79
93
  [self.captureSession startRunning];
80
94
  });
81
95
  }
96
+ - (void)closeScanner {
97
+ // Stop the capture session
98
+ [self.captureSession stopRunning];
99
+
100
+ // Remove the preview layer and close button
101
+ dispatch_async(dispatch_get_main_queue(), ^{
102
+ AVCaptureVideoPreviewLayer *previewLayer = objc_getAssociatedObject(self, @selector(previewLayer));
103
+ [previewLayer removeFromSuperlayer];
82
104
 
105
+ UIButton *closeButton = objc_getAssociatedObject(self, @selector(closeScanner));
106
+ [closeButton removeFromSuperview];
107
+ });
108
+
109
+ // Notify JavaScript that scanning was cancelled
110
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Scanning cancelled"];
111
+ [self.commandDelegate sendPluginResult:result callbackId:self.callbackID];
112
+ }
83
113
  - (void)ScanQRCode:(CDVInvokedUrlCommand*)command {
84
114
  self.callbackID = command.callbackId;
85
115
 
@@ -113,6 +143,19 @@
113
143
  // Retain reference to the layer
114
144
  objc_setAssociatedObject(self, @selector(previewLayer), previewLayer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
115
145
  [self.viewController.view.layer addSublayer:previewLayer];
146
+ // Add an "X" close button
147
+ UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
148
+ closeButton.frame = CGRectMake(self.viewController.view.frame.size.width - 50, 50, 40, 40); // Position: Top-right corner
149
+ [closeButton setTitle:@"✕" forState:UIControlStateNormal]; // Unicode "X"
150
+ closeButton.titleLabel.font = [UIFont boldSystemFontOfSize:24];
151
+ [closeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
152
+ closeButton.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
153
+ closeButton.layer.cornerRadius = 20;
154
+ closeButton.clipsToBounds = YES;
155
+ [closeButton addTarget:self action:@selector(closeScanner) forControlEvents:UIControlEventTouchUpInside];
156
+
157
+ [self.viewController.view addSubview:closeButton];
158
+ objc_setAssociatedObject(self, @selector(closeScanner), closeButton, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
116
159
  });
117
160
 
118
161
  // Start scanning on a background thread