GithubHelp home page GithubHelp logo

Comments (2)

codoffer avatar codoffer commented on April 28, 2024 2

Thanks @thiendangit

I have solved the issue by adding setTimeout with each method and incrementing on every use.

asyncPrintText = (text, waitTime) => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        this.Printer.printText(text);
        resolve();
      }, waitTime * 100);
    });
  };

  asyncPrintBill = (bill, waitTime) => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        this.Printer.printBill(bill);
        resolve();
      }, waitTime * 100);
    });
  };

  asyncPrintColumnsText = (
    columnHeader,
    columnWidth,
    columnAliment,
    columnStyle,
    waitTime,
  ) => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        this.Printer.printColumnsText(
          columnHeader,
          columnWidth,
          columnAliment,
          columnStyle,
        );
        resolve();
      }, waitTime * 100);
    });
  };

I am using like below

printBillOrderInfo = () => {
    return new Promise((resolve, reject) => {
      const paymentMethod = this.order?.method
        ? orderPaymentMethods?.[this.order.method] !== undefined
          ? orderPaymentMethods?.[this.order.method]
          : ' - '
        : ' - ';
      const userName =
        this.order?.user?.name !== null ? this.order?.user?.name : ' - ';
      const pickupMethod = orderPickupMethods?.[this.order.action];
      const orderRemark = this.order?.note !== null ? this.order?.note : ' - ';
      const orderDate = codoDateformat(this.order?.create_at);
      Promise.all([
        printerService.asyncPrintColumnsText(
          ['Order Id : ', `${this.order?.order_number}`],
          [23, 23],
          [ColumnAliment.LEFT, ColumnAliment.RIGHT],
          ['', ''],
          this.waitTime++,
        ),
        printerService.asyncPrintColumnsText(
          ['Method : ', `${pickupMethod}`],
          [23, 23],
          [ColumnAliment.LEFT, ColumnAliment.RIGHT],
          ['', ''],
          this.waitTime++,
        ),
        printerService.asyncPrintColumnsText(
          ['Payment Method : ', `${paymentMethod}`],
          [23, 23],
          [ColumnAliment.LEFT, ColumnAliment.RIGHT],
          ['', ''],
          this.waitTime++,
        ),
        printerService.asyncPrintColumnsText(
          ['Note : ', `${orderRemark}`],
          [23, 23],
          [ColumnAliment.LEFT, ColumnAliment.RIGHT],
          ['', ''],
          this.waitTime++,
        ),
        printerService.asyncPrintColumnsText(
          ['User : ', `${userName}`],
          [23, 23],
          [ColumnAliment.LEFT, ColumnAliment.RIGHT],
          ['', ''],
          this.waitTime++,
        ),
        printerService.asyncPrintColumnsText(
          ['Order Date : ', `${orderDate}`],
          [23, 23],
          [ColumnAliment.LEFT, ColumnAliment.RIGHT],
          ['', ''],
          this.waitTime++,
        ),
        printerService.asyncPrintColumnsText(
          [`${DOUBLE_DASHED_LINE}`],
          [52],
          [ColumnAliment.LEFT],
          [''],
          this.waitTime++,
        ),
      ]).then(() => {
        resolve();
      });
    });
  };

from react-native-thermal-receipt-printer-image-qr.

thiendangit avatar thiendangit commented on April 28, 2024

@codoffer try to using setTimeOut in asyncPrintColumnsText function!

asyncPrintColumnsText = (
    columnHeader,
    columnWidth,
    columnAliment,
    columnStyle,
  ) => {
    return new Promise((resolve, reject) => {
      setTimeOut(()=>{
        this.Printer.printColumnsText(
        columnHeader,
        columnWidth,
        columnAliment,
        columnStyle,
      );
      resolve();
      }, 100)
    });
  };

from react-native-thermal-receipt-printer-image-qr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.