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

deps: pull react-native-qrcode-local-image into zeus_modules #2537

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/QRCodeScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { launchImageLibrary } from 'react-native-image-picker';
import { StackNavigationProp } from '@react-navigation/stack';

const LocalQRCode = require('@remobile/react-native-qrcode-local-image');
const LocalQRCode = require('../zeus_modules/@remobile/react-native-qrcode-local-image');

import Header from './Header';
import Button from '../components/Button';
Expand Down
6 changes: 0 additions & 6 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,6 @@ PODS:
- React
- react-native-print (0.11.0):
- React-Core
- react-native-qrcode-local-image (1.0.4):
- React
- react-native-randombytes (3.5.3):
- React
- react-native-restart (0.0.27):
Expand Down Expand Up @@ -1374,7 +1372,6 @@ DEPENDENCIES:
- react-native-notifications (from `../node_modules/react-native-notifications`)
- react-native-ping (from `../node_modules/react-native-ping`)
- react-native-print (from `../node_modules/react-native-print`)
- "react-native-qrcode-local-image (from `../node_modules/@remobile/react-native-qrcode-local-image`)"
- react-native-randombytes (from `../node_modules/react-native-randombytes`)
- react-native-restart (from `../node_modules/react-native-restart`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
Expand Down Expand Up @@ -1520,8 +1517,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-ping"
react-native-print:
:path: "../node_modules/react-native-print"
react-native-qrcode-local-image:
:path: "../node_modules/@remobile/react-native-qrcode-local-image"
react-native-randombytes:
:path: "../node_modules/react-native-randombytes"
react-native-restart:
Expand Down Expand Up @@ -1662,7 +1657,6 @@ SPEC CHECKSUMS:
react-native-notifications: 4601a5a8db4ced6ae7cfc43b44d35fe437ac50c4
react-native-ping: e9f64f02087c3cd2a0bc771ad0cf4a88edaa3072
react-native-print: f704aef52d931bfce6d1d84351dbb5232d7ecb89
react-native-qrcode-local-image: 35ccb306e4265bc5545f813e54cc830b5d75bcfc
react-native-randombytes: 3638d24759d67c68f6ccba60c52a7a8a8faa6a23
react-native-restart: 7595693413fe3ca15893702f2c8306c62a708162
react-native-safe-area-context: dcab599c527c2d7de2d76507a523d20a0b83823d
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@react-navigation/bottom-tabs": "7.0.0-alpha.22",
"@react-navigation/native": "7.0.0-alpha.18",
"@react-navigation/stack": "7.0.0-alpha.20",
"@remobile/react-native-qrcode-local-image": "github:BlueWallet/react-native-qrcode-local-image#31b0113",
"@scure/base": "1.1.6",
"@tradle/react-native-http": "2.0.1",
"@types/dateformat": "5.0.0",
Expand Down
17 changes: 0 additions & 17 deletions patches/rnqli-build.gradle.patch

This file was deleted.

4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2562,10 +2562,6 @@
"@react-navigation/elements" "^2.0.0-alpha.17"
color "^4.2.3"

"@remobile/react-native-qrcode-local-image@github:BlueWallet/react-native-qrcode-local-image#31b0113":
version "1.0.4"
resolved "https://codeload.github.com/BlueWallet/react-native-qrcode-local-image/tar.gz/31b0113110fbafcf5a5f3ca4183a563550f5c352"

"@rnx-kit/chromium-edge-launcher@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@rnx-kit/chromium-edge-launcher/-/chromium-edge-launcher-1.0.0.tgz#c0df8ea00a902c7a417cd9655aab06de398b939c"
Expand Down
12 changes: 12 additions & 0 deletions zeus_modules/@remobile/react-native-qrcode-local-image/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.[aod]
*.DS_Store
.DS_Store
*Thumbs.db
*.iml
.gradle
.idea
node_modules
npm-debug.log
/android/build
/ios/**/*xcuserdata*
/ios/**/*xcshareddata*
12 changes: 12 additions & 0 deletions zeus_modules/@remobile/react-native-qrcode-local-image/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.DS_Store
.DS_Store
*Thumbs.db
.gradle
.idea
*.iml
npm-debug.log
node_modules
/android/build
/ios/**/*xcuserdata*
/ios/**/*xcshareddata*

22 changes: 22 additions & 0 deletions zeus_modules/@remobile/react-native-qrcode-local-image/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2015-2016 YunJiang.Fang <42550564@qq.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
102 changes: 102 additions & 0 deletions zeus_modules/@remobile/react-native-qrcode-local-image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# React Native QRCodeLocalImage (remobile)
A local qrcode image parse for react-native, support for ios and android

## Installation
```sh
npm install @remobile/react-native-qrcode-local-image --save
```
### Installation (iOS)
* Drag RCTQRCodeLocalImage.xcodeproj to your project on Xcode.
* Click on your main project file (the one that represents the .xcodeproj) select Build Phases and drag libRCTQRCodeLocalImage.a from the Products folder inside the RCTQRCodeLocalImage.xcodeproj.
* Look for Header Search Paths and make sure it contains $(SRCROOT)/../../../react-native/React as recursive.

### Installation (Android)
```gradle
...
include ':react-native-qrcode-local-image'
project(':react-native-qrcode-local-image').projectDir = new File(settingsDir, '../node_modules/@remobile/react-native-qrcode-local-image/android')
```

* In `android/app/build.gradle`

```gradle
...
dependencies {
...
compile project(':react-native-qrcode-local-image')
}
```

* register module (in MainApplication.java)

```java
......
import com.remobile.qrcodeLocalImage.RCTQRCodeLocalImagePackage; // <--- import

......

@Override
protected List<ReactPackage> getPackages() {
......
new RCTQRCodeLocalImagePackage() // <------ add here
......
}

```

## Usage

### Example
```js
'use strict';

var React = require('react');
var ReactNative = require('react-native');
var {
StyleSheet,
View,
Text,
} = ReactNative;

var Button = require('@remobile/react-native-simple-button');
var QRCode = require('@remobile/react-native-qrcode-local-image');


module.exports = React.createClass({
getInitialState() {
return {text: ''}
},
onPress() {
QRCode.decode(!app.isandroid?'/Users/fang/Desktop/qr.png':'/sdcard/qr.png', (error, result)=>{
this.setState({text: JSON.stringify({error, result})});
});
},
render() {
return (
<View style={styles.container}>
<Button onPress={this.onPress}>测试</Button>
<Text>
{this.state.text}
</Text>
</View>
);
}
});


var styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'transparent',
justifyContent: 'space-around',
paddingVertical: 150,
},
});
```

### method
- `decode(path, callback)` path canbe local image or url


### see detail use
* https://github.com/remobile/react-native-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion rootProject.ext.get('compileSdkVersion')
buildToolsVersion rootProject.ext.get('buildToolsVersion')

defaultConfig {
minSdkVersion 16
targetSdkVersion rootProject.ext.get('targetSdkVersion')
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:23.0.1'
implementation 'com.facebook.react:react-native:+'
implementation 'com.google.zxing:core:3.2.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.remobile.qrcodeLocalImage">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.remobile.qrcodeLocalImage;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.Base64;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.RGBLuminanceSource;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Hashtable;


public class RCTQRCodeLocalImage extends ReactContextBaseJavaModule {

private Context context;

public RCTQRCodeLocalImage(ReactApplicationContext reactContext) {
super(reactContext);
this.context = context;
}

@Override
public String getName() {
return "RCTQRCodeLocalImage";
}

@ReactMethod
public void decode(String path, Callback callback) {
Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); // 设置二维码内容的编码
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
options.inPreferredConfig = Bitmap.Config.RGB_565;
options.inPurgeable = true;

Bitmap scanBitmap = null;
if (path.startsWith("http://")||path.startsWith("https://")) {
scanBitmap = getbitmap(path);
} else if (path.startsWith("content://")) {
try {
final Uri imagePath = Uri.parse(path.replace("file://", "").replace("file:/", ""));
InputStream inputStream = this.context.getContentResolver().openInputStream(imagePath);
if (inputStream != null) {
scanBitmap = BitmapFactory.decodeStream(inputStream, null, options);
inputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
scanBitmap = null;
}
} else if (path.startsWith("base64://")) {
try {
byte[] decodedBytes = Base64.decode(path.replace("base64://", ""), 0);
scanBitmap = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
} catch (Exception e) {
e.printStackTrace();
scanBitmap = null;
}
} else {
scanBitmap = BitmapFactory.decodeFile(path.replace("file://", ""), options);
}

if (scanBitmap == null) {
callback.invoke("cannot load image");
return;
}

int[] intArray = new int[scanBitmap.getWidth()*scanBitmap.getHeight()];
scanBitmap.getPixels(intArray, 0, scanBitmap.getWidth(), 0, 0, scanBitmap.getWidth(), scanBitmap.getHeight());

RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap.getWidth(), scanBitmap.getHeight(), intArray);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
try {
Result result = reader.decode(bitmap, hints);
if (result == null) {
callback.invoke("image format error");
} else {
callback.invoke(null, result.toString());
}

} catch (Exception e) {
callback.invoke("decode error");
}
}

public static Bitmap getbitmap(String imageUri) {
Bitmap bitmap = null;
try {
URL myFileUrl = new URL(imageUri);
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (OutOfMemoryError e) {
e.printStackTrace();
bitmap = null;
} catch (IOException e) {
e.printStackTrace();
bitmap = null;
}
return bitmap;
}
}
Loading
Loading