File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
composeqrcode/src/main/java/com/lightspark/composeqr Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ fun QrCodeView(
36
36
modifier : Modifier = Modifier ,
37
37
colors : QrCodeColors = QrCodeColors .default(),
38
38
dotShape : DotShape = DotShape .Square ,
39
- encoder : QrEncoder = QrEncoder (),
39
+ encoder : QrEncoder = ZxingQrEncoder (),
40
40
overlayContent : (@Composable () -> Unit )? = null,
41
41
) {
42
42
Box (modifier = modifier, contentAlignment = Alignment .Center ) {
@@ -70,9 +70,9 @@ fun QrCodeView(
70
70
modifier : Modifier = Modifier ,
71
71
colors : QrCodeColors = QrCodeColors .default(),
72
72
dotShape : DotShape = DotShape .Square ,
73
- encoder : QrEncoder = QrEncoder ()
73
+ encoder : QrEncoder = ZxingQrEncoder ()
74
74
) {
75
- val encodedData = remember(data, encoder) { encoder(data) }
75
+ val encodedData = remember(data, encoder) { encoder.encode (data) }
76
76
77
77
Canvas (modifier = modifier.background(colors.background)) {
78
78
encodedData?.let { matrix ->
Original file line number Diff line number Diff line change @@ -6,10 +6,18 @@ import com.google.zxing.qrcode.encoder.ByteMatrix
6
6
import com.google.zxing.qrcode.encoder.Encoder
7
7
8
8
/* *
9
- * Encodes a string into a QR code ByteMatrix. This is just a small wrapper around the ZXing library with sane defaults.
9
+ * Encodes a string into a QR code ByteMatrix. The default implementation, `ZxingQrEncoder` just
10
+ * wraps the ZXing library with sane defaults.
10
11
*/
11
- class QrEncoder {
12
- operator fun invoke (qrData : String ): ByteMatrix ? {
12
+ interface QrEncoder {
13
+ fun encode (qrData : String ): ByteMatrix ?
14
+ }
15
+
16
+ /* *
17
+ * This is just a small wrapper around the ZXing library with sane defaults.
18
+ */
19
+ class ZxingQrEncoder : QrEncoder {
20
+ override fun encode (qrData : String ): ByteMatrix ? {
13
21
return Encoder .encode(
14
22
qrData,
15
23
ErrorCorrectionLevel .H ,
You can’t perform that action at this time.
0 commit comments