Commit 9faf854f authored by Tomasz Drwięga's avatar Tomasz Drwięga Committed by Marek Kotewicz
Browse files

Disable Camera when the screen is not active. (#61)

parent 5531f170
......@@ -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',
......
......@@ -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
......@@ -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 {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment