react-native-esc-pos-printer icon indicating copy to clipboard operation
react-native-esc-pos-printer copied to clipboard

Android Search Printer result will disappear on version 4.0.6-beta

Open powershek opened this issue 1 year ago • 1 comments

I am try the search function on android by the syntax below

const { start, printerError, isDiscovering, printers } = usePrintersDiscovery()

Display

      <View style={{flexDirection:'row',alignItems:'center',width:'100%'}} >
        <Text style={}>Show android result</Text>
            <FlatList
                showsVerticalScrollIndicator={false}
                showsHorizontalScrollIndicator={false}
                data={printers}
                keyExtractor={(item, index) => `${index}`}
                renderItem={_renderPrinter_test}
                horizontal={true}
                // ListEmptyComponent={renderEmptyZoneHint}
            />            
        </View>

Trigger:

function doSearchPrinterAction() { start()

} printers will suddenly show up and disappear. every thing works on IOS. can you please

powershek avatar Jul 09 '24 10:07 powershek

I found that on function PrintersDiscovery.onDiscovery

Android version didn't append the found printer list.

powershek avatar Jul 10 '24 07:07 powershek

Hello

@powershek what is logs for "printers" array?

const { start, printerError, isDiscovering, printers } = usePrintersDiscovery()

console.log(printers) // here ??

tr3v3r avatar Jul 17 '24 10:07 tr3v3r

Hello

@powershek what is logs for "printers" array?

const { start, printerError, isDiscovering, printers } = usePrintersDiscovery()

console.log(printers) // here ??

I have found that it takes only one element. Bleutooth or WLAN , the last one remain . But in iOS, both listed in array

aargon007 avatar Jul 25 '24 14:07 aargon007

@aargon007 please try to increase timeout or disable auth stop

start({ timeout: 20000 })

or

start({ autoStop: false }) // don't forget to stop manually

tr3v3r avatar Jul 25 '24 14:07 tr3v3r

PrintersDiscovery.onDiscovery ->. The android behaviour only return 1 printer each time, but IOS append in a list. I had change the code myself in usePrintersDiscovery.ts like this to work

var printerListAndroid = new Array();

useEffect(() => { const removeListener = PrintersDiscovery.onDiscovery( (deviceInfo: DeviceInfo[]) => { // console.log("printer deviceInfo=", deviceInfo, Platform.OS)

    if (Platform.OS === 'ios') {
      setPrinters(deviceInfo);
    } else {
      //setPrinters([...printers, ...deviceInfo]);
      // console.log("printer android deviceInfo=", printerListAndroid, Platform.OS)        
      printerListAndroid.push(deviceInfo[0]);
      setPrinters(printerListAndroid);
    }
  }
);

return () => {
  removeListener();
};

}, []);

powershek avatar Jul 26 '24 16:07 powershek

@powershek Seems I found the issue

Just released 4.0.1 with the fix. Please check and let me know if issue still exists

tr3v3r avatar Jul 26 '24 20:07 tr3v3r

Issue resolved in 4.1.3

tr3v3r avatar Aug 06 '24 15:08 tr3v3r