@momo-kits/qrcode 0.150.2-beta.10 → 0.150.2-beta.12

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.
Files changed (52) hide show
  1. package/LICENSE +1 -1
  2. package/Qrcode.podspec +43 -0
  3. package/README.md +4 -8
  4. package/android/build.gradle +10 -3
  5. package/android/gradle.properties +8 -5
  6. package/android/src/main/java/com/momokits/qrcode/MomoBarCodeViewManager.kt +111 -0
  7. package/android/src/main/java/com/momokits/qrcode/MomoQrCodeUtils.kt +23 -0
  8. package/android/src/main/java/com/momokits/qrcode/MomoQrCodeViewManager.kt +96 -0
  9. package/android/src/main/java/com/momokits/qrcode/{RCTQRCodePackage.kt → MomoQrCodeViewPackage.kt} +9 -10
  10. package/ios/BarCodeView.h +20 -0
  11. package/ios/BarCodeView.m +65 -0
  12. package/ios/QRCodeView.h +19 -0
  13. package/ios/QRCodeView.m +74 -0
  14. package/ios/RNBarCode.h +11 -0
  15. package/ios/RNBarCode.mm +63 -0
  16. package/ios/RNQRCode.h +10 -0
  17. package/ios/RNQRCode.mm +66 -0
  18. package/lib/module/BarCodeView.js +16 -0
  19. package/lib/module/BarCodeView.js.map +1 -0
  20. package/lib/module/QRCodeView.js +42 -0
  21. package/lib/module/QRCodeView.js.map +1 -0
  22. package/lib/module/RNBarCodeNativeComponent.ts +15 -0
  23. package/lib/module/RNQRCodeNativeComponent.ts +10 -0
  24. package/lib/module/index.js +5 -2
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/typescript/src/BarCodeView.d.ts +10 -0
  27. package/lib/typescript/src/BarCodeView.d.ts.map +1 -0
  28. package/lib/typescript/src/QRCodeView.d.ts +14 -0
  29. package/lib/typescript/src/QRCodeView.d.ts.map +1 -0
  30. package/lib/typescript/src/RNBarCodeNativeComponent.d.ts +15 -0
  31. package/lib/typescript/src/RNBarCodeNativeComponent.d.ts.map +1 -0
  32. package/lib/typescript/src/RNQRCodeNativeComponent.d.ts +10 -0
  33. package/lib/typescript/src/RNQRCodeNativeComponent.d.ts.map +1 -0
  34. package/lib/typescript/src/index.d.ts +5 -2
  35. package/lib/typescript/src/index.d.ts.map +1 -1
  36. package/package.json +160 -159
  37. package/src/BarCodeView.tsx +15 -0
  38. package/src/QRCodeView.tsx +63 -0
  39. package/src/RNBarCodeNativeComponent.ts +15 -0
  40. package/src/RNQRCodeNativeComponent.ts +10 -0
  41. package/src/index.tsx +6 -2
  42. package/RCTQRCode.podspec +0 -21
  43. package/android/src/main/java/com/momokits/qrcode/RCTQRCodeView.kt +0 -91
  44. package/android/src/main/java/com/momokits/qrcode/RCTQRCodeViewManager.kt +0 -57
  45. package/ios/RCTQRCodeComponentView.mm +0 -11
  46. package/ios/RCTQRCodeView.h +0 -18
  47. package/ios/RCTQRCodeView.mm +0 -101
  48. package/ios/RCTQRCodeViewManager.mm +0 -27
  49. package/lib/module/RCTQRCodeViewNativeComponent.ts +0 -11
  50. package/lib/typescript/src/RCTQRCodeViewNativeComponent.d.ts +0 -11
  51. package/lib/typescript/src/RCTQRCodeViewNativeComponent.d.ts.map +0 -1
  52. package/src/RCTQRCodeViewNativeComponent.ts +0 -11
@@ -0,0 +1,63 @@
1
+ import { Image, PixelRatio } from 'react-native';
2
+ import RNQRCode from './RNQRCodeNativeComponent';
3
+ import type { CodegenTypes } from 'react-native';
4
+
5
+ const ratio = PixelRatio.get();
6
+ const ic_logo =
7
+ 'https://img.mservice.io/momo_app_v2/new_version/img/appx_image/ic_momo.png';
8
+
9
+ type QRCodeViewProps = {
10
+ code: string;
11
+ size: CodegenTypes.Int32;
12
+ ratio?: CodegenTypes.Float;
13
+ icon?: string;
14
+ showLogo?: boolean;
15
+ iconSize?: CodegenTypes.Int32;
16
+ iconStyle?: any;
17
+ style?: any;
18
+ };
19
+
20
+ const QRCodeView = ({
21
+ code,
22
+ showLogo = false,
23
+ ratio: customRatio,
24
+ icon = ic_logo,
25
+ iconSize = 32,
26
+ size,
27
+ iconStyle,
28
+ style,
29
+ ...rest
30
+ }: QRCodeViewProps) => {
31
+ return (
32
+ <>
33
+ <RNQRCode
34
+ code={code}
35
+ ratio={customRatio ?? ratio}
36
+ size={size}
37
+ {...rest}
38
+ style={[
39
+ {
40
+ width: size,
41
+ height: size,
42
+ },
43
+ style,
44
+ ]}
45
+ />
46
+ {showLogo ? (
47
+ <Image
48
+ source={{ uri: icon }}
49
+ style={[
50
+ {
51
+ width: iconSize,
52
+ height: iconSize,
53
+ position: 'absolute',
54
+ },
55
+ iconStyle,
56
+ ]}
57
+ />
58
+ ) : null}
59
+ </>
60
+ );
61
+ };
62
+
63
+ export default QRCodeView;
@@ -0,0 +1,15 @@
1
+ import type { ViewProps } from 'react-native';
2
+ import { codegenNativeComponent, CodegenTypes } from 'react-native';
3
+
4
+ export interface BarCodeNativeComponentProps extends ViewProps {
5
+ /** the data string to encode */
6
+ code?: string;
7
+ /** scale-factor for the raw CIImage */
8
+ ratio?: CodegenTypes.Float;
9
+ /** pixel width of the final barcode */
10
+ width?: CodegenTypes.Int32;
11
+ /** pixel height of the final barcode */
12
+ height?: CodegenTypes.Int32;
13
+ }
14
+
15
+ export default codegenNativeComponent<BarCodeNativeComponentProps>('RNBarCode');
@@ -0,0 +1,10 @@
1
+ import type { ViewProps } from 'react-native';
2
+ import { codegenNativeComponent, CodegenTypes } from 'react-native';
3
+
4
+ export interface QRCodeNativeComponentProps extends ViewProps {
5
+ code?: string;
6
+ ratio?: CodegenTypes.Float;
7
+ size?: CodegenTypes.Int32;
8
+ }
9
+
10
+ export default codegenNativeComponent<QRCodeNativeComponentProps>('RNQRCode');
package/src/index.tsx CHANGED
@@ -1,2 +1,6 @@
1
- export { default as RCTQRCodeView } from './RCTQRCodeViewNativeComponent';
2
- export * from './RCTQRCodeViewNativeComponent';
1
+ import RNQRCode from './RNQRCodeNativeComponent';
2
+ import RNBarCode from './RNBarCodeNativeComponent';
3
+ import BarCodeView from './BarCodeView';
4
+ import QRCodeView from './QRCodeView';
5
+
6
+ export { BarCodeView, QRCodeView, RNQRCode, RNBarCode };
package/RCTQRCode.podspec DELETED
@@ -1,21 +0,0 @@
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 = "RCTQRCode"
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://momo-kits.github.io.git", :tag => "#{s.version}" }
15
-
16
- s.source_files = "ios/**/*.{h,m,mm,cpp}"
17
- s.private_header_files = "ios/**/*.h"
18
-
19
-
20
- install_modules_dependencies(s)
21
- end
@@ -1,91 +0,0 @@
1
- package com.momokits.qrcode
2
-
3
- import android.content.Context
4
- import android.graphics.*
5
- import android.util.AttributeSet
6
- import android.widget.ImageView
7
- import com.google.zxing.BarcodeFormat
8
- import com.google.zxing.EncodeHintType
9
- import com.google.zxing.WriterException
10
- import com.google.zxing.qrcode.QRCodeWriter
11
- import java.util.*
12
-
13
- class RCTQRCodeView : ImageView {
14
- private var qrValue: String? = null
15
- private var qrSize: Int = 200
16
- private var qrColor: Int = Color.BLACK
17
- private var qrBackgroundColor: Int = Color.WHITE
18
-
19
- constructor(context: Context?) : super(context) {
20
- init()
21
- }
22
-
23
- constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
24
- init()
25
- }
26
-
27
- constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
28
- context,
29
- attrs,
30
- defStyleAttr
31
- ) {
32
- init()
33
- }
34
-
35
- private fun init() {
36
- scaleType = ScaleType.FIT_CENTER
37
- }
38
-
39
- fun setValue(value: String?) {
40
- qrValue = value
41
- generateQRCode()
42
- }
43
-
44
- fun setSize(size: Int) {
45
- qrSize = size
46
- generateQRCode()
47
- }
48
-
49
- fun setQRColor(color: Int) {
50
- qrColor = color
51
- generateQRCode()
52
- }
53
-
54
- fun setQRBackgroundColor(color: Int) {
55
- qrBackgroundColor = color
56
- generateQRCode()
57
- }
58
-
59
- private fun generateQRCode() {
60
- if (qrValue.isNullOrEmpty()) {
61
- setImageBitmap(null)
62
- return
63
- }
64
-
65
- try {
66
- val writer = QRCodeWriter()
67
- val hints = EnumMap<EncodeHintType, Any>(EncodeHintType::class.java)
68
- hints[EncodeHintType.CHARACTER_SET] = "UTF-8"
69
- hints[EncodeHintType.MARGIN] = 1
70
-
71
- val bitMatrix = writer.encode(qrValue, BarcodeFormat.QR_CODE, qrSize, qrSize, hints)
72
- val width = bitMatrix.width
73
- val height = bitMatrix.height
74
- val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565)
75
-
76
- for (x in 0 until width) {
77
- for (y in 0 until height) {
78
- bitmap.setPixel(x, y, if (bitMatrix[x, y]) qrColor else qrBackgroundColor)
79
- }
80
- }
81
-
82
- post {
83
- setImageBitmap(bitmap)
84
- }
85
-
86
- } catch (e: WriterException) {
87
- e.printStackTrace()
88
- setImageBitmap(null)
89
- }
90
- }
91
- }
@@ -1,57 +0,0 @@
1
- package com.momokits.qrcode
2
-
3
- import android.graphics.Color
4
- import com.facebook.react.module.annotations.ReactModule
5
- import com.facebook.react.uimanager.SimpleViewManager
6
- import com.facebook.react.uimanager.ThemedReactContext
7
- import com.facebook.react.uimanager.annotations.ReactProp
8
-
9
- @ReactModule(name = RCTQRCodeViewManager.NAME)
10
- class RCTQRCodeViewManager : SimpleViewManager<RCTQRCodeView>() {
11
-
12
- override fun getName(): String {
13
- return NAME
14
- }
15
-
16
- public override fun createViewInstance(context: ThemedReactContext): RCTQRCodeView {
17
- return RCTQRCodeView(context)
18
- }
19
-
20
- @ReactProp(name = "value")
21
- fun setValue(view: RCTQRCodeView, value: String?) {
22
- view.setValue(value)
23
- }
24
-
25
- @ReactProp(name = "size", defaultFloat = 200f)
26
- fun setSize(view: RCTQRCodeView, size: Float) {
27
- view.setSize(size.toInt())
28
- }
29
-
30
- @ReactProp(name = "color")
31
- fun setColor(view: RCTQRCodeView, color: String?) {
32
- color?.let {
33
- try {
34
- view.setQRColor(Color.parseColor(it))
35
- } catch (e: IllegalArgumentException) {
36
- // Invalid color format, use default
37
- view.setQRColor(Color.BLACK)
38
- }
39
- }
40
- }
41
-
42
- @ReactProp(name = "backgroundColor")
43
- fun setBackgroundColor(view: RCTQRCodeView, backgroundColor: String?) {
44
- backgroundColor?.let {
45
- try {
46
- view.setQRBackgroundColor(Color.parseColor(it))
47
- } catch (e: IllegalArgumentException) {
48
- // Invalid color format, use default
49
- view.setQRBackgroundColor(Color.WHITE)
50
- }
51
- }
52
- }
53
-
54
- companion object {
55
- const val NAME = "RCTQRCodeView"
56
- }
57
- }
@@ -1,11 +0,0 @@
1
- #import <React/RCTComponentViewFactory.h>
2
- #import "RCTQRCodeView.h"
3
-
4
- @implementation RCTComponentViewFactory (RCTQRCodeView)
5
-
6
- + (void)load
7
- {
8
- [RCTComponentViewFactory registerComponentViewClass:[RCTQRCodeView class]];
9
- }
10
-
11
- @end
@@ -1,18 +0,0 @@
1
- #import <React/RCTViewComponentView.h>
2
- #import <UIKit/UIKit.h>
3
-
4
- #ifndef RCTQRCodeView_h
5
- #define RCTQRCodeView_h
6
-
7
- NS_ASSUME_NONNULL_BEGIN
8
-
9
- @interface RCTQRCodeView : RCTViewComponentView
10
-
11
- - (void)setValue:(NSString *)value;
12
- - (void)setQrSize:(CGFloat)size;
13
-
14
- @end
15
-
16
- NS_ASSUME_NONNULL_END
17
-
18
- #endif /* RCTQRCodeView_h */
@@ -1,101 +0,0 @@
1
- #import "RCTQRCodeView.h"
2
- #import <React/RCTConversions.h>
3
- #import <CoreImage/CoreImage.h>
4
-
5
- @implementation RCTQRCodeView {
6
- UIImageView *_qrImageView;
7
- NSString *_value;
8
- CGFloat _size;
9
- }
10
-
11
- - (instancetype)initWithFrame:(CGRect)frame
12
- {
13
- if (self = [super initWithFrame:frame]) {
14
- _qrImageView = [[UIImageView alloc] init];
15
- _qrImageView.contentMode = UIViewContentModeScaleAspectFit;
16
- _qrImageView.backgroundColor = [UIColor whiteColor];
17
- [self addSubview:_qrImageView];
18
- _size = 200.0; // Default size
19
- }
20
- return self;
21
- }
22
-
23
- - (void)layoutSubviews
24
- {
25
- [super layoutSubviews];
26
- _qrImageView.frame = self.bounds;
27
- }
28
-
29
- // Override the updateProps method to handle props without generated specs
30
- - (void)updateProps:(facebook::react::Props::Shared const &)props oldProps:(facebook::react::Props::Shared const &)oldProps
31
- {
32
- [super updateProps:props oldProps:oldProps];
33
-
34
- // Since we don't have generated props, we'll handle them through the bridge
35
- // The actual prop handling will be done via the view manager
36
- }
37
-
38
- - (void)prepareForRecycle
39
- {
40
- [super prepareForRecycle];
41
- _qrImageView.image = nil;
42
- _value = nil;
43
- }
44
-
45
- // Public methods for setting props
46
- - (void)setValue:(NSString *)value
47
- {
48
- if (![_value isEqualToString:value]) {
49
- _value = value;
50
- [self generateQRCode];
51
- }
52
- }
53
-
54
- - (void)setQrSize:(CGFloat)size
55
- {
56
- if (_size != size) {
57
- _size = size;
58
- [self generateQRCode];
59
- }
60
- }
61
-
62
- - (void)generateQRCode
63
- {
64
- if (!_value || _value.length == 0) {
65
- _qrImageView.image = nil;
66
- return;
67
- }
68
-
69
- NSData *stringData = [_value dataUsingEncoding:NSUTF8StringEncoding];
70
-
71
- CIFilter *qrFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
72
- [qrFilter setValue:stringData forKey:@"inputMessage"];
73
- [qrFilter setValue:@"M" forKey:@"inputCorrectionLevel"];
74
-
75
- CIImage *qrImage = qrFilter.outputImage;
76
-
77
- if (!qrImage) {
78
- return;
79
- }
80
-
81
- // Calculate scale based on desired size
82
- CGFloat scale = _size / qrImage.extent.size.width;
83
-
84
- CIFilter *scaleFilter = [CIFilter filterWithName:@"CILanczosScaleTransform"];
85
- [scaleFilter setValue:qrImage forKey:@"inputImage"];
86
- [scaleFilter setValue:@(scale) forKey:@"inputScale"];
87
- [scaleFilter setValue:@1.0 forKey:@"inputAspectRatio"];
88
-
89
- CIImage *scaledImage = scaleFilter.outputImage;
90
-
91
- CIContext *context = [CIContext context];
92
- CGImageRef cgImage = [context createCGImage:scaledImage fromRect:scaledImage.extent];
93
- UIImage *qrCodeImage = [UIImage imageWithCGImage:cgImage];
94
- CGImageRelease(cgImage);
95
-
96
- dispatch_async(dispatch_get_main_queue(), ^{
97
- self->_qrImageView.image = qrCodeImage;
98
- });
99
- }
100
-
101
- @end
@@ -1,27 +0,0 @@
1
- #import <React/RCTViewManager.h>
2
- #import <React/RCTUIManager.h>
3
- #import "RCTQRCodeView.h"
4
-
5
- @interface RCTQRCodeViewManager : RCTViewManager
6
- @end
7
-
8
- @implementation RCTQRCodeViewManager
9
-
10
- RCT_EXPORT_MODULE(RCTQRCodeView)
11
-
12
- - (UIView *)view
13
- {
14
- return [[RCTQRCodeView alloc] init];
15
- }
16
-
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
- }
26
-
27
- @end
@@ -1,11 +0,0 @@
1
- import { codegenNativeComponent, type ViewProps } from 'react-native';
2
- import type { ColorValue } from 'react-native';
3
-
4
- export interface NativeProps extends ViewProps {
5
- value?: string;
6
- size?: number;
7
- backgroundColor?: ColorValue;
8
- color?: ColorValue;
9
- }
10
-
11
- export default codegenNativeComponent<NativeProps>('RCTQRCodeView');
@@ -1,11 +0,0 @@
1
- import { type ViewProps } from 'react-native';
2
- import type { ColorValue } from 'react-native';
3
- export interface NativeProps extends ViewProps {
4
- value?: string;
5
- size?: number;
6
- backgroundColor?: ColorValue;
7
- color?: ColorValue;
8
- }
9
- declare const _default: import("react-native/types_generated/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
10
- export default _default;
11
- //# sourceMappingURL=RCTQRCodeViewNativeComponent.d.ts.map
@@ -1 +0,0 @@
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,11 +0,0 @@
1
- import { codegenNativeComponent, type ViewProps } from 'react-native';
2
- import type { ColorValue } from 'react-native';
3
-
4
- export interface NativeProps extends ViewProps {
5
- value?: string;
6
- size?: number;
7
- backgroundColor?: ColorValue;
8
- color?: ColorValue;
9
- }
10
-
11
- export default codegenNativeComponent<NativeProps>('RCTQRCodeView');