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

221 cordova capacitor react integration #224

Merged
merged 10 commits into from
Oct 23, 2024

Conversation

NathanFortyTwo
Copy link
Collaborator

Address issues #223 #222 and #221

Adds code to be able to use ScannerCompatActivity, and enioka-scan services, from an already existing application in cordova, capacitor and react-native using npm packages

Cordova and Capacitor use compatible plugin system so only one package is needed

"enioka-scan",
"scanner",
"integration-layer",
"capacitor"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"capacitor"
"capacitor",
"cordova",
"plugin"

"capacitor"
],
"author": "enioka",
"license": "MIT"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"license": "MIT"
"license": "Apache-2.0"

Comment on lines 1 to 113
implementation group: 'com.enioka.scanner', name: 'provider-os-camera', version: '3.0.1'

//provider dependant, here is for honeywell scanner.

implementation group: 'com.enioka.scanner', name: 'provider-os-honeywell-integrated', version: '3.0.1'
}
```
*(using the ``mavenCentral()`` repository )*


You can then implement your own logic and Activities by creating a class extending ``ScannerCompatActivity``.

```java
import com.enioka.scanner.activities.ScannerCompatActivity;

public class MyScanActivity extends ScannerCompatActivity {

@Override
public void initCamera(){
super.initCamera();

//initCamera logic...
}

@Override
public void onData(List<Barcode> data)
{
//onData Logic
}

//rest of the Activity logic
}

```

## Cordova
Cordova has its own plugin system
You can add the compat library using

```bash
$ cordova plugin add enioka-scan-compat
```

in any .js file :

```js

function foo()
{
window.startActivityNow(
{className:"com.example.myapp.MyScanActivity"},
successHandler,
errorHandler
)
}
```


## Capacitor
Capcitor supports cordova modules installed with npm

``` bash
$ npm install enioka-scan-compat-
```



```html
<script src="js/index.js" type="module"></script>
```

```js
function foo() {
window.startActivityNow(
{className:"com.example.myapp.MyScanActivity"},
successHandler,
errorHandler
)
}
```

## React Native

``` bash
$ npm install enioka-scan-compat-
```

```tsx
import { startActivity } from 'enioka-scan-compat-'

<Button title = "startActivity" onPress={() => startActivity("com.example.myapp.MyScanActivity")}>
</Button>
```

## Troubleshooting

- in gradle.properties :
``android.enableJetifier=true``
- in AndroidManifest.xml
``android.allowBackup=true``
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le formatting du markdown dans un commentaire de PR sera pas ouf, je peux t'envoyer la version RAW si besoin. Reformulation de certains points et simplification.

Pour la partie heritage de notre activity, comment ca s'integre a leur projet ? Est-ce qu'ils doivent rajouter du code java a un endroit particulier pour que le plugin le detecte ?

Markdown:

Compatibility layer for various android application frameworks

enioka-scan provides npm packages that facilitate its integration with non-java applications by allowing you to use the provided Scanner and Camera activities.

For all android projects

The npm plugins only facilitate the integration of the provided UI, however you still need to add the usual Maven Central dependencies in android/app/build.gradle:

dependencies {
    // core library
    implementation group: 'com.enioka.scanner', name: 'enioka-scan-core', version: 'X.Y.Z'
    // wanted device-specific providers (e.g. Camera and Honeywell integrated)
    implementation group: 'com.enioka.scanner', name: 'provider-os-camera', version: 'X.Y.Z'
    implementation group: 'com.enioka.scanner', name: 'provider-os-honeywell-integrated', version: 'X.Y.Z'
}

Cordova and Capacitor

Cordova has its own plugin system. You can add the integration dependency using:

$ cordova plugin add @enioka/enioka-scan-cordova-capacitor-integration

Capcitor supports Cordova modules installed with npm, it therefore uses the same dependency:

$ npm install @enioka/enioka-scan-cordova-capacitor-integration

You can then easily instantiate the scanner activity in any .js file :

function foo() 
{
    window.startActivityNow(
        { className:"com.enioka.scanner.activities.ScannerCompatActivity" },
        successHandler,
        errorHandler
    )
}

React Native

The React Native integration dependency can be installed with the following command:

$ npm install @enioka/enioka-scan-react-native-integration

You can then easily instantiate the scanner activity in any .js file used in your HTML page:

import { startActivity } from 'enioka-scan-react-native-integration'

<Button title = "startActivity" onPress={() => startActivity("com.enioka.scanner.activities.ScannerCompatActivity")}>
</Button>

Troubleshooting

Because your application's manifest will have to be merged with the enioka Scan dependencies, make sure the following properties match the ones used in enioka Scan (which are not the default values):

  • in gradle.properties:
    android.enableJetifier=true
  • in AndroidManifest.xml:
    android.allowBackup=true

Improvements

So far this setup only allows the launch of an activity without much control on their intent extras, and without much thought put into the Service aspect, as these frameworks are primarily UI-oriented and not designed for deep Android integration.

This means:

  • We do not provide any means to easily bind to the Scanner service independently from the provided ScannerCompatActivity. The service should still be available after installing the core dependency, so your franework may offer a way to bind to it.
  • We do not provide any means to easily extend the UI beyond simply launching the default one, you may be able to extend it in a Java class and use this class in the startActivity() call instead, but Java will still be needed.
  • We do not provide any way to customize the startActivity() intent for now though that will be a feature down the line.

return false;
}

Intent intent = new Intent(this.cordova.getContext(), klass);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ca pourrait etre bien de supporter un bundle / des extras a integrer a cet intent, pour permettre a l'utilisateur de controller les options de l'application (voir app de demo pour comment ce serait utilise). C'est ok si pas evident tout de suite, ca peut attendre une autre MR.

@@ -0,0 +1,3 @@
*.pbxproj -text
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitattributes pas necessaire, a supprimer

Comment on lines 2 to 4
ActivityStarter_minSdkVersion=21
ActivityStarter_targetSdkVersion=31
ActivityStarter_compileSdkVersion=31
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On va preferer reprendre les versions de la lib core plutot que de l'appli de demo (qui est plus elevee uniquement pour pouvoir passer sur le play store):

Suggested change
ActivityStarter_minSdkVersion=21
ActivityStarter_targetSdkVersion=31
ActivityStarter_compileSdkVersion=31
ActivityStarter_minSdkVersion=19
ActivityStarter_targetSdkVersion=28
ActivityStarter_compileSdkVersion=28

Activity activity = getCurrentActivity();
try {
Class<?> klass = Class.forName(targetActivity);
Intent intent = new Intent(activity, klass);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comme pour Cordova, si possible on aimerait donner plus de controle a l'utilisateur avec le support d'intent extras / bundles comme ce qui est fait dans l'app de demo pour appliquer les parametres au service.

@@ -0,0 +1,14 @@
pre-commit:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas necessaire pour notre cas d'usage, a supprimer

@@ -0,0 +1,187 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a nettoyer au maximum pour ne conserver que le strict necessaire pour le plugin npm

@@ -0,0 +1 @@
it.todo('write a test');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas necessaire, a supprimer

@NathanFortyTwo
Copy link
Collaborator Author

bundle/extras pas encore intégrés aux Intent dans startActivity,
Je ne suis pas sur de comment récupérer le bundle depuis le code utilisateur.

@DaSpood DaSpood merged commit c33cb27 into master Oct 23, 2024
@DaSpood DaSpood deleted the 221-cordova-capacitor-react-integration branch October 23, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants