@momo-kits/qrcode 0.150.2-beta.10 → 0.150.2-beta.11
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/android/src/main/java/com/momokits/qrcode/RCTQRCodeView.kt +15 -7
- package/android/src/main/java/com/momokits/qrcode/RCTQRCodeViewManager.kt +0 -5
- package/ios/RCTQRCodeView.h +2 -1
- package/ios/RCTQRCodeView.mm +50 -9
- package/ios/RCTQRCodeViewManager.mm +2 -8
- package/lib/module/RCTQRCodeViewNativeComponent.ts +0 -1
- package/lib/typescript/src/RCTQRCodeViewNativeComponent.d.ts +0 -1
- package/lib/typescript/src/RCTQRCodeViewNativeComponent.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/RCTQRCodeViewNativeComponent.ts +0 -1
|
@@ -12,7 +12,6 @@ import java.util.*
|
|
|
12
12
|
|
|
13
13
|
class RCTQRCodeView : ImageView {
|
|
14
14
|
private var qrValue: String? = null
|
|
15
|
-
private var qrSize: Int = 200
|
|
16
15
|
private var qrColor: Int = Color.BLACK
|
|
17
16
|
private var qrBackgroundColor: Int = Color.WHITE
|
|
18
17
|
|
|
@@ -36,13 +35,15 @@ class RCTQRCodeView : ImageView {
|
|
|
36
35
|
scaleType = ScaleType.FIT_CENTER
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
fun
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
|
39
|
+
super.onSizeChanged(w, h, oldw, oldh)
|
|
40
|
+
if (w > 0 && h > 0) {
|
|
41
|
+
generateQRCode()
|
|
42
|
+
}
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
fun
|
|
45
|
-
|
|
45
|
+
fun setValue(value: String?) {
|
|
46
|
+
qrValue = value
|
|
46
47
|
generateQRCode()
|
|
47
48
|
}
|
|
48
49
|
|
|
@@ -62,13 +63,20 @@ class RCTQRCodeView : ImageView {
|
|
|
62
63
|
return
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
// Use view dimensions, with fallback to default size
|
|
67
|
+
val size = if (width > 0 && height > 0) {
|
|
68
|
+
minOf(width, height)
|
|
69
|
+
} else {
|
|
70
|
+
200 // Default size
|
|
71
|
+
}
|
|
72
|
+
|
|
65
73
|
try {
|
|
66
74
|
val writer = QRCodeWriter()
|
|
67
75
|
val hints = EnumMap<EncodeHintType, Any>(EncodeHintType::class.java)
|
|
68
76
|
hints[EncodeHintType.CHARACTER_SET] = "UTF-8"
|
|
69
77
|
hints[EncodeHintType.MARGIN] = 1
|
|
70
78
|
|
|
71
|
-
val bitMatrix = writer.encode(qrValue, BarcodeFormat.QR_CODE,
|
|
79
|
+
val bitMatrix = writer.encode(qrValue, BarcodeFormat.QR_CODE, size, size, hints)
|
|
72
80
|
val width = bitMatrix.width
|
|
73
81
|
val height = bitMatrix.height
|
|
74
82
|
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565)
|
|
@@ -22,11 +22,6 @@ class RCTQRCodeViewManager : SimpleViewManager<RCTQRCodeView>() {
|
|
|
22
22
|
view.setValue(value)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
@ReactProp(name = "size", defaultFloat = 200f)
|
|
26
|
-
fun setSize(view: RCTQRCodeView, size: Float) {
|
|
27
|
-
view.setSize(size.toInt())
|
|
28
|
-
}
|
|
29
|
-
|
|
30
25
|
@ReactProp(name = "color")
|
|
31
26
|
fun setColor(view: RCTQRCodeView, color: String?) {
|
|
32
27
|
color?.let {
|
package/ios/RCTQRCodeView.h
CHANGED
|
@@ -9,7 +9,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
9
9
|
@interface RCTQRCodeView : RCTViewComponentView
|
|
10
10
|
|
|
11
11
|
- (void)setValue:(NSString *)value;
|
|
12
|
-
- (void)
|
|
12
|
+
- (void)setColor:(NSString *)color;
|
|
13
|
+
- (void)setBackgroundColor:(NSString *)backgroundColor;
|
|
13
14
|
|
|
14
15
|
@end
|
|
15
16
|
|
package/ios/RCTQRCodeView.mm
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
@implementation RCTQRCodeView {
|
|
6
6
|
UIImageView *_qrImageView;
|
|
7
7
|
NSString *_value;
|
|
8
|
-
|
|
8
|
+
UIColor *_qrColor;
|
|
9
|
+
UIColor *_qrBackgroundColor;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
@@ -13,9 +14,11 @@
|
|
|
13
14
|
if (self = [super initWithFrame:frame]) {
|
|
14
15
|
_qrImageView = [[UIImageView alloc] init];
|
|
15
16
|
_qrImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
16
|
-
_qrImageView.backgroundColor = [UIColor whiteColor];
|
|
17
17
|
[self addSubview:_qrImageView];
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
// Default colors
|
|
20
|
+
_qrColor = [UIColor blackColor];
|
|
21
|
+
_qrBackgroundColor = [UIColor whiteColor];
|
|
19
22
|
}
|
|
20
23
|
return self;
|
|
21
24
|
}
|
|
@@ -51,14 +54,39 @@
|
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
- (void)
|
|
57
|
+
- (void)setColor:(NSString *)color
|
|
58
|
+
{
|
|
59
|
+
if (color) {
|
|
60
|
+
_qrColor = [self colorFromHexString:color] ?: [UIColor blackColor];
|
|
61
|
+
[self generateQRCode];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
- (void)setBackgroundColor:(NSString *)backgroundColor
|
|
55
66
|
{
|
|
56
|
-
if (
|
|
57
|
-
|
|
67
|
+
if (backgroundColor) {
|
|
68
|
+
_qrBackgroundColor = [self colorFromHexString:backgroundColor] ?: [UIColor whiteColor];
|
|
58
69
|
[self generateQRCode];
|
|
59
70
|
}
|
|
60
71
|
}
|
|
61
72
|
|
|
73
|
+
- (UIColor *)colorFromHexString:(NSString *)hexString
|
|
74
|
+
{
|
|
75
|
+
if (!hexString) return nil;
|
|
76
|
+
|
|
77
|
+
NSString *cleanString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""];
|
|
78
|
+
if ([cleanString length] != 6) return nil;
|
|
79
|
+
|
|
80
|
+
NSScanner *scanner = [NSScanner scannerWithString:cleanString];
|
|
81
|
+
unsigned hexValue = 0;
|
|
82
|
+
if (![scanner scanHexInt:&hexValue]) return nil;
|
|
83
|
+
|
|
84
|
+
return [UIColor colorWithRed:((hexValue & 0xFF0000) >> 16) / 255.0
|
|
85
|
+
green:((hexValue & 0xFF00) >> 8) / 255.0
|
|
86
|
+
blue:(hexValue & 0xFF) / 255.0
|
|
87
|
+
alpha:1.0];
|
|
88
|
+
}
|
|
89
|
+
|
|
62
90
|
- (void)generateQRCode
|
|
63
91
|
{
|
|
64
92
|
if (!_value || _value.length == 0) {
|
|
@@ -78,8 +106,13 @@
|
|
|
78
106
|
return;
|
|
79
107
|
}
|
|
80
108
|
|
|
81
|
-
//
|
|
82
|
-
CGFloat
|
|
109
|
+
// Use the view's bounds for sizing, with a minimum scale
|
|
110
|
+
CGFloat viewSize = MIN(self.bounds.size.width, self.bounds.size.height);
|
|
111
|
+
if (viewSize == 0) {
|
|
112
|
+
viewSize = 200.0; // Default size
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
CGFloat scale = viewSize / qrImage.extent.size.width;
|
|
83
116
|
|
|
84
117
|
CIFilter *scaleFilter = [CIFilter filterWithName:@"CILanczosScaleTransform"];
|
|
85
118
|
[scaleFilter setValue:qrImage forKey:@"inputImage"];
|
|
@@ -88,8 +121,16 @@
|
|
|
88
121
|
|
|
89
122
|
CIImage *scaledImage = scaleFilter.outputImage;
|
|
90
123
|
|
|
124
|
+
// Apply colors using CIFilter
|
|
125
|
+
CIFilter *colorFilter = [CIFilter filterWithName:@"CIFalseColor"];
|
|
126
|
+
[colorFilter setValue:scaledImage forKey:@"inputImage"];
|
|
127
|
+
[colorFilter setValue:[CIColor colorWithCGColor:_qrColor.CGColor] forKey:@"inputColor0"];
|
|
128
|
+
[colorFilter setValue:[CIColor colorWithCGColor:_qrBackgroundColor.CGColor] forKey:@"inputColor1"];
|
|
129
|
+
|
|
130
|
+
CIImage *coloredImage = colorFilter.outputImage;
|
|
131
|
+
|
|
91
132
|
CIContext *context = [CIContext context];
|
|
92
|
-
CGImageRef cgImage = [context createCGImage:
|
|
133
|
+
CGImageRef cgImage = [context createCGImage:coloredImage fromRect:coloredImage.extent];
|
|
93
134
|
UIImage *qrCodeImage = [UIImage imageWithCGImage:cgImage];
|
|
94
135
|
CGImageRelease(cgImage);
|
|
95
136
|
|
|
@@ -15,13 +15,7 @@ RCT_EXPORT_MODULE(RCTQRCodeView)
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
RCT_EXPORT_VIEW_PROPERTY(value, NSString)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (json) {
|
|
21
|
-
[view setQrSize:[RCTConvert CGFloat:json]];
|
|
22
|
-
} else {
|
|
23
|
-
[view setQrSize:200.0];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
18
|
+
RCT_EXPORT_VIEW_PROPERTY(color, NSString)
|
|
19
|
+
RCT_EXPORT_VIEW_PROPERTY(backgroundColor, NSString)
|
|
26
20
|
|
|
27
21
|
@end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RCTQRCodeViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/RCTQRCodeViewNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,
|
|
1
|
+
{"version":3,"file":"RCTQRCodeViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/RCTQRCodeViewNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;;AAED,wBAAoE"}
|
package/package.json
CHANGED