QR code design library for Compose Multiplatform
![Screenshot 2023-10-10 at 10 34 05](https://private-user-images.githubusercontent.com/63979218/275222922-7469cc1c-d6fd-4dab-997d-f2604dfa49de.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MzcxNzIsIm5iZiI6MTczOTUzNjg3MiwicGF0aCI6Ii82Mzk3OTIxOC8yNzUyMjI5MjItNzQ2OWNjMWMtZDZmZC00ZGFiLTk5N2QtZjI2MDRkZmE0OWRlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDEyNDExMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWI0NmYzMmEwOGEzNTY3ZThmOGE1ODhmZDJhYjg2ZDExYzcyMzA3YjI4MDk1ZDZmYzI0NDA0ZWMwN2U0ZGI1M2YmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.lv8dwuZk36WujNzM8j4ElDYs23zV_qV3-asoxF7dEZQ)
Why QRose?
- Lightweight - doesn't contain any dependencies except of
compose.ui
; - Flexible - high customization ability that is open for extension;
- Efficient - declare and render codes synchronously right from the composition in 60+ fps;
- Scalable - no raster bitmaps, only scalable vector graphics;
- Multiplatform - supports all the targets supported by Compose Multiplatform.
dependencies {
implementation("io.github.alexzhirkevich:qrose:1.0.0-beta3")
}
You can create code right in composition using rememberQrCodePainter
.
Or do it outside of Compose scope by instantiating a QrCodePainter
class.
Image(
painter = rememberQrCodePainter("https://example.com"),
contentDescription = "QR code"
)
There are some overloads of rememberQrCodePainter
including DSL constructor:
val logoPainter : Painter = painterResource("logo.png")
val qrcodePainter : Painter = rememberQrCodePainter("https://example.com") {
logo {
painter = logoPainter
padding = QrLogoPadding.Natural(.1f)
shape = QrLogoShape.circle()
size = 0.2f
}
shapes {
ball = QrBallShape.circle()
darkPixel = QrPixelShape.roundCorners()
frame = QrFrameShape.roundCorners(.25f)
}
colors {
dark = QrBrush.brush {
Brush.linearGradient(
0f to Color.Red,
1f to Color.Blue,
end = Offset(it, it)
)
}
frame = QrBrush.solid(Color.Black)
}
}
Or just parametrized constructor:
val qrcodePainter = rememberQrCodePainter(
data = "https://example.com",
shapes = QrShapes(
darkPixel = QrPixelShape.roundCorners()
)
)
You can create your own shapes for each QR code part, for example:
class MyCircleBallShape : QrBallShape {
override fun Path.path(size: Float, neighbors: Neighbors): Path = apply {
addOval(Rect(0f,0f, size, size))
}
}
Note A path here uses
PathFillType.EvenOdd
that cannot be changed.
QR codes can hold various payload types: Text, Wi-Fi, E-mail, vCard, etc.
QrData
object can be used to perform such encodings, for example:
val wifiData : String = QrData.wifi(ssid = "My Network", psk = "12345678")
val wifiCode = rememberQrCodePainter(wifiData)
QR codes can be exported to PNG
, JPEG
and WEBP
formats using toByteArray
function:
val painter : Painter = QrCodePainter(
data = "https://example.com",
options = QrOptions {
colors {
//...
}
}
)
val bytes : ByteArray = painter.toByteArray(1024, 1024, ImageFormat.PNG)