@hoangnh0099/react-native-sunmi-printer 0.2.0
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/LICENSE +20 -0
- package/README.md +300 -0
- package/SunmiPrinter.podspec +20 -0
- package/android/build.gradle +68 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/sunmiprinter/SunmiPrinterModule.kt +526 -0
- package/android/src/main/java/com/sunmiprinter/SunmiPrinterPackage.kt +31 -0
- package/ios/SunmiPrinter.h +5 -0
- package/ios/SunmiPrinter.mm +21 -0
- package/lib/module/NativeSunmiPrinter.js +5 -0
- package/lib/module/NativeSunmiPrinter.js.map +1 -0
- package/lib/module/index.js +147 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeSunmiPrinter.d.ts +45 -0
- package/lib/typescript/src/NativeSunmiPrinter.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +40 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +171 -0
- package/src/NativeSunmiPrinter.ts +92 -0
- package/src/index.tsx +205 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nguyễn Huy Hoàng
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
# @hoangnh0099/react-native-sunmi-printer
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@hoangnh0099/react-native-sunmi-printer)
|
|
4
|
+
[](https://github.com/ngxhuyhoang/react-native-sunmi-printer/blob/main/LICENSE)
|
|
5
|
+
[](#supported-devices)
|
|
6
|
+
[](#)
|
|
7
|
+
|
|
8
|
+
React Native library for Sunmi built-in printers. Supports Sunmi V2S and newer devices (Android 11+).
|
|
9
|
+
|
|
10
|
+
Built with **React Native New Architecture** (TurboModule).
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install @hoangnh0099/react-native-sunmi-printer
|
|
18
|
+
# or
|
|
19
|
+
yarn add @hoangnh0099/react-native-sunmi-printer
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> **Note:** This library only supports Android. Sunmi devices are Android-based hardware.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Print Text
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import { printText, lineWrap } from '@hoangnh0099/react-native-sunmi-printer';
|
|
32
|
+
|
|
33
|
+
await printText('Hello, Sunmi!\n');
|
|
34
|
+
await lineWrap(3);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Print Image (Base64)
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import { printImage, lineWrap } from '@hoangnh0099/react-native-sunmi-printer';
|
|
41
|
+
|
|
42
|
+
await printImage(base64String);
|
|
43
|
+
await lineWrap(3);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Print QR Code
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import { printQRCode, lineWrap } from '@hoangnh0099/react-native-sunmi-printer';
|
|
50
|
+
|
|
51
|
+
// printQRCode(data, moduleSize, errorLevel)
|
|
52
|
+
// moduleSize: 1-16
|
|
53
|
+
// errorLevel: 0=L(7%), 1=M(15%), 2=Q(25%), 3=H(30%)
|
|
54
|
+
await printQRCode('https://example.com', 8, 2);
|
|
55
|
+
await lineWrap(3);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Print Barcode
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import {
|
|
62
|
+
printBarCode,
|
|
63
|
+
lineWrap,
|
|
64
|
+
} from '@hoangnh0099/react-native-sunmi-printer';
|
|
65
|
+
|
|
66
|
+
// printBarCode(data, symbology, height, width, textPosition)
|
|
67
|
+
// symbology: 0=UPC-A, 1=UPC-E, 2=EAN13, 3=EAN8, 4=CODE39,
|
|
68
|
+
// 5=ITF, 6=CODABAR, 7=CODE93, 8=CODE128
|
|
69
|
+
// height: 1-255 | width: 2-6
|
|
70
|
+
// textPosition: 0=none, 1=above, 2=below, 3=both
|
|
71
|
+
await printBarCode('1234567890', 8, 162, 2, 2);
|
|
72
|
+
await lineWrap(3);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Print Table
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
import {
|
|
79
|
+
printColumnsString,
|
|
80
|
+
lineWrap,
|
|
81
|
+
} from '@hoangnh0099/react-native-sunmi-printer';
|
|
82
|
+
|
|
83
|
+
// printColumnsString(texts, widths, aligns)
|
|
84
|
+
// widths: proportional weights (e.g., [1, 1] = equal columns)
|
|
85
|
+
// aligns: 0=left, 1=center, 2=right
|
|
86
|
+
await printColumnsString(['Item', 'Price'], [1, 1], [0, 2]);
|
|
87
|
+
await printColumnsString(['Coffee', '$3.00'], [1, 1], [0, 2]);
|
|
88
|
+
await lineWrap(3);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Text Formatting
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import {
|
|
95
|
+
setAlignment,
|
|
96
|
+
setFontSize,
|
|
97
|
+
printText,
|
|
98
|
+
printerInit,
|
|
99
|
+
} from '@hoangnh0099/react-native-sunmi-printer';
|
|
100
|
+
|
|
101
|
+
await setAlignment(1); // 0=left, 1=center, 2=right
|
|
102
|
+
await setFontSize(28);
|
|
103
|
+
await printText('Centered Title\n');
|
|
104
|
+
|
|
105
|
+
// Reset formatting
|
|
106
|
+
await printerInit();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Transaction Mode
|
|
110
|
+
|
|
111
|
+
Use transaction mode to get actual print completion status:
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
import {
|
|
115
|
+
enterPrinterBuffer,
|
|
116
|
+
printText,
|
|
117
|
+
lineWrap,
|
|
118
|
+
exitPrinterBuffer,
|
|
119
|
+
} from '@hoangnh0099/react-native-sunmi-printer';
|
|
120
|
+
|
|
121
|
+
await enterPrinterBuffer(true);
|
|
122
|
+
await printText('Buffered print\n');
|
|
123
|
+
await lineWrap(3);
|
|
124
|
+
await exitPrinterBuffer(true); // resolves when printing completes
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Printer Status
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
import { updatePrinterState } from '@hoangnh0099/react-native-sunmi-printer';
|
|
131
|
+
|
|
132
|
+
const state = await updatePrinterState();
|
|
133
|
+
// 1=normal, 2=initializing, 3=hardware error, 4=out of paper,
|
|
134
|
+
// 5=overheating, 6=cover open, 7=cutter error, 505=no printer
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## API Reference
|
|
140
|
+
|
|
141
|
+
<details>
|
|
142
|
+
<summary><b>Printer Info</b></summary>
|
|
143
|
+
|
|
144
|
+
| Method | Return | Description |
|
|
145
|
+
| ---------------------- | ----------------- | -------------------------------------- |
|
|
146
|
+
| `getPrinterSerialNo()` | `Promise<string>` | Printer serial number |
|
|
147
|
+
| `getPrinterVersion()` | `Promise<string>` | Firmware version |
|
|
148
|
+
| `getPrinterModal()` | `Promise<string>` | Device model |
|
|
149
|
+
| `getPrinterPaper()` | `Promise<number>` | Paper size (1=58mm, other=80mm) |
|
|
150
|
+
| `getPrinterMode()` | `Promise<number>` | Mode (0=normal, 1=black mark, 2=label) |
|
|
151
|
+
| `getServiceVersion()` | `Promise<string>` | Print service version |
|
|
152
|
+
| `getFirmwareStatus()` | `Promise<number>` | Firmware status |
|
|
153
|
+
| `updatePrinterState()` | `Promise<number>` | Current printer state |
|
|
154
|
+
| `getPrintedLength()` | `Promise<string>` | Print distance since boot |
|
|
155
|
+
| `getPrinterFactory()` | `Promise<string>` | Printer head manufacturer |
|
|
156
|
+
|
|
157
|
+
</details>
|
|
158
|
+
|
|
159
|
+
<details>
|
|
160
|
+
<summary><b>Initialization</b></summary>
|
|
161
|
+
|
|
162
|
+
| Method | Description |
|
|
163
|
+
| ----------------------- | ----------------------------------- |
|
|
164
|
+
| `printerInit()` | Reset all printer styles to default |
|
|
165
|
+
| `printerSelfChecking()` | Print self-test page |
|
|
166
|
+
|
|
167
|
+
</details>
|
|
168
|
+
|
|
169
|
+
<details>
|
|
170
|
+
<summary><b>Formatting</b></summary>
|
|
171
|
+
|
|
172
|
+
| Method | Description |
|
|
173
|
+
| ----------------------------- | ----------------------------------------- |
|
|
174
|
+
| `setAlignment(alignment)` | Set alignment (0=left, 1=center, 2=right) |
|
|
175
|
+
| `setFontName(typeface)` | Set font (`"gh"` for built-in monospace) |
|
|
176
|
+
| `setFontSize(fontsize)` | Set font size |
|
|
177
|
+
| `setPrinterStyle(key, value)` | Set printer style (bold, underline, etc.) |
|
|
178
|
+
|
|
179
|
+
</details>
|
|
180
|
+
|
|
181
|
+
<details>
|
|
182
|
+
<summary><b>Text</b></summary>
|
|
183
|
+
|
|
184
|
+
| Method | Description |
|
|
185
|
+
| --------------------------------------------- | ----------------------------------------- |
|
|
186
|
+
| `printText(text)` | Print text (include `\n` to flush) |
|
|
187
|
+
| `printTextWithFont(text, typeface, fontsize)` | Print text with specific font and size |
|
|
188
|
+
| `printOriginalText(text)` | Print text with variable-width characters |
|
|
189
|
+
|
|
190
|
+
</details>
|
|
191
|
+
|
|
192
|
+
<details>
|
|
193
|
+
<summary><b>Image</b></summary>
|
|
194
|
+
|
|
195
|
+
| Method | Description |
|
|
196
|
+
| --------------------------------- | ------------------------------------------------------- |
|
|
197
|
+
| `printImage(base64)` | Print base64-encoded image |
|
|
198
|
+
| `printBitmapCustom(base64, type)` | Print with mode (0=default, 1=black&white, 2=grayscale) |
|
|
199
|
+
|
|
200
|
+
> Max width: 384px (58mm) or 576px (80mm). Call `lineWrap()` after printing to feed paper.
|
|
201
|
+
|
|
202
|
+
</details>
|
|
203
|
+
|
|
204
|
+
<details>
|
|
205
|
+
<summary><b>Barcode</b></summary>
|
|
206
|
+
|
|
207
|
+
| Method | Description |
|
|
208
|
+
| ------------------------------------------------------------ | ------------- |
|
|
209
|
+
| `printBarCode(data, symbology, height, width, textPosition)` | Print barcode |
|
|
210
|
+
| `printQRCode(data, moduleSize, errorLevel)` | Print QR code |
|
|
211
|
+
|
|
212
|
+
</details>
|
|
213
|
+
|
|
214
|
+
<details>
|
|
215
|
+
<summary><b>Table</b></summary>
|
|
216
|
+
|
|
217
|
+
| Method | Description |
|
|
218
|
+
| ------------------------------------------- | ---------------------------------------------- |
|
|
219
|
+
| `printColumnsText(texts, widths, aligns)` | Print columns (widths in character count) |
|
|
220
|
+
| `printColumnsString(texts, widths, aligns)` | Print columns (widths as proportional weights) |
|
|
221
|
+
|
|
222
|
+
</details>
|
|
223
|
+
|
|
224
|
+
<details>
|
|
225
|
+
<summary><b>Raw / Paper</b></summary>
|
|
226
|
+
|
|
227
|
+
| Method | Description |
|
|
228
|
+
| ------------------- | -------------------------------- |
|
|
229
|
+
| `sendRAWData(data)` | Send raw ESC/POS byte array |
|
|
230
|
+
| `lineWrap(lines)` | Feed paper by N lines |
|
|
231
|
+
| `cutPaper()` | Cut paper (if cutter available) |
|
|
232
|
+
| `autoOutPaper()` | Auto feed paper to tear position |
|
|
233
|
+
|
|
234
|
+
</details>
|
|
235
|
+
|
|
236
|
+
<details>
|
|
237
|
+
<summary><b>Cash Drawer</b></summary>
|
|
238
|
+
|
|
239
|
+
| Method | Description |
|
|
240
|
+
| -------------- | ------------------------------- |
|
|
241
|
+
| `openDrawer()` | Open cash drawer (if available) |
|
|
242
|
+
|
|
243
|
+
</details>
|
|
244
|
+
|
|
245
|
+
<details>
|
|
246
|
+
<summary><b>Label</b></summary>
|
|
247
|
+
|
|
248
|
+
| Method | Description |
|
|
249
|
+
| --------------- | -------------------------------- |
|
|
250
|
+
| `labelLocate()` | Locate label position |
|
|
251
|
+
| `labelOutput()` | Push label to cutter for peeling |
|
|
252
|
+
|
|
253
|
+
</details>
|
|
254
|
+
|
|
255
|
+
<details>
|
|
256
|
+
<summary><b>LCD Customer Display</b></summary>
|
|
257
|
+
|
|
258
|
+
| Method | Description |
|
|
259
|
+
| ------------------------------------- | ------------------------------------------ |
|
|
260
|
+
| `sendLCDCommand(flag)` | LCD command (1=init, 2=on, 3=off, 4=clear) |
|
|
261
|
+
| `sendLCDFillString(text, size, fill)` | Display text on LCD |
|
|
262
|
+
| `sendLCDMultiString(texts, align)` | Display multi-line text on LCD |
|
|
263
|
+
| `sendLCDBitmap(base64)` | Display image on LCD |
|
|
264
|
+
|
|
265
|
+
</details>
|
|
266
|
+
|
|
267
|
+
<details>
|
|
268
|
+
<summary><b>Transaction</b></summary>
|
|
269
|
+
|
|
270
|
+
| Method | Description |
|
|
271
|
+
| --------------------------- | -------------------------------------------- |
|
|
272
|
+
| `enterPrinterBuffer(clean)` | Start buffering commands |
|
|
273
|
+
| `exitPrinterBuffer(commit)` | Exit buffer (commit=true to print) |
|
|
274
|
+
| `commitPrinterBuffer()` | Print buffer contents (stays in buffer mode) |
|
|
275
|
+
|
|
276
|
+
</details>
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Supported Devices
|
|
281
|
+
|
|
282
|
+
| Device | Android | Status |
|
|
283
|
+
| ------------------- | ------- | --------- |
|
|
284
|
+
| Sunmi V2S | 11 | Supported |
|
|
285
|
+
| Sunmi V2S Plus | 11 | Supported |
|
|
286
|
+
| Newer Sunmi devices | 11+ | Supported |
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Contributing
|
|
291
|
+
|
|
292
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
293
|
+
|
|
294
|
+
## License
|
|
295
|
+
|
|
296
|
+
[MIT](LICENSE)
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,20 @@
|
|
|
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 = "SunmiPrinter"
|
|
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://github.com/ngxhuyhoang/react-native-sunmi-printer.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
|
|
17
|
+
s.private_header_files = "ios/**/*.h"
|
|
18
|
+
|
|
19
|
+
install_modules_dependencies(s)
|
|
20
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.SunmiPrinter = [
|
|
3
|
+
kotlinVersion: "2.0.21",
|
|
4
|
+
minSdkVersion: 30,
|
|
5
|
+
compileSdkVersion: 36,
|
|
6
|
+
targetSdkVersion: 36
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
ext.getExtOrDefault = { prop ->
|
|
10
|
+
if (rootProject.ext.has(prop)) {
|
|
11
|
+
return rootProject.ext.get(prop)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return SunmiPrinter[prop]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
repositories {
|
|
18
|
+
google()
|
|
19
|
+
mavenCentral()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
dependencies {
|
|
23
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
24
|
+
// noinspection DifferentKotlinGradleVersion
|
|
25
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
apply plugin: "com.android.library"
|
|
31
|
+
apply plugin: "kotlin-android"
|
|
32
|
+
|
|
33
|
+
apply plugin: "com.facebook.react"
|
|
34
|
+
|
|
35
|
+
android {
|
|
36
|
+
namespace "com.sunmiprinter"
|
|
37
|
+
|
|
38
|
+
compileSdkVersion getExtOrDefault("compileSdkVersion")
|
|
39
|
+
|
|
40
|
+
defaultConfig {
|
|
41
|
+
minSdkVersion getExtOrDefault("minSdkVersion")
|
|
42
|
+
targetSdkVersion getExtOrDefault("targetSdkVersion")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
buildFeatures {
|
|
46
|
+
buildConfig true
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
buildTypes {
|
|
50
|
+
release {
|
|
51
|
+
minifyEnabled false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
lint {
|
|
56
|
+
disable "GradleCompatible"
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
compileOptions {
|
|
60
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
61
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
dependencies {
|
|
66
|
+
implementation "com.facebook.react:react-android"
|
|
67
|
+
implementation "com.sunmi:printerlibrary:1.0.24"
|
|
68
|
+
}
|