Skip to content

Commit 8618dad

Browse files
committed
Merge branch 'feature/rfid-scan-button'
2 parents c6d36f1 + ce2ad20 commit 8618dad

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

examples/react-chayns-rfid_input/Example.jsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,27 @@ export default class Example extends React.Component {
2323
};
2424

2525
render() {
26-
return(
26+
const { rfid, rfidInput } = this.state;
27+
28+
return (
2729
<ExampleContainer headline="RFID Input">
2830
<h3>RFID-Live</h3>
29-
<p>{this.state.rfidInput || '-'}</p>
31+
<p>{rfidInput || '-'}</p>
3032
<h3>RFID</h3>
31-
<p>{this.state.rfid || '-'}</p>
33+
<p>{rfid || '-'}</p>
34+
35+
<RfidInput
36+
onConfirm={this.onConfirm}
37+
onInput={this.onInput}
38+
value={rfidInput}
39+
enableScan={RfidInput.isNfcAvailable()}
40+
/>
3241

3342
<RfidInput
3443
onConfirm={this.onConfirm}
3544
onInput={this.onInput}
36-
value={this.state.rfidInput}
37-
enableScan={chayns.env.isApp && chayns.env.isAndroid}
45+
value={rfidInput}
46+
enableScan
3847
/>
3948
</ExampleContainer>
4049
);

src/react-chayns-rfid_input/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ You can use the input like this:
2929
## RfidInput.pretifyRfid
3030
A static function to set a space after every second character.
3131

32+
## RfidInput.isNfcAvailable
33+
A static function which checks with a whitelist, whether the current app could support nfc-scans.
34+
3235
## Props
3336
The following properties can be set on the RfidInput-Component
3437

src/react-chayns-rfid_input/component/RfidInput.jsx

+22-13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export default class RfidInput extends React.Component {
3333
scanText: 'Scannen',
3434
};
3535

36+
static isNfcAvailable() {
37+
return (chayns.env.isMyChaynsApp && (chayns.env.isAndroid || (chayns.env.isIOS && chayns.env.appVersion >= 5764)))
38+
|| (chayns.env.isApp && (chayns.env.isAndroid));
39+
}
40+
3641
state = {
3742
isScanning: false,
3843
};
@@ -90,8 +95,12 @@ export default class RfidInput extends React.Component {
9095
value,
9196
} = this.props;
9297
const { isScanning } = this.state;
93-
const classNames = classnames(className, 'cc__rfid-input');
98+
99+
const classNames = classnames(className, 'cc__rfid-input', {
100+
'cc__rfid-input--enable-scan': enableScan,
101+
});
94102
const disabled = !VALID_RFID.test(value);
103+
95104
return(
96105
<div className={classNames}>
97106
<div className="cc__rfid-input__wrapper">
@@ -104,24 +113,24 @@ export default class RfidInput extends React.Component {
104113
autoCapitalize="off"
105114
spellCheck="false"
106115
/>
107-
<ChooseButton
108-
onClick={this.onConfirm}
109-
disabled={disabled}
110-
className="cc__rfid-input__confirm"
111-
>
112-
{confirmNode}
113-
</ChooseButton>
114-
</div>
115-
{enableScan && (
116-
<div className="cc__rfid-input__control">
116+
{enableScan && !value && (
117117
<ChooseButton
118118
onClick={isScanning ? this.endScan : this.startScan}
119119
className="cc__rfid-input__scan"
120120
>
121121
{scanText}
122122
</ChooseButton>
123-
</div>
124-
)}
123+
)}
124+
{(!enableScan || value) && (
125+
<ChooseButton
126+
onClick={this.onConfirm}
127+
disabled={disabled}
128+
className="cc__rfid-input__confirm"
129+
>
130+
{confirmNode}
131+
</ChooseButton>
132+
)}
133+
</div>
125134
</div>
126135
);
127136
}

src/react-chayns-rfid_input/index.scss

+7
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@
1111
text-align: center;
1212
margin: 15px 0;
1313
}
14+
15+
&--enable-scan {
16+
.cc__rfid-input__scan, .cc__rfid-input__confirm {
17+
width: 52px;
18+
box-sizing: content-box;
19+
}
20+
}
1421
}

0 commit comments

Comments
 (0)