Surile / react-native-sunmi-printer

商米内置打印机
MIT License
47 stars 33 forks source link

Running in Expo #16

Closed butbut1111 closed 2 years ago

butbut1111 commented 2 years ago

hello, when i try to copy the code from example and run it in my project which use expo, i encounter this error. Any idea why? Thanks

import React from 'react';
import { StyleSheet, View, Text, TouchableOpacity } from 'react-native';
import SunmiPrinter, {
  AlignValue,
  SunmiScan,
} from '@heasy/react-native-sunmi-printer';

export default function App() {
  const _printRecieve = () => {
    SunmiPrinter.setFontSize(30);
    SunmiPrinter.setFontWeight(true);
    SunmiPrinter.lineWrap(1);
    SunmiPrinter.setAlignment(AlignValue.CENTER);
    SunmiPrinter.printerText('VIPKIT');
    SunmiPrinter.lineWrap(2);
    SunmiPrinter.setAlignment(AlignValue.CENTER);
    SunmiPrinter.printerText('电子发票申请\n');
    SunmiPrinter.lineWrap(1);
    SunmiPrinter.printColumnsString(
      ['订单编号', '1231231231'],
      [60, 120],
      [AlignValue.LEFT, AlignValue.RIGHT]
    );
    SunmiPrinter.lineWrap(1);
    SunmiPrinter.printColumnsString(
      ['实付金额', `¥${200}`],
      [60, 120],
      [AlignValue.LEFT, AlignValue.RIGHT]
    );
    SunmiPrinter.lineWrap(1);
    SunmiPrinter.setAlignment(AlignValue.CENTER);
    SunmiPrinter.print2DCode(
      'https://qr.api.cli.im/newqr/create?data=https%253A%252F%252Fgithub.com%252FSurile%252Freact-native-sunmi-printer&level=H&transparent=false&bgcolor=%23FFFFFF&forecolor=%23000000&blockpixel=12&marginblock=1&logourl=&logoshape=no&size=260&kid=cliim&key=db8abf82a7306ec8f01d41c1155b0a9d',
      1,
      4,
      4
    );
    SunmiPrinter.lineWrap(1);
    SunmiPrinter.setAlignment(AlignValue.CENTER);
    SunmiPrinter.printerText('扫码自助申请电子发票\n');
    SunmiPrinter.lineWrap(1);
    SunmiPrinter.printColumnsString(
      ['服务员', 'Surile'],
      [60, 120],
      [AlignValue.LEFT, AlignValue.RIGHT]
    );
    SunmiPrinter.lineWrap(1);
    SunmiPrinter.printColumnsString(
      ['打印时间', '2021-09-27'],
      [60, 120],
      [AlignValue.LEFT, AlignValue.RIGHT]
    );
    SunmiPrinter.lineWrap(3);
    SunmiPrinter.cutPaper();
  };

  return (
    <View style={styles.container}>
      <TouchableOpacity style={styles.button} onPress={_printRecieve}>
        <Text style={styles.buttonText}>打印</Text>
      </TouchableOpacity>
      <TouchableOpacity
        // eslint-disable-next-line react-native/no-inline-styles
        style={{ ...styles.button, marginTop: 10 }}
        onPress={() => {
          SunmiScan.scan()
            .then((res) => {
              console.log(res);
            })
            .catch((err) => {
              console.log('error---->', err);
            });
        }}
      >
        <Text style={styles.buttonText}>扫码</Text>
      </TouchableOpacity>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  button: {
    padding: 20,
    backgroundColor: '#222',
    justifyContent: 'center',
    alignItems: 'center',
    borderRadius: 10,
  },
  buttonText: {
    color: 'white',
    fontSize: 18,
  },
});

IMG_8974

TypeError: null is not an object (evaluating '_reactNativeSunmiPrinter.default.setFontSize')
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0
Surile commented 2 years ago

https://github.com/Surile/react-native-sunmi-printer/issues/10#issuecomment-1113176276

butbut1111 commented 2 years ago

Hello, I just tired the mentioned method but seems not working. My device is V2 (not v2s, v2s plus , v2pro), according to the documentation, seems only v2s and v2s plus need the additional line.

butbut1111 commented 2 years ago

Hello @Surile I got a v2s on hand but still have the same error, already tried the plugin method but seems the error message still persist. Any ideas? Thanks!

Surile commented 2 years ago

@butbut1111 I don't know. I need to see the file

Surile commented 2 years ago

@butbut1111 This is https://github.com/Surile/react-native-sunmi-printer/issues/10

butbut1111 commented 2 years ago

I manage to run it without expo! thanks a lot

anilnet commented 1 year ago

hi , I get the same error when I want to work with expo. I tried what is written in the comment below but the error is not fixed. expo comment Is there a solution?

thanks