Skip to content

coopcycle/react-native-sunmi-printer-library

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@mitsuharu/react-native-sunmi-printer-library

React Native module that support for SUNMI mobile printer devices.

devices that test my libarary

  • SUNMI V2 PRO
  • SUNMI V2s

I test with GMS 1 enable and developable SUNMI V2 PRO and V2s as follows. Though I do not have other devices, users report to work with V1s and V2.

Android SUNMI OS firmware storage memory NFC
SUNMI V2 PRO 7.1 3.6.23 754 16 GB 2 GB enable
SUNMI V2 PRO (foodpanda) 7.1 1.0.33 138 8 GB 1 GB disable
SUNMI V2s 11 3.0.11 242 32 GB 3 GB enable

Installation

npm install @mitsuharu/react-native-sunmi-printer-library

or

yarn add @mitsuharu/react-native-sunmi-printer-library

Usage

You see example directory for details.

prepare

import * as SunmiPrinterLibrary from '@mitsuharu/react-native-sunmi-printer-library'
try {
    await SunmiPrinterLibrary.prepare()
} catch (error: any) {
    console.warn("This device is not supported.")
}

print Text

await SunmiPrinterLibrary.printText('Hello World')

OR

SunmiPrinterLibrary.printText('Hello World')

change style

await SunmiPrinterLibrary.setAlignment('center')
await SunmiPrinterLibrary.setTextStyle('bold', true)
await SunmiPrinterLibrary.setParagraphStyle('textRightSpacing', 5)
await SunmiPrinterLibrary.setFontSize(32)
await SunmiPrinterLibrary.printText('Hello World')

print Image (Base64)

const base64 = 'data:image/png;base64,iVBORw0KGgoAAAA...'
await SunmiPrinterLibrary.printImage(base64, 384, 'binary')
await SunmiPrinterLibrary.printImage(base64, 384, 'grayscale')

print QR code

await SunmiPrinterLibrary.printQRCode('Hello World', 8, 'middle')

scan QR code

const result = await SunmiPrinterLibrary.scan()

OR

SunmiPrinterLibrary.scan()
useEffect(() => {
   DeviceEventEmitter.addListener(
      SunmiPrinterLibrary.EventType.onScanSuccess,
      (message) => {
        console.log(`[onScanSuccess] ${message}`)
      })
   DeviceEventEmitter.addListener(
      SunmiPrinterLibrary.EventType.onScanFailed, 
      (message) => {
        console.log(`[onScanFailed] ${message}`)
      })
   return () => {
      DeviceEventEmitter.removeAllListeners(SunmiPrinterLibrary.EventType.onScanSuccess)
      DeviceEventEmitter.removeAllListeners(SunmiPrinterLibrary.EventType.onScanFailed)
    }
}, [])

not support

  • Transaction Print API
  • Cash Drawer API
  • Black Mark Print API

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Develop

yarn
yarn example android

License

MIT


Made with create-react-native-library

Footnotes

  1. Google Mobile Services https://www.android.com/gms

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 76.2%
  • Kotlin 13.3%
  • Java 4.0%
  • JavaScript 2.3%
  • Ruby 2.2%
  • Objective-C 1.3%
  • Other 0.7%