This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function brokenReducer(state = initialState, action) { | |
switch(action.type) { | |
case 'INCREMENT': | |
// NO! BAD: this is changing state! | |
state.count++; | |
return state; | |
case 'DECREMENT': | |
// NO! BAD: this is changing state too! | |
state.count--; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { connect } from 'react-redux'; | |
class Counter extends React.Component { | |
increment = () => { | |
this.props.dispatch({ type: 'INCREMENT' }); | |
} | |
decrement = () => { | |
this.props.dispatch({ type: 'DECREMENT' }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render() { | |
const { photo } = this.state; | |
return ( | |
<View style={{ flex: 1, width: '100%' }}> | |
{photo ? ( | |
<ImageBackground | |
style={{ flex: 1 }} | |
source={{ uri: photo.uri }} /> | |
) : ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render() { | |
const { cameraPermission } = this.state; | |
// Render one of 3 things depending on permissions | |
return ( | |
<View style={styles.container}> | |
{cameraPermission === null ? ( | |
<Text>Waiting for permission...</Text> | |
) : cameraPermission === false ? ( | |
<Text>Permission denied</Text> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { StyleSheet, Text, View } from 'react-native'; | |
// add this: | |
import { Camera, Permissions } from 'expo'; | |
export default class App extends React.Component { | |
// initialize state | |
state = { | |
cameraPermission: null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here's the timer code, lifted from takePicture: | |
queuePhoto = () => { | |
// In 27 seconds, turn the camera back on | |
setTimeout(() => { | |
this.setState({ photo: null }); | |
}, PHOTO_INTERVAL - FOCUS_TIME); | |
// In 30 seconds, take the next picture | |
setTimeout(this.takePicture, PHOTO_INTERVAL); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
takePicture = () => { | |
this.camera.takePictureAsync({ | |
quality: 0.1, | |
base64: true, | |
exif: false | |
}).then(photo => { | |
this.setState({ photo }); | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { StyleSheet, Text, View } from 'react-native'; | |
export default class App extends React.Component { | |
render() { | |
return ( | |
<View style={styles.container}> | |
<Text>Open up App.js to start working on your app!</Text> | |
</View> | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Autoshoot extends React.Component { | |
render() { | |
return ( | |
<View style={{ flex: 1, width: '100%' }}> | |
<Camera | |
style={{ flex: 1 }} | |
type={Camera.Constants.Type.back} | |
ref={cam => this.camera = cam}> | |
</Camera> | |
</View> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Autoshoot extends React.Component { | |
state = { | |
photo: null | |
} | |
... | |
} |