From d5acea7d82278223aff72c5eb10ee5e18e80dabf Mon Sep 17 00:00:00 2001 From: Tafel <35837839+tafelnl@users.noreply.github.com> Date: Fri, 4 Jun 2021 15:06:56 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20support=20for=20capac?= =?UTF-8?q?itor=20v3=20(#44)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ⬆️ upgrade capacitor packages * ♻️ [android] refactor code to support new way of handling permissions * ♻️ [ios] refactor code to support v3 * ♻️ [web] refactor code to support v3 * 🔨 refactor package and rollup to reflect new v3 defaults * 📝 update documentation * 🔖 v2.0.0-alpha.0 * 🔨 refactor package and rollup to reflect new v3 defaults * ♻️ [web] refactor error throwing to reflect new capacitor preferences * 📝 update documentation to reflex new capacitor preferences * 🐛 fix typescript definitions * 🔖 v2.0.0-alpha.1 --- CapacitorCommunityBarcodeScanner.podspec | 2 +- README.md | 67 +- android/src/main/AndroidManifest.xml | 6 +- .../barcodescanner/BarcodeScanner.java | 42 +- ios/Plugin.xcodeproj/project.pbxproj | 8 +- ios/Plugin/Plugin.swift | 20 +- ios/Podfile | 2 +- package-lock.json | 3710 +++++++---------- package.json | 76 +- rollup.config.js | 33 +- src/definitions.ts | 12 +- src/index.ts | 10 +- src/web.ts | 31 +- tsconfig.json | 6 +- 14 files changed, 1614 insertions(+), 2411 deletions(-) diff --git a/CapacitorCommunityBarcodeScanner.podspec b/CapacitorCommunityBarcodeScanner.podspec index 6911023..0c50611 100644 --- a/CapacitorCommunityBarcodeScanner.podspec +++ b/CapacitorCommunityBarcodeScanner.podspec @@ -11,7 +11,7 @@ Pod::Spec.new do |s| s.author = package['author'] s.source = { :git => package['repository']['url'], :tag => s.version.to_s } s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}' - s.ios.deployment_target = '11.0' + s.ios.deployment_target = '12.0' s.dependency 'Capacitor' s.swift_version = '5.1' end diff --git a/README.md b/README.md index 06c5a99..6c0b0d8 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ - [Maintainers](#maintainers) - [About](#about) - [Installation](#installation) -- [Configuration](#configuration) - [Usage](#usage) - [Troubleshooting](#troubleshooting) @@ -49,41 +48,6 @@ npx cap sync ### iOS -On iOS, no further steps are needed. - -### Android - -On Android, register the plugin in your main activity: - -```java -import com.dutchconcepts.capacitor.barcodescanner.BarcodeScanner; - -public class MainActivity extends BridgeActivity { - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // Initializes the Bridge - this.init( - savedInstanceState, - new ArrayList>() { - { - // Additional plugins you've installed go here - // Ex: add(TotallyAwesomePlugin.class); - add(BarcodeScanner.class); - } - } - ); - } -} - -``` - -## Configuration - -### iOS - For iOS you need to set a usage description in your info.plist file. This can be done by either adding it to the Source Code directly or by using Xcode Property List inspector. @@ -140,11 +104,9 @@ Within your `AndroidManifest.xml` file, change the following: Scanning a (QR) barcode can be as simple as: ```js -import { Plugins } from '@capacitor/core'; +import { BarcodeScanner } from '@capacitor-community/barcode-scanner'; const startScan = async () => { - const { BarcodeScanner } = Plugins; - BarcodeScanner.hideBackground(); // make background of WebView transparent const result = await BarcodeScanner.startScan(); // start scanning and wait for a result @@ -160,7 +122,7 @@ const startScan = async () => { Because of the fact that the Scanner View will be rendered behind the WebView, you will have to call `hideBackground()` to make the WebView and the `` element transparent. Every other element that needs transparency, you will have to handle yourself. -The `` element is made transparent by adding `background: 'transparent';` to the `style=""` attribute. So in theory it is possible that this is overwritten by some CSS property in your setup. Because this plugins does not aim to fix every single scenario out there, you will have to think of a workaround for this yourself, if this applies to you (probably not). +The `` element is made transparent by adding `background: 'transparent';` to the `style=""` attribute. So in theory it is possible that this is overwritten by some CSS property in your setup. Because this plugin does not aim to fix every single scenario out there, you will have to think of a workaround for this yourself, if this applies to you (probably not). If you still cannot see the camera view, check if any other elements are blocking it. For more info on this see [here](#the-scanner-view-does-not-show-up). @@ -169,10 +131,9 @@ If you still cannot see the camera view, check if any other elements are blockin After `startScan()` is resolved, the Scanner View will be automatically destroyed to save battery. But if you want to cancel the scan before `startScan()` is resolved (AKA no code has been recognized yet), you will have to call `stopScan()` manually. Example: ```js -import { Plugins } from '@capacitor/core'; +import { BarcodeScanner } from '@capacitor-community/barcode-scanner'; const stopScan = () => { - const { BarcodeScanner } = Plugins; BarcodeScanner.showBackground(); BarcodeScanner.stopScan(); }; @@ -184,12 +145,11 @@ In Vue.js you could do something like this in a specific view where you use the ```vue