UNPKG

sunmi-device-sdk

Version:

JavaScript SDK for Sunmi card readers and printers

114 lines (86 loc) 2.35 kB
# React Native Setup for Sunmi Device SDK ## Overview This directory contains React Native native module wrappers for the Sunmi card reader and printer. ## Installation in React Native ### 1. Install the npm package ```bash npm install @sunmi/device-sdk ``` ### 2. Copy native Android files Copy the following files to your React Native Android project: ```bash # From this repo's src/android/ to your RN project: cp -r src/android/com your-rn-project/android/app/src/main/java/ cp -r src/android/woyou your-rn-project/android/app/src/main/aidl/ cp libs/rel.aar your-rn-project/android/app/libs/ ``` ### 3. Add React Native bridge modules Create these files in your React Native project: **SunmiCardReaderModule.java** **SunmiPrinterModule.java** See the example files in this directory. ### 4. Update build.gradle ```gradle // android/app/build.gradle android { defaultConfig { // ... existing config } repositories { flatDir { dirs 'libs' } } } dependencies { implementation(name: 'rel', ext: 'aar') // ... other dependencies } ``` ### 5. Register modules ```java // MainApplication.java import com.sunmi.SunmiCardReaderPackage; import com.sunmi.SunmiPrinterPackage; @Override protected List<ReactPackage> getPackages() { return Arrays.asList( new MainReactPackage(), new SunmiCardReaderPackage(), new SunmiPrinterPackage() ); } ``` ### 6. Use in your React Native app ```typescript import { SunmiPrinter, PrintAlignment } from '@sunmi/device-sdk'; const MyComponent = () => { const printReceipt = async () => { try { await SunmiPrinter.init(); await SunmiPrinter.setAlignment(PrintAlignment.CENTER); await SunmiPrinter.printText('Hello from React Native!'); await SunmiPrinter.feedPaper(3); } catch (error) { console.error('Print failed:', error); } }; return ( <Button title="Print" onPress={printReceipt} /> ); }; ``` ## Architecture ``` Your React Native App ↓ @sunmi/device-sdk (JavaScript/TypeScript) ↓ React Native Bridge (Native Modules) ↓ Sunmi Android SDK (Java/AIDL) ↓ Sunmi Hardware ``` ## No Cordova Required! The package automatically detects it's running in React Native and uses the React Native bridge instead of Cordova.