@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.
@@ -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 setValue(value: String?) {
40
- qrValue = value
41
- generateQRCode()
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 setSize(size: Int) {
45
- qrSize = size
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, qrSize, qrSize, hints)
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 {
@@ -9,7 +9,8 @@ NS_ASSUME_NONNULL_BEGIN
9
9
  @interface RCTQRCodeView : RCTViewComponentView
10
10
 
11
11
  - (void)setValue:(NSString *)value;
12
- - (void)setQrSize:(CGFloat)size;
12
+ - (void)setColor:(NSString *)color;
13
+ - (void)setBackgroundColor:(NSString *)backgroundColor;
13
14
 
14
15
  @end
15
16
 
@@ -5,7 +5,8 @@
5
5
  @implementation RCTQRCodeView {
6
6
  UIImageView *_qrImageView;
7
7
  NSString *_value;
8
- CGFloat _size;
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
- _size = 200.0; // Default size
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)setQrSize:(CGFloat)size
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 (_size != size) {
57
- _size = size;
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
- // Calculate scale based on desired size
82
- CGFloat scale = _size / qrImage.extent.size.width;
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:scaledImage fromRect:scaledImage.extent];
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
- RCT_CUSTOM_VIEW_PROPERTY(size, NSNumber, RCTQRCodeView)
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
@@ -3,7 +3,6 @@ import type { ColorValue } from 'react-native';
3
3
 
4
4
  export interface NativeProps extends ViewProps {
5
5
  value?: string;
6
- size?: number;
7
6
  backgroundColor?: ColorValue;
8
7
  color?: ColorValue;
9
8
  }
@@ -2,7 +2,6 @@ import { type ViewProps } from 'react-native';
2
2
  import type { ColorValue } from 'react-native';
3
3
  export interface NativeProps extends ViewProps {
4
4
  value?: string;
5
- size?: number;
6
5
  backgroundColor?: ColorValue;
7
6
  color?: ColorValue;
8
7
  }
@@ -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,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;;AAED,wBAAoE"}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/qrcode",
3
- "version": "0.150.2-beta.10",
3
+ "version": "0.150.2-beta.11",
4
4
  "description": "RCTQRCode & RCTBarCode",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -3,7 +3,6 @@ import type { ColorValue } from 'react-native';
3
3
 
4
4
  export interface NativeProps extends ViewProps {
5
5
  value?: string;
6
- size?: number;
7
6
  backgroundColor?: ColorValue;
8
7
  color?: ColorValue;
9
8
  }