Skip to content

Commit e72b454

Browse files
authored
Merge pull request #42 from JodusNodus/ios11-fix
Version 2.0.0 with ios11 support
2 parents cd94a6b + 1cfe06b commit e72b454

File tree

8 files changed

+12485
-197
lines changed

8 files changed

+12485
-197
lines changed

README.md

Lines changed: 28 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ A [React](https://facebook.github.io/react/) component for reading QR codes from
88

99
## Known Issues
1010
- Due to browser implementations the camera can only be accessed over https or localhost.
11-
- Not compatible with macOS/iOS Safari. Use `legacyMode` to support these platforms.
1211
- In Firefox a prompt will be shown to the user asking which camera to use, so `facingMode` will not affect it.
1312

1413
## Install
@@ -24,33 +23,29 @@ class Test extends Component {
2423
constructor(props){
2524
super(props)
2625
this.state = {
27-
delay: 100,
26+
delay: 300,
2827
result: 'No result',
2928
}
30-
3129
this.handleScan = this.handleScan.bind(this)
3230
}
3331
handleScan(data){
34-
this.setState({
35-
result: data,
36-
})
32+
if(data){
33+
this.setState({
34+
result: data,
35+
})
36+
}
3737
}
3838
handleError(err){
3939
console.error(err)
4040
}
4141
render(){
42-
const previewStyle = {
43-
height: 240,
44-
width: 320,
45-
}
46-
4742
return(
4843
<div>
4944
<QrReader
5045
delay={this.state.delay}
51-
style={previewStyle}
5246
onError={this.handleError}
5347
onScan={this.handleScan}
48+
style={{ width: '100%' }}
5449
/>
5550
<p>{this.state.result}</p>
5651
</div>
@@ -60,74 +55,25 @@ class Test extends Component {
6055
```
6156

6257
## Props
58+
### Events
59+
| Prop | Argument | Description
60+
|-------------|------------------|-------------
61+
| onScan | `result` | Scan event handler. Called every scan with the decoded value or `null` if no QR code was found.
62+
| onError | `Error` | Called when an error occurs.
63+
| onLoad | none | Called when the component is ready for use.
64+
| onImageLoad | img onLoad event | Called when the image in legacyMode is loaded.
65+
66+
### Options
67+
| Prop | Type | Default | Description
68+
|----------------|-------------------------|---------------|-------------
69+
| delay | number or `false` | `500` | The delay between scans in milliseconds. To disable the interval pass in `false`.
70+
| facingMode | `user` or `environment` | `environment` | Specify which camera should be used (if available).
71+
| resolution | number | `600` | The resolution of the video (or image in legacyMode). Larger resolution will increase the accuracy but it will also slow down the processing time.
72+
| style | a valid React style | none | Styling for the container element. **Warning** The preview will always keep its 1:1 aspect ratio.
73+
| className | string | none | ClassName for the container element.
74+
| showViewFinder | boolean | `true` | Show or hide the build in view finder. See demo
75+
| legacyMode | boolean | `false` | If the device does not allow camera access (e.g. IOS Browsers, Safari) you can enable legacyMode to allow the user to take a picture (On a mobile device) or use an existing one. To trigger the image dialog just call the method `openImageDialog` from the parent component. **Warning** You must call the method from a user action (eg. click event on some element).
6376

64-
**onScan**
65-
66-
Type: `function`, Required, Argument: `result`
67-
68-
Scan event handler. Called every scan with the decoded value or `null` if no QR code was found.
69-
70-
**onError**
71-
72-
Type: `function`, Required, Argument: `error`
73-
74-
Function to call when an error occurs such as:
75-
- Not supported platform
76-
- The lack of available devices
77-
78-
**onLoad**
79-
80-
Type: `function`, Optional
81-
82-
Called when the component is ready for use.
83-
84-
**onImageLoad**
85-
86-
Type: `function`, Optional, Argument: React img onLoad event
87-
88-
Called when the image in legacyMode is loaded.
89-
90-
**delay**
91-
92-
Type: `number`, Optional, Default: `500`
93-
94-
The delay between scans in milliseconds. To disable the interval pass in `false`.
95-
96-
**facingMode**
97-
98-
Type: `string`, Optional
99-
100-
Specify which camera direction should be used (if available). Options: `front` and `rear`.
101-
102-
**legacyMode**
103-
104-
Type: `boolean`, Optional, Default: `false`.
105-
106-
If the device does not allow camera access (e.g. IOS Browsers, Safari) you can enable legacyMode to allow the user to take a picture (On a mobile device) or use an existing one. To trigger the image dialog just call the method `openImageDialog` from the parent component. **Warning** You must call the method from a user action (eg. click event on some element).
107-
108-
**maxImageSize**
109-
110-
Type: `number`, Optional, Default: `1500`.
111-
112-
If `legacyMode` is active then the image will be downscaled to the given value while keepings its aspect ratio. Allowing larger images will increase the accuracy but it will also slow down the processing time.
113-
114-
**style**
115-
116-
Type: `object`, Optional
117-
118-
Styling for the preview element. This will be a `video` or an `img` when `legacymode` is `true`. **Warning** The preview will keep its aspect ratio, to disable this set the CSS property [objectFit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) to `fill`.
119-
120-
**className**
121-
122-
Type: `string`, Optional
123-
124-
ClassName for the container element.
125-
126-
**chooseDeviceId**
127-
128-
Type: `function`, Optional, Arguments: (1) video devices matching `facingMode`, (2) all video devices
129-
130-
Called when choosing which device to use for scanning. By default chooses the first video device matching `facingMode`, if no devices match the first video device found is choosen.
13177

13278
## Dev
13379

@@ -140,15 +86,13 @@ Called when choosing which device to use for scanning. By default chooses the fi
14086
### Demo
14187
`npm run storybook`
14288

143-
### Test
144-
`npm test`
145-
14689
### Linting
14790
`npm run lint`
14891

14992
## Tested platforms
150-
- Chrome 56 and Firefox 53 on macOs 10.12
151-
- Chrome 55 and Firefox 50 on Android 6.0.1
93+
- Chrome macOs & Android
94+
- Firefox macOs & Android
95+
- Safari macOs & IOS
15296

15397
## License
15498
The MIT License (MIT)

lib/getDeviceId.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function defaultDeviceIdChooser(filteredDevices, videoDevices, facingMode) {
77
if (filteredDevices.length > 0) {
88
return filteredDevices[0].deviceId;
99
}
10-
if (videoDevices.length == 0 || facingMode == 'front') {
10+
if (videoDevices.length == 1 || facingMode == 'front') {
1111
return videoDevices[0].deviceId;
1212
}
1313
return videoDevices[1].deviceId;
@@ -33,10 +33,6 @@ module.exports = function getDeviceId(facingMode) {
3333
if (videoDevices.length < 1) {
3434
reject(new NoVideoInputDevicesError());
3535
return;
36-
} else if (videoDevices.length == 1) {
37-
// Only 1 video device available thus stop here
38-
resolve(devices[0].deviceId);
39-
return;
4036
}
4137

4238
var pattern = facingMode == 'rear' ? /rear|back|environment/ig : /front|user|face/ig;

lib/index.js

Lines changed: 109 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)