Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
parity-signer
Commits
9faf854f
Commit
9faf854f
authored
Apr 13, 2017
by
Tomasz Drwięga
Committed by
Marek Kotewicz
Apr 13, 2017
Browse files
Disable Camera when the screen is not active. (#61)
parent
5531f170
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/components/QrScanner.js
View file @
9faf854f
...
...
@@ -23,24 +23,44 @@ import AppStyles from '../styles'
export
default
class
Scanner
extends
Component
{
static
propTypes
=
{
onBarCodeRead
:
PropTypes
.
func
.
isRequired
onBarCodeRead
:
PropTypes
.
func
.
isRequired
,
isActive
:
PropTypes
.
bool
.
isRequired
}
render
()
{
if
(
!
this
.
props
.
isActive
)
{
return
(
<
View
style
=
{[
AppStyles
.
view
,
styles
.
view
]}
>
<
StatusBar
barStyle
=
'
light-content
'
/>
{
this
.
renderRects
()
}
<
/View
>
)
}
return
(
<
Camera
onBarCodeRead
=
{
this
.
props
.
onBarCodeRead
}
style
=
{
AppStyles
.
view
}
>
<
StatusBar
barStyle
=
'
light-content
'
/>
<
View
style
=
{
styles
.
rectangleContainer
}
>
<
View
style
=
{
styles
.
rectangle
}
>
<
View
style
=
{
styles
.
innerRectangle
}
/
>
<
/View
>
<
/View
>
{
this
.
renderRects
()
}
<
/Camera
>
)
}
renderRects
()
{
return
(
<
View
style
=
{
styles
.
rectangleContainer
}
>
<
View
style
=
{
styles
.
rectangle
}
>
<
View
style
=
{
styles
.
innerRectangle
}
/
>
<
/View
>
<
/View
>
)
}
}
const
styles
=
StyleSheet
.
create
({
view
:
{
backgroundColor
:
'
black
'
},
rectangleContainer
:
{
flex
:
1
,
alignItems
:
'
center
'
,
...
...
src/containers/QrScanner.js
View file @
9faf854f
...
...
@@ -20,15 +20,18 @@ import { connect } from 'react-redux'
import
QrScanner
from
'
../components/QrScanner
'
import
{
scannerDispatch
}
from
'
../actions/scanner
'
const
mapDispatchToProps
=
(
dispatch
,
ownProps
)
=>
({
onBarCodeRead
:
(
scanned
)
=>
{
dispatch
(
scannerDispatch
(
scanned
.
data
))
}
})
const
QrScannerContainer
=
connect
(
undefined
,
mapDispatchToProps
(
state
,
...
args
)
=>
{
const
{
name
}
=
state
.
routes
.
scene
return
{
isActive
:
name
===
'
qrScan
'
||
name
===
'
tabs
'
}
},
(
dispatch
,
ownProps
)
=>
({
onBarCodeRead
:
(
scanned
)
=>
{
dispatch
(
scannerDispatch
(
scanned
.
data
))
}
})
)(
QrScanner
)
export
default
QrScannerContainer
src/reducers/routes.js
View file @
9faf854f
...
...
@@ -18,7 +18,13 @@
import
{
ActionConst
}
from
'
react-native-router-flux
'
export
default
function
reducer
(
state
=
{},
{
type
,
scene
})
{
const
initialState
=
{
scene
:
{
name
:
'
qrScan
'
}
}
export
default
function
reducer
(
state
=
initialState
,
{
type
,
scene
})
{
switch
(
type
)
{
case
ActionConst
.
FOCUS
:
return
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment