You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+66-67Lines changed: 66 additions & 67 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,6 @@ This React module allows you to introduce a mobile interoperability into React a
3
3
4
4
This module is particularly useful in the current new normal established by the COVID-19 pandemic, where businesses require visiting customers to communicate accurately with customer representatives while enforcing the rules of wearing masks and social distancing. Thanks to this library, you will be able to establish an instant and secure communication right within the business software you are using, allowing your customers to collaborate effectively, securely and safely. For example, you may provide one-click subscriptions through user mobiles by leveraging the [mobile secure storage](https://globalinput.co.uk/global-input-app/mobile-authentication). Alternative, you do not even have to collect users' personal data thanks to the ability to request data on-demand from the mobile app at the point of service, freeing yourself from the pains of privacy regulations. You may also choose to allow your customers to encrypt their own data using their mobiles, giving users full control over the security and privacy of their personal data.
5
5
6
-
7
6
## Setup
8
7
9
8
```shell
@@ -18,27 +17,27 @@ import {useGlobalInputApp} from 'global-input-react';
18
17
Then, ```useGlobalInputApp()``` function (which is a React hook) can be called with a parameter, defining a mobile user interface. For example, the following code displays a login screen on the user's mobile screen when connected to your application:
19
18
20
19
```JavaScript
21
-
constusernameField={
22
-
id:'username',
23
-
label:'Username',
20
+
constusernameField={
21
+
id:'username',
22
+
label:'Username',
24
23
};
25
24
26
-
constpasswordField={
27
-
id:'password',
28
-
label:'Password'
25
+
constpasswordField={
26
+
id:'password',
27
+
label:'Password'
29
28
};
30
29
31
-
constloginButton={
32
-
id:'login',
33
-
label:'Sign In',
34
-
type:'button'
30
+
constloginButton={
31
+
id:'login',
32
+
label:'Sign In',
33
+
type:'button'
35
34
};
36
35
37
-
constmobile=useGlobalInputApp({initData:{
38
-
form:{
39
-
title:'Sign In',
40
-
fields: [usernameField,passwordField,loginButton]
41
-
}
36
+
constmobile=useGlobalInputApp({initData:{
37
+
form:{
38
+
title:'Sign In',
39
+
fields: [usernameField,passwordField,loginButton]
40
+
}
42
41
}});
43
42
```
44
43
The ```initData``` contains a ```form``` with a set of fields: ```usernameField```,```passwordField```, and ```loginButton```.
@@ -53,9 +52,9 @@ It displays an encrypted QR Code for mobile apps to scan to connect to your appl
53
52
54
53
When connected to your application, the mobile app displays a ```form``` specified in ```initData```. Also, when the user interacts with elements in the ```form```, your application can receive mobile events through ```mobile.field``` variable, with the ```mobile.field.id``` identifying the element that the user has interacted with, and with ```mobile.field.value``` holding the value that the user has entered. Actually, you can simply pass your callback function into the ```mobile.setOnchange()``` function to receive those mobile events instead of implementing the logic for monitoring the changes in the ```mobile.field``` variable:
55
54
```JavaScript
56
-
mobile.setOnchange(({field})=>{
57
-
const {id, value}=field;
58
-
switch(id){
55
+
mobile.setOnchange( ( {field} ) =>{
56
+
const {id, value}=field;
57
+
switch(id){
59
58
caseusernameField.id:
60
59
setUsername(value);
61
60
break;
@@ -72,22 +71,22 @@ In the above code, You can implement the ```setUsername()``` and ```setPassword(
72
71
```JavaScript
73
72
importReact, { useState } from'react';
74
73
...
75
-
const [username, setUsername]=useState('');
76
-
const [password, setPassword]=useState('');
74
+
const [username, setUsername]=useState('');
75
+
const [password, setPassword]=useState('');
77
76
```
78
77
79
78
You can also send values from your application to the mobile app responding to local or remote events:
@@ -98,15 +97,17 @@ Using this approach, you can turn a simple password-based authentication into a
98
97
When ```mobile.sendInitData()``` function is called with a ```InitData``` parameter, the connected mobile app will switch to the user interface specified:
99
98
100
99
```JavaScript
101
-
constlogin=(username,password)=>{
102
-
constinitData={
103
-
};
104
-
mobile.sendInitData(initData:{
105
-
form: {
106
-
title:"Welcome "+username,
107
-
fields: [{type:"info", value:"Test Completed",}]
108
-
}
109
-
});
100
+
constinfoField= {
101
+
type:"info",
102
+
value:"Test Completed"
103
+
};
104
+
constlogin= (username,password) => {
105
+
mobile.sendInitData({
106
+
form: {
107
+
title:"Welcome "+username,
108
+
fields: [infoField]
109
+
}
110
+
});
110
111
}
111
112
```
112
113
Another way is to place another instance of ```useGlobalInputApp``` in a component, and then switch to that component.
@@ -124,22 +125,22 @@ When ```useGlobalInputApp``` is invoked for the first time, the module will sta
124
125
For an element in a ```form```, ```type``` attribute defines how to process/display the data contained in it. For example, if it is set to ```button```, the mobile app display a ```Button```:
125
126
126
127
```JavaScript
127
-
constloginButton={
128
-
id:'login',
129
-
label:'Sign In',
130
-
type:'button'
131
-
};
128
+
constloginButton={
129
+
id:'login',
130
+
label:'Sign In',
131
+
type:'button'
132
+
};
132
133
```
133
134
134
135
The default value of the ```type``` attribute is "text". In this case, it display either a text input or a text area, depending on the value of ```nLines```, which represents how many number of lines is visible:
135
136
136
137
```JavaScript
137
-
constcontentField={
138
-
id:'content',
139
-
label:'Content',
140
-
type:"text",
141
-
nLines:5,
142
-
value:"This is a content in the text box"
138
+
constcontentField={
139
+
id:'content',
140
+
label:'Content',
141
+
type:"text",
142
+
nLines:5,
143
+
value:"This is a content in the text box"
143
144
};
144
145
```
145
146
If the ```value``` attribute is set, it will be sent along with the form to pre-populate the the field when being displayed on the mobile screen.
@@ -151,24 +152,22 @@ If the ```value``` attribute is set, it will be sent along with the form to pre-
151
152
If you set the value of ```type``` of element in a ```form``` to ```"encrypt"```, the connected mobile app encrypts the ```value``` of the element and send back the result to your application:
152
153
153
154
```JavaScript
154
-
constcontentToEncrypt="...";
155
-
constencryptField={
156
-
id:'content',
157
-
label:'Content',
158
-
type:"encrypt",
159
-
value:contentToEncrypt
155
+
constencryptField= {
156
+
id:'content',
157
+
label:'Content',
158
+
type:"encrypt",
159
+
value: contentToEncrypt
160
160
};
161
161
```
162
162
163
163
In a similar way, setting ```type``` to ```"decrypt"``` will lead to decryption:
164
164
165
165
```JavaScript
166
-
constcontentToDecrypt="...";
167
-
constdecryptField={
166
+
constdecryptField= {
168
167
id:'content',
169
168
label:'Content',
170
169
type:"decrypt",
171
-
value:contentToDecrypt
170
+
value:contentToDecrypt
172
171
};
173
172
174
173
```
@@ -178,7 +177,7 @@ const decryptField={
178
177
The value attribute in an element can also be an object containing some styling information:
179
178
180
179
```JavaScript
181
-
constinfoField={
180
+
constinfoField={
182
181
id:"title",
183
182
type:"info",
184
183
value: {
@@ -194,12 +193,12 @@ const infoField={
194
193
You can display a multi-line text using an array for ```content```:
195
194
196
195
```JavaScript
197
-
constinformationField={
198
-
id:"informationText",
199
-
type:"info",
200
-
value: {
201
-
type:"view",
202
-
style: {
196
+
constinformationField={
197
+
id:"informationText",
198
+
type:"info",
199
+
value: {
200
+
type:"view",
201
+
style: {
203
202
borderColor:"#rgba(72,128,237,0.5)",
204
203
backgroundColor:"#rgba(72,128,237,0.5)",
205
204
borderWidth:1,
@@ -238,20 +237,20 @@ Finally, the examples in the [website](https://globalinput.co.uk/), and tests in
238
237
As discussed previously, in order to connect to a device application, your mobile app needs to obtain the value of```connectionCode``` through scanning a QRCode. Then, you can pass it to the ```connect()```function to connect to your device application as its second parameter:
239
238
240
239
```JavaScript
241
-
const mobileConnector=createMessageConnector();
242
-
const {initData} =awaitmobileConnector.connect({
243
-
onInput:(inputMessage)=>{
240
+
const mobileConnector = createMessageConnector();
241
+
const {initData} =awaitmobileConnector.connect({
242
+
onInput:(inputMessage)=>{
244
243
....
245
244
}
246
-
},connectionCode);
245
+
},connectionCode);
247
246
```
248
247
In the above code, ```initData``` contains a ```form``` provided by the connected device application, while ```onInput()``` function is called whenever a message is received from the device application.
249
248
250
249
You can also send messages to the device application, responding to the events generated when the user interacts with form elements:
There are two input parameters required for calling ```mobileConnector.sendValue()``` function: the first one identifies the target element that the value is being sent to, while the second parameter holds the value needs to be sent across.
0 commit comments