## Installation
npm install rn-evolute-printer``sh`
npm install rn-evolute-printerAndroid Setup
Add the following line to the app/build.gradle file in your project.
`js`
dependencies {
implementation files('path/to/library/android/libs/PrinterLib_24.aar')
}
To fetch the Bluetooth device name list in your React Native project, utilize the react-native-ble-manager package. Refer to the official documentation for more details and examples.
Package link:
https://www.npmjs.com/package/react-native-ble-manager
`js
import BleManager from 'react-native-ble-manager';
\\ code
`
`js
import EvolutePrinter from 'rn-evolute-printer';
// Initialize the printer with callbacks for success and error handling
const initialize = await EvolutePrinter.initiate(
errorCallback,
successCallback
);
// The printerName is retrieved using the react-native-ble-manager package.
// Connect to a specific printer using its name.
const connect = await EvolutePrinter.connect(
printerName,
errorCallback,
successCallback
);
// Print data, with optional success and error callbacks
const print = await EvolutePrinter.print(data, errorCallback, successCallback);
`
Here’s a complete example to guide you through each step from initializing the library to printing data.
`js
import EvolutePrinter from 'rn-evolute-printer';
const initializePrinter = async () => {
try {
// Step 1: Initialize the Printer
await EvolutePrinter.initiate(
(error) => console.error('Initialization Error:', error),
() => console.log('Initialization Successful')
);
// Step 2: Connect to a Printer
const printerName = pairedDevices[0]?.name || 'YourPrinterName';
const isConnected = await EvolutePrinter.connect(
printerName,
(error) => console.error('connect Error:', error),
() => console.log('connect Successful')
);
if (isConnected) {
console.log(Connected to ${printerName});
// Step 3: Print Data
await EvolutePrinter.print(
'Hello, this is a test print!',
(error) => console.error('Print Error:', error),
() => console.log('Print Successful')
);
} else {
console.error(Failed to connect to printer: ${printerName});
}
} catch (error) {
console.error('Error:', error);
}
};
// Initialize and run the example
initializePrinter();
``
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
---
Made with create-react-native-library