@momo-kits/qrcode 0.150.2-beta.11 → 0.150.2-beta.13
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/LICENSE +1 -1
- package/Qrcode.podspec +43 -0
- package/README.md +4 -8
- package/android/build.gradle +10 -3
- package/android/gradle.properties +8 -5
- package/android/src/main/java/com/momokits/qrcode/MomoBarCodeViewManager.kt +111 -0
- package/android/src/main/java/com/momokits/qrcode/MomoQrCodeUtils.kt +23 -0
- package/android/src/main/java/com/momokits/qrcode/MomoQrCodeViewManager.kt +96 -0
- package/android/src/main/java/com/momokits/qrcode/{RCTQRCodePackage.kt → MomoQrCodeViewPackage.kt} +9 -10
- package/ios/BarCodeView.h +20 -0
- package/ios/BarCodeView.m +65 -0
- package/ios/QRCodeView.h +19 -0
- package/ios/QRCodeView.m +74 -0
- package/ios/RNBarCode.h +11 -0
- package/ios/RNBarCode.mm +63 -0
- package/ios/RNQRCode.h +10 -0
- package/ios/RNQRCode.mm +66 -0
- package/lib/module/BarCodeView.js +16 -0
- package/lib/module/BarCodeView.js.map +1 -0
- package/lib/module/QRCodeView.js +42 -0
- package/lib/module/QRCodeView.js.map +1 -0
- package/lib/module/RNBarCodeNativeComponent.ts +15 -0
- package/lib/module/RNQRCodeNativeComponent.ts +10 -0
- package/lib/module/index.js +5 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/BarCodeView.d.ts +10 -0
- package/lib/typescript/src/BarCodeView.d.ts.map +1 -0
- package/lib/typescript/src/QRCodeView.d.ts +14 -0
- package/lib/typescript/src/QRCodeView.d.ts.map +1 -0
- package/lib/typescript/src/RNBarCodeNativeComponent.d.ts +15 -0
- package/lib/typescript/src/RNBarCodeNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/RNQRCodeNativeComponent.d.ts +10 -0
- package/lib/typescript/src/RNQRCodeNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +160 -159
- package/src/BarCodeView.tsx +15 -0
- package/src/QRCodeView.tsx +63 -0
- package/src/RNBarCodeNativeComponent.ts +15 -0
- package/src/RNQRCodeNativeComponent.ts +10 -0
- package/src/index.tsx +6 -2
- package/RCTQRCode.podspec +0 -21
- package/android/src/main/java/com/momokits/qrcode/RCTQRCodeView.kt +0 -99
- package/android/src/main/java/com/momokits/qrcode/RCTQRCodeViewManager.kt +0 -52
- package/ios/RCTQRCodeComponentView.mm +0 -11
- package/ios/RCTQRCodeView.h +0 -19
- package/ios/RCTQRCodeView.mm +0 -142
- package/ios/RCTQRCodeViewManager.mm +0 -21
- package/lib/module/RCTQRCodeViewNativeComponent.ts +0 -10
- package/lib/typescript/src/RCTQRCodeViewNativeComponent.d.ts +0 -10
- package/lib/typescript/src/RCTQRCodeViewNativeComponent.d.ts.map +0 -1
- package/src/RCTQRCodeViewNativeComponent.ts +0 -10
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025
|
|
3
|
+
Copyright (c) 2025 dung.pham2
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
|
6
6
|
in the Software without restriction, including without limitation the rights
|
package/Qrcode.podspec
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "Qrcode"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://www.npmjs.com/.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm}"
|
|
17
|
+
s.private_header_files = "ios/**/*.h"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
21
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
22
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
23
|
+
install_modules_dependencies(s)
|
|
24
|
+
else
|
|
25
|
+
s.dependency "React-Core"
|
|
26
|
+
|
|
27
|
+
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
28
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
29
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
30
|
+
s.pod_target_xcconfig = {
|
|
31
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
32
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
33
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
34
|
+
}
|
|
35
|
+
s.dependency "React-RCTFabric"
|
|
36
|
+
s.dependency "React-Codegen"
|
|
37
|
+
s.dependency "RCT-Folly"
|
|
38
|
+
s.dependency "RCTRequired"
|
|
39
|
+
s.dependency "RCTTypeSafety"
|
|
40
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
package/README.md
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
# @momo-kits/qrcode
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
a package
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
```sh
|
|
9
8
|
npm install @momo-kits/qrcode
|
|
10
9
|
```
|
|
11
10
|
|
|
12
|
-
|
|
13
11
|
## Usage
|
|
14
12
|
|
|
15
13
|
|
|
16
14
|
```js
|
|
17
|
-
import {
|
|
15
|
+
import { QrcodeView } from "@momo-kits/qrcode";
|
|
18
16
|
|
|
19
17
|
// ...
|
|
20
18
|
|
|
21
|
-
<
|
|
19
|
+
<QrcodeView color="tomato" />
|
|
22
20
|
```
|
|
23
21
|
|
|
24
22
|
|
|
25
23
|
## Contributing
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
29
|
-
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
25
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
30
26
|
|
|
31
27
|
## License
|
|
32
28
|
|
package/android/build.gradle
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
buildscript {
|
|
2
2
|
ext.getExtOrDefault = {name ->
|
|
3
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Qrcode_' + name]
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
repositories {
|
|
@@ -22,7 +22,7 @@ apply plugin: "kotlin-android"
|
|
|
22
22
|
apply plugin: "com.facebook.react"
|
|
23
23
|
|
|
24
24
|
def getExtOrIntegerDefault(name) {
|
|
25
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["
|
|
25
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Qrcode_" + name]).toInteger()
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
android {
|
|
@@ -74,5 +74,12 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
|
74
74
|
dependencies {
|
|
75
75
|
implementation "com.facebook.react:react-android"
|
|
76
76
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
77
|
-
implementation 'com.google.zxing:core:3.
|
|
77
|
+
implementation 'com.google.zxing:core:3.2.1'
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
react {
|
|
82
|
+
jsRootDir = file("../src/")
|
|
83
|
+
libraryName = "QrcodeView"
|
|
84
|
+
codegenJavaPackageName = "com.momokits.qrcode"
|
|
78
85
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
Qrcode_kotlinVersion=2.0.21
|
|
2
|
+
Qrcode_minSdkVersion=24
|
|
3
|
+
Qrcode_targetSdkVersion=34
|
|
4
|
+
Qrcode_compileSdkVersion=35
|
|
5
|
+
Qrcode_ndkVersion=27.1.12297006
|
|
6
|
+
|
|
7
|
+
newArchEnabled=true
|
|
8
|
+
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
package com.momokits.qrcode
|
|
2
|
+
|
|
3
|
+
// MomoBarCodeViewManager.kt
|
|
4
|
+
|
|
5
|
+
//package com.qrcode
|
|
6
|
+
|
|
7
|
+
import android.graphics.Bitmap
|
|
8
|
+
import android.os.Build
|
|
9
|
+
import android.widget.ImageView
|
|
10
|
+
import androidx.annotation.Nullable
|
|
11
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
|
12
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
13
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
14
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
15
|
+
import com.facebook.react.viewmanagers.RNBarCodeManagerInterface
|
|
16
|
+
import com.facebook.react.viewmanagers.RNBarCodeManagerDelegate
|
|
17
|
+
import com.google.zxing.BarcodeFormat
|
|
18
|
+
import com.google.zxing.EncodeHintType
|
|
19
|
+
import com.google.zxing.WriterException
|
|
20
|
+
import com.google.zxing.common.BitMatrix
|
|
21
|
+
import com.google.zxing.oned.Code128Writer
|
|
22
|
+
|
|
23
|
+
class MomoBarCodeViewManager :
|
|
24
|
+
SimpleViewManager<ImageView>(), // base class
|
|
25
|
+
RNBarCodeManagerInterface<ImageView> { // generated interface
|
|
26
|
+
|
|
27
|
+
companion object {
|
|
28
|
+
const val REACT_CLASS = "RNBarCode"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// wire up the delegate
|
|
32
|
+
private val delegate: RNBarCodeManagerDelegate<ImageView, MomoBarCodeViewManager> =
|
|
33
|
+
RNBarCodeManagerDelegate(this)
|
|
34
|
+
|
|
35
|
+
override fun getName() = REACT_CLASS
|
|
36
|
+
|
|
37
|
+
private var code: String? = null
|
|
38
|
+
private var width: Int = 0
|
|
39
|
+
private var height: Int = 0
|
|
40
|
+
private var ratio: Double = 1.0
|
|
41
|
+
|
|
42
|
+
private val hintMap = HashMap<EncodeHintType, Any>()
|
|
43
|
+
private val code128Writer = Code128Writer()
|
|
44
|
+
|
|
45
|
+
override fun createViewInstance(context: ThemedReactContext): ImageView {
|
|
46
|
+
val imageView = ImageView(context)
|
|
47
|
+
// initialize hints
|
|
48
|
+
hintMap[EncodeHintType.MARGIN] = 0
|
|
49
|
+
hintMap[EncodeHintType.CHARACTER_SET] = "UTF-8"
|
|
50
|
+
return scaleToFitImage(imageView)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private fun scaleToFitImage(imageView: ImageView): ImageView {
|
|
54
|
+
imageView.adjustViewBounds = true
|
|
55
|
+
imageView.scaleType = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
|
|
56
|
+
ImageView.ScaleType.MATRIX
|
|
57
|
+
} else {
|
|
58
|
+
ImageView.ScaleType.FIT_CENTER
|
|
59
|
+
}
|
|
60
|
+
return imageView
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// these come from BarCodeManagerInterface:
|
|
64
|
+
@ReactProp(name = "code")
|
|
65
|
+
override fun setCode(view: ImageView, @Nullable code: String?) {
|
|
66
|
+
this.code = code
|
|
67
|
+
parseToBarCode(view)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@ReactProp(name = "ratio")
|
|
71
|
+
override fun setRatio(view: ImageView, value: Float) {
|
|
72
|
+
this.ratio = ratio ?: 1.0
|
|
73
|
+
parseToBarCode(view)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@ReactProp(name = "width")
|
|
77
|
+
override fun setWidth(view: ImageView, width: Int) {
|
|
78
|
+
this.width = width ?: 0
|
|
79
|
+
parseToBarCode(view)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@ReactProp(name = "height")
|
|
83
|
+
override fun setHeight(view: ImageView, height: Int) {
|
|
84
|
+
this.height = height ?: 0
|
|
85
|
+
parseToBarCode(view)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private fun parseToBarCode(imageView: ImageView) {
|
|
89
|
+
val text = code
|
|
90
|
+
if (!text.isNullOrEmpty() && width > 0 && height > 0) {
|
|
91
|
+
try {
|
|
92
|
+
val w = (ratio * width).toInt()
|
|
93
|
+
val h = (ratio * height).toInt()
|
|
94
|
+
val bm: BitMatrix =
|
|
95
|
+
code128Writer.encode(text, BarcodeFormat.CODE_128, w, h, hintMap)
|
|
96
|
+
val bitmap: Bitmap = MomoQrCodeUtils.createBitmap(bm, w, h)
|
|
97
|
+
imageView.setImageBitmap(bitmap)
|
|
98
|
+
} catch (e: WriterException) {
|
|
99
|
+
e.printStackTrace()
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
scaleToFitImage(imageView)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Fabric requires you to expose the delegate:
|
|
106
|
+
override fun getDelegate(): ViewManagerDelegate<ImageView>? =
|
|
107
|
+
delegate
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.momokits.qrcode
|
|
2
|
+
|
|
3
|
+
import android.graphics.Bitmap
|
|
4
|
+
import com.google.zxing.common.BitMatrix
|
|
5
|
+
|
|
6
|
+
object MomoQrCodeUtils {
|
|
7
|
+
private const val WHITE = -0x1
|
|
8
|
+
private const val BLACK = -0x1000000
|
|
9
|
+
|
|
10
|
+
fun createBitmap(matrix: BitMatrix, width: Int, height: Int): Bitmap {
|
|
11
|
+
val pixels = IntArray(width * height)
|
|
12
|
+
for (y in 0..<height) {
|
|
13
|
+
val offset = y * width
|
|
14
|
+
for (x in 0..<width) {
|
|
15
|
+
pixels[offset + x] = if (matrix[x, y]) BLACK else WHITE
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
|
20
|
+
bitmap.setPixels(pixels, 0, width, 0, 0, width, height)
|
|
21
|
+
return bitmap
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// MomoQrCodeViewManager.kt
|
|
2
|
+
|
|
3
|
+
package com.momokits.qrcode
|
|
4
|
+
|
|
5
|
+
import android.R.attr.bitmap
|
|
6
|
+
import android.graphics.Bitmap
|
|
7
|
+
import android.widget.ImageView
|
|
8
|
+
import androidx.annotation.Nullable
|
|
9
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
|
10
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
11
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
12
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
13
|
+
import com.facebook.react.viewmanagers.RNQRCodeManagerDelegate
|
|
14
|
+
import com.facebook.react.viewmanagers.RNQRCodeManagerInterface
|
|
15
|
+
import com.google.zxing.BarcodeFormat
|
|
16
|
+
import com.google.zxing.EncodeHintType
|
|
17
|
+
import com.google.zxing.WriterException
|
|
18
|
+
import com.google.zxing.common.BitMatrix
|
|
19
|
+
import com.google.zxing.oned.Code128Writer
|
|
20
|
+
import com.google.zxing.qrcode.QRCodeWriter
|
|
21
|
+
import kotlin.math.floor
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class MomoQrCodeViewManager :
|
|
25
|
+
SimpleViewManager<ImageView>(),
|
|
26
|
+
RNQRCodeManagerInterface<ImageView> {
|
|
27
|
+
|
|
28
|
+
private var code: String? = null
|
|
29
|
+
private var size: Int = 200
|
|
30
|
+
private var ratio: Double = 1.0
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
private val hintMap = HashMap<EncodeHintType, Any>()
|
|
34
|
+
private val code128Writer = Code128Writer()
|
|
35
|
+
|
|
36
|
+
companion object {
|
|
37
|
+
const val REACT_CLASS = "RNQRCode"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private val delegate: RNQRCodeManagerDelegate<ImageView, MomoQrCodeViewManager> =
|
|
41
|
+
RNQRCodeManagerDelegate(this)
|
|
42
|
+
|
|
43
|
+
override fun getName() = REACT_CLASS
|
|
44
|
+
|
|
45
|
+
override fun createViewInstance(ctx: ThemedReactContext) =
|
|
46
|
+
ImageView(ctx)
|
|
47
|
+
|
|
48
|
+
@ReactProp(name = "code")
|
|
49
|
+
override fun setCode(view: ImageView, @Nullable code: String?) {
|
|
50
|
+
this.code = code
|
|
51
|
+
parseToQRCode(view)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@ReactProp(name = "ratio")
|
|
55
|
+
override fun setRatio(view: ImageView, value: Float) {
|
|
56
|
+
this.ratio = ratio ?: 1.0
|
|
57
|
+
parseToQRCode(view)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@ReactProp(name = "size")
|
|
61
|
+
override fun setSize(view: ImageView, size: Int) {
|
|
62
|
+
this.size = size ?: 0
|
|
63
|
+
parseToQRCode(view)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override fun getDelegate(): ViewManagerDelegate<ImageView>? =
|
|
67
|
+
delegate
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
private fun parseToQRCode(imageView: ImageView) {
|
|
71
|
+
val text = code
|
|
72
|
+
val currentSize = size
|
|
73
|
+
if (!text.isNullOrEmpty() && currentSize > 0) {
|
|
74
|
+
try {
|
|
75
|
+
val adjustedSize = (ratio * currentSize).toInt()
|
|
76
|
+
val hintMap = HashMap<EncodeHintType, Any>().apply {
|
|
77
|
+
put(EncodeHintType.MARGIN, 0)
|
|
78
|
+
put(EncodeHintType.CHARACTER_SET, "UTF-8")
|
|
79
|
+
}
|
|
80
|
+
val bitMatrix: BitMatrix = QRCodeWriter().encode(
|
|
81
|
+
text,
|
|
82
|
+
BarcodeFormat.QR_CODE,
|
|
83
|
+
adjustedSize,
|
|
84
|
+
adjustedSize,
|
|
85
|
+
hintMap
|
|
86
|
+
)
|
|
87
|
+
val bitmap: Bitmap = MomoQrCodeUtils.createBitmap(bitMatrix, adjustedSize, adjustedSize)
|
|
88
|
+
imageView.adjustViewBounds = true
|
|
89
|
+
imageView.scaleType = ImageView.ScaleType.FIT_CENTER
|
|
90
|
+
imageView.setImageBitmap(bitmap)
|
|
91
|
+
} catch (e: WriterException) {
|
|
92
|
+
e.printStackTrace()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
package/android/src/main/java/com/momokits/qrcode/{RCTQRCodePackage.kt → MomoQrCodeViewPackage.kt}
RENAMED
|
@@ -4,16 +4,15 @@ import com.facebook.react.ReactPackage
|
|
|
4
4
|
import com.facebook.react.bridge.NativeModule
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
6
|
import com.facebook.react.uimanager.ViewManager
|
|
7
|
-
import java.util.ArrayList
|
|
8
7
|
|
|
9
|
-
class
|
|
10
|
-
override fun
|
|
11
|
-
|
|
12
|
-
viewManagers.add(RCTQRCodeViewManager())
|
|
13
|
-
return viewManagers
|
|
14
|
-
}
|
|
8
|
+
class MomoQrCodeViewPackage : ReactPackage {
|
|
9
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> =
|
|
10
|
+
emptyList()
|
|
15
11
|
|
|
16
|
-
override fun
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
|
|
13
|
+
listOf(
|
|
14
|
+
MomoQrCodeViewManager(),
|
|
15
|
+
MomoBarCodeViewManager()
|
|
16
|
+
)
|
|
19
17
|
}
|
|
18
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// QRCodeView.h
|
|
3
|
+
// MoMoPlatform
|
|
4
|
+
//
|
|
5
|
+
// Created by NGUYEN HOANG MINH on 08/05/2020 AP.
|
|
6
|
+
// Copyright © 1399 Facebook. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <UIKit/UIKit.h>
|
|
10
|
+
|
|
11
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
12
|
+
|
|
13
|
+
@interface BarCodeView : UIImageView
|
|
14
|
+
@property (nonatomic, strong) NSString *code;
|
|
15
|
+
@property (nonatomic, assign) CGFloat ratio;
|
|
16
|
+
@property (nonatomic, assign) NSInteger width;
|
|
17
|
+
@property (nonatomic, assign) NSInteger height;
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
#import "BarCodeView.h"
|
|
3
|
+
|
|
4
|
+
@implementation BarCodeView
|
|
5
|
+
|
|
6
|
+
- (void)setCode:(NSString *)code {
|
|
7
|
+
_code = code;
|
|
8
|
+
[self setBarCode: self.code ratio:self.ratio width: self.width height: self.height];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
- (void)setRatio:(CGFloat)ratio {
|
|
12
|
+
_ratio = ratio;
|
|
13
|
+
[self setBarCode:self.code ratio:self.ratio width:self.width height:self.height];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
- (void)setWidth:(NSInteger)width {
|
|
17
|
+
_width = width;
|
|
18
|
+
[self setBarCode:self.code ratio:self.ratio width:self.width height:self.height];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
- (void)setHeight:(NSInteger)height {
|
|
22
|
+
_height = height;
|
|
23
|
+
[self setBarCode:self.code ratio:self.ratio width:self.width height:self.height];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
- (void)setBarCode:(NSString*)code ratio:(CGFloat) ratio width:(NSInteger) width height:(NSInteger) height{
|
|
27
|
+
if (code && width > 0 && height > 0) {
|
|
28
|
+
CGSize sizeQRCode = CGSizeMake(width, height);
|
|
29
|
+
UIImage *ret = [BarCodeView generatBarCodeFromString:code size:sizeQRCode ratio:ratio];
|
|
30
|
+
[self setImage:ret];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
+(UIImage *)generatBarCodeFromString:(NSString *)string size:(CGSize)sizeCode ratio:(CGFloat)ratio {
|
|
35
|
+
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
|
|
36
|
+
CIFilter *filter = [CIFilter filterWithName:@"CICode128BarcodeGenerator"];
|
|
37
|
+
if(filter) {
|
|
38
|
+
[filter setValue:data forKey:@"inputMessage"];
|
|
39
|
+
CIImage *ciImage = [filter outputImage];
|
|
40
|
+
if(ciImage) {
|
|
41
|
+
return [self nonInterpolatedImage:ciImage ratio:ratio];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return nil;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
+(UIImage *)nonInterpolatedImage:(CIImage *)ciImage ratio:(CGFloat)ratio {
|
|
48
|
+
CGImageRef cgImage = [[CIContext context]createCGImage:ciImage fromRect:ciImage.extent];
|
|
49
|
+
CGSize size = CGSizeMake([ciImage extent].size.width * ratio, [ciImage extent].size.height * ratio);
|
|
50
|
+
if (cgImage) {
|
|
51
|
+
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size];
|
|
52
|
+
UIImage *outImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
|
|
53
|
+
CGContextRef context = rendererContext.CGContext;
|
|
54
|
+
CGContextSetInterpolationQuality(context, kCGInterpolationNone);
|
|
55
|
+
CGContextTranslateCTM(context, 0, size.height);
|
|
56
|
+
CGContextScaleCTM(context, 1.0, -1.0);
|
|
57
|
+
CGContextDrawImage(context, CGContextGetClipBoundingBox(context), cgImage);
|
|
58
|
+
}];
|
|
59
|
+
return outImage;
|
|
60
|
+
} else {
|
|
61
|
+
return [[UIImage alloc]initWithCIImage:ciImage];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@end
|
package/ios/QRCodeView.h
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
// QRCodeView.h
|
|
3
|
+
// MoMoPlatform
|
|
4
|
+
//
|
|
5
|
+
// Created by HUYNH PHI HAU on 1/8/1399 AP.
|
|
6
|
+
// Copyright © 1399 Facebook. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <UIKit/UIKit.h>
|
|
10
|
+
|
|
11
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
12
|
+
|
|
13
|
+
@interface QRCodeView : UIImageView
|
|
14
|
+
@property (nonatomic, strong) NSString *code;
|
|
15
|
+
@property (nonatomic, assign) CGFloat ratio;
|
|
16
|
+
@property (nonatomic, assign) NSInteger size;
|
|
17
|
+
@end
|
|
18
|
+
|
|
19
|
+
NS_ASSUME_NONNULL_END
|
package/ios/QRCodeView.m
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//
|
|
2
|
+
// QRCodeView.m
|
|
3
|
+
// MoMoPlatform
|
|
4
|
+
//
|
|
5
|
+
// Created by NGUYEN HOANG MINH on 08/05/2020 AP.
|
|
6
|
+
// Copyright © 1399 Facebook. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "QRCodeView.h"
|
|
10
|
+
|
|
11
|
+
@implementation QRCodeView
|
|
12
|
+
|
|
13
|
+
- (void)setCode:(NSString *)code {
|
|
14
|
+
_code = code;
|
|
15
|
+
[self setQRCode:self.code ratio:self.ratio size:self.size];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
- (void)setRatio:(CGFloat)ratio {
|
|
19
|
+
NSLog(@"[QRCodeView] setRatio: %f", ratio);
|
|
20
|
+
_ratio = ratio;
|
|
21
|
+
[self setQRCode:self.code ratio:self.ratio size:self.size];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
- (void)setSize:(NSInteger)size {
|
|
25
|
+
_size = size;
|
|
26
|
+
[self setQRCode:self.code ratio:self.ratio size:self.size];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
- (void)setQRCode:(NSString*)code ratio:(CGFloat) ratio size:(NSInteger) size {
|
|
30
|
+
if (code && size > 0) {
|
|
31
|
+
CGSize sizeQRCode = CGSizeMake(size, size);
|
|
32
|
+
UIImage *ret = [QRCodeView generateQRCodeFromString:code size:sizeQRCode];
|
|
33
|
+
[self setImage:ret];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
+(UIImage *)generateQRCodeFromString:(NSString *)string size:(CGSize)sizeCode {
|
|
38
|
+
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
|
|
39
|
+
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
|
|
40
|
+
if(filter) {
|
|
41
|
+
[filter setValue:data forKey:@"inputMessage"];
|
|
42
|
+
[filter setValue:@"H" forKey:@"inputCorrectionLevel"];
|
|
43
|
+
CIImage *ciImage = [filter outputImage];
|
|
44
|
+
if(ciImage) {
|
|
45
|
+
// MinhNH: we don't use pixel ratio here!
|
|
46
|
+
CGSize ciImageSize = [ciImage extent].size;
|
|
47
|
+
CGFloat widthRatio = sizeCode.width * [[UIScreen mainScreen]scale] / ciImageSize.width;
|
|
48
|
+
CGFloat heightRatio = sizeCode.height * [[UIScreen mainScreen]scale] / ciImageSize.height;
|
|
49
|
+
return [self nonInterpolatedImage:ciImage widthRatio:widthRatio heightRatio:heightRatio];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return nil;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
+(UIImage *)nonInterpolatedImage:(CIImage *)ciImage widthRatio:(CGFloat)dx heightRatio:(CGFloat)dy {
|
|
56
|
+
CGImageRef cgImage = [[CIContext context]createCGImage:ciImage fromRect:ciImage.extent];
|
|
57
|
+
CGSize size = CGSizeMake([ciImage extent].size.width * dx, [ciImage extent].size.height * dy);
|
|
58
|
+
if (cgImage) {
|
|
59
|
+
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size];
|
|
60
|
+
UIImage *outImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
|
|
61
|
+
CGContextRef context = rendererContext.CGContext;
|
|
62
|
+
CGContextSetInterpolationQuality(context, kCGInterpolationNone);
|
|
63
|
+
CGContextTranslateCTM(context, 0, size.height);
|
|
64
|
+
CGContextScaleCTM(context, 1.0, -1.0);
|
|
65
|
+
CGContextDrawImage(context, CGContextGetClipBoundingBox(context), cgImage);
|
|
66
|
+
}];
|
|
67
|
+
return outImage;
|
|
68
|
+
} else {
|
|
69
|
+
return [[UIImage alloc]initWithCIImage:ciImage];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@end
|
package/ios/RNBarCode.h
ADDED
package/ios/RNBarCode.mm
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// RNBarCode.mm
|
|
2
|
+
|
|
3
|
+
#import "RNBarCode.h"
|
|
4
|
+
#import <react/renderer/components/QrcodeViewSpec/ComponentDescriptors.h>
|
|
5
|
+
#import <react/renderer/components/QrcodeViewSpec/Props.h>
|
|
6
|
+
#import <react/renderer/components/QrcodeViewSpec/RCTComponentViewHelpers.h>
|
|
7
|
+
#import "BarCodeView.h"
|
|
8
|
+
|
|
9
|
+
#import "RCTFabricComponentsPlugins.h"
|
|
10
|
+
|
|
11
|
+
using namespace facebook::react;
|
|
12
|
+
|
|
13
|
+
@interface RNBarCode () <RCTRNBarCodeViewProtocol>
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
@implementation RNBarCode {
|
|
17
|
+
BarCodeView *_barcodeView;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
- (instancetype)init
|
|
21
|
+
{
|
|
22
|
+
if (self = [super init]) {
|
|
23
|
+
_barcodeView = [BarCodeView new];
|
|
24
|
+
[self addSubview:_barcodeView];
|
|
25
|
+
}
|
|
26
|
+
return self;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
- (void)updateProps:(Props::Shared const &)props
|
|
30
|
+
oldProps:(Props::Shared const &)oldProps
|
|
31
|
+
{
|
|
32
|
+
const auto &barProps =
|
|
33
|
+
*std::static_pointer_cast<RNBarCodeProps const>(props);
|
|
34
|
+
|
|
35
|
+
// string → NSString*
|
|
36
|
+
if (!barProps.code.empty()) {
|
|
37
|
+
NSString *nsCode = [NSString stringWithUTF8String:barProps.code.c_str()];
|
|
38
|
+
_barcodeView.code = nsCode;
|
|
39
|
+
}
|
|
40
|
+
_barcodeView.ratio = barProps.ratio;
|
|
41
|
+
_barcodeView.width = barProps.width;
|
|
42
|
+
_barcodeView.height = barProps.height;
|
|
43
|
+
|
|
44
|
+
[super updateProps:props oldProps:oldProps];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
- (void)layoutSubviews
|
|
48
|
+
{
|
|
49
|
+
[super layoutSubviews];
|
|
50
|
+
_barcodeView.frame = self.bounds;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
54
|
+
{
|
|
55
|
+
return concreteComponentDescriptorProvider<RNBarCodeComponentDescriptor>();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@end
|
|
59
|
+
|
|
60
|
+
Class<RCTRNBarCodeViewProtocol> RCTBarCodeCls(void)
|
|
61
|
+
{
|
|
62
|
+
return RNBarCode.class;
|
|
63
|
+
}
|