ordering-ui-react-native 0.21.38-test → 0.21.40-test

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.21.38-test",
3
+ "version": "0.21.40-test",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -42,7 +42,8 @@ import { NewOrderNotification } from './src/components/NewOrderNotification';
42
42
  import { DriverSchedule } from './src/components/DriverSchedule';
43
43
  import { ScheduleBlocked } from './src/components/ScheduleBlocked';
44
44
  import { OrderDetailsLogistic } from './src/components/OrderDetailsLogistic'
45
- import HandleStarPrinter from './src/components/StarPrinter';
45
+ import { HandleStarPrinter } from './src/components/StarPrinter';
46
+ import { SearchStarPrinter } from './src/components/StarPrinter/SearchPrinter';
46
47
  //OComponents
47
48
  import {
48
49
  OText,
@@ -133,4 +134,5 @@ export {
133
134
  StoreMethods,
134
135
  //printer
135
136
  HandleStarPrinter,
137
+ SearchStarPrinter,
136
138
  };
@@ -0,0 +1,80 @@
1
+ import React, { useState } from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ Button,
6
+ FlatList,
7
+ } from 'react-native';
8
+
9
+ import {
10
+ InterfaceType,
11
+ StarDeviceDiscoveryManager,
12
+ StarDeviceDiscoveryManagerFactory,
13
+ StarPrinter
14
+ } from 'react-native-star-io10';
15
+
16
+ export const SearchStarPrinter = () => {
17
+
18
+ let _manager: StarDeviceDiscoveryManager;
19
+
20
+ const [state, setState] = useState({
21
+ bluetoonabled: true,
22
+ printers: [],
23
+ })
24
+
25
+ let _onPressDiscoveryButton = async () => {
26
+ setState({
27
+ ...state,
28
+ printers: [],
29
+ });
30
+
31
+ try {
32
+ await _manager?.stopDiscovery()
33
+
34
+ var interfaceTypes: Array<InterfaceType> = []
35
+ if (state.bluetoonabled) {
36
+ interfaceTypes.push(InterfaceType.Bluetooth);
37
+ }
38
+
39
+ _manager = await StarDeviceDiscoveryManagerFactory.create(interfaceTypes);
40
+ _manager.discoveryTime = 10000;
41
+
42
+ _manager.onPrinterFound = (printer: StarPrinter) => {
43
+ const printers = state.printers;
44
+ printers.push(printer);
45
+ setState({
46
+ ...state,
47
+ printers: printers
48
+ });
49
+
50
+ console.log(`Found printer: ${printer.connectionSettings.identifier}.`);
51
+ };
52
+
53
+ _manager.onDiscoveryFinished = () => {
54
+ console.log(`Discovery finished.`);
55
+ };
56
+
57
+ await _manager.startDiscovery();
58
+ }
59
+ catch (error) {
60
+ console.log(`Error: ${String(error)}`);
61
+ }
62
+ }
63
+
64
+ return (
65
+ <View style={{ margin: 50 }}>
66
+ <View
67
+ style={{ width: 100, marginTop: 30 }}>
68
+ <Button
69
+ title="Discovery"
70
+ onPress={_onPressDiscoveryButton}
71
+ />
72
+ </View>
73
+ <FlatList
74
+ style={{ marginTop: 30 }}
75
+ data={state.printers}
76
+ renderItem={({ item }) => <Text>{item.connectionSettings.interfaceType} : {item.connectionSettings.identifier}</Text>}
77
+ keyExtractor={(item, index) => index.toString()} />
78
+ </View>
79
+ );
80
+ };
@@ -14,11 +14,11 @@ import {
14
14
  } from 'react-native';
15
15
 
16
16
 
17
- const HandleStarPrinter = () => {
17
+ export const HandleStarPrinter = ({ navigation }: any) => {
18
18
 
19
19
  const [printState, setPrintState] = useState({
20
20
  interfaceType: InterfaceType.Bluetooth,
21
- identifier: '00:11:62:00:00:00',
21
+ identifier: '',
22
22
  imageBase64: ''
23
23
  });
24
24
 
@@ -111,6 +111,10 @@ const HandleStarPrinter = () => {
111
111
  }
112
112
  }
113
113
 
114
+ const onSearchPrint = () => {
115
+ navigation.navigate('SearchStarPrinter')
116
+ }
117
+
114
118
  return (
115
119
  <View style={{ margin: 50 }}>
116
120
  <View style={{ flexDirection: 'row' }}>
@@ -121,10 +125,7 @@ const HandleStarPrinter = () => {
121
125
  onValueChange={(value) => {
122
126
  setPrintState({ interfaceType: value });
123
127
  }}>
124
- <Picker.Item label='LAN' value={InterfaceType.Lan} />
125
128
  <Picker.Item label='Bluetooth' value={InterfaceType.Bluetooth} />
126
- <Picker.Item label='Bluetooth LE' value={InterfaceType.BluetoothLE} />
127
- <Picker.Item label='USB' value={InterfaceType.Usb} />
128
129
  </Picker>
129
130
  </View>
130
131
  <View style={{ flexDirection: 'row', marginTop: 30 }}>
@@ -136,6 +137,12 @@ const HandleStarPrinter = () => {
136
137
  setPrintState({ identifier: value });
137
138
  }}
138
139
  />
140
+ <View style={{ width: 100, marginTop: 20 }}>
141
+ <Button
142
+ title="Search Printer"
143
+ onPress={onSearchPrint}
144
+ />
145
+ </View>
139
146
  </View>
140
147
  <View style={{ width: 100, marginTop: 20 }}>
141
148
  <Button
@@ -147,4 +154,3 @@ const HandleStarPrinter = () => {
147
154
  );
148
155
  };
149
156
 
150
- export default HandleStarPrinter;