Skip to content

Commit b704122

Browse files
fix: fix warning when decode selected photo
1 parent fd9c8dd commit b704122

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

BarcodeReaderSimpleSample/BarcodeScanner.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const modalInitState = {
3636
};
3737

3838
class BarcodeScanner extends React.Component {
39+
ifDecodingFile = false;
3940
state = {
4041
results: null,
4142
isVisible: false,
@@ -52,10 +53,11 @@ class BarcodeScanner extends React.Component {
5253
.catch(err => {
5354
console.log(err);
5455
});
55-
56+
this.ifDecodingFile = true;
5657
imagePickerLauncher(option, res => {
5758
if (res.didCancel) {
5859
// this.setState(modalInitState);
60+
this.ifDecodingFile = false;
5961
return false;
6062
}
6163
this.decodeFile(res.assets[0].uri.split('file://')[1])
@@ -67,7 +69,10 @@ class BarcodeScanner extends React.Component {
6769
console.log(err);
6870
this.setState({isVisible: true, modalText: err.toString()});
6971
})
70-
.finally(this.initSettingForVideo(this.reader));
72+
.finally(() => {
73+
this.initSettingForVideo(this.reader);
74+
this.ifDecodingFile = false;
75+
});
7176
});
7277
};
7378

@@ -99,7 +104,9 @@ class BarcodeScanner extends React.Component {
99104
// Add a result listener. The result listener will handle callback when barcode result is returned.
100105
this.reader.addResultListener(results => {
101106
// Update the newly detected barcode results to the state.
102-
this.setState({results: results});
107+
if (!this.ifDecodingFile) {
108+
this.setState({results: results});
109+
}
103110
});
104111

105112
// Enable video barcode scanning.

0 commit comments

Comments
 (0)