Skip to content

Instantly share code, notes, and snippets.

@dceddia
dceddia / App.js
Created Jun 15, 2018
Timers trigger more timers.
View App.js
takePicture = () => {
this.camera.takePictureAsync({
quality: 0.1,
base64: true,
exif: false
}).then(photo => {
this.setState({ photo });
// In 27 seconds, turn the camera back on
setTimeout(() => {
@dceddia
dceddia / App.js
Created Jun 15, 2018
Initialize Autoshoot's state
View App.js
class Autoshoot extends React.Component {
state = {
photo: null
}
...
}
@dceddia
dceddia / App.js
Created Jun 15, 2018
Creating the Autoshoot component to render the Camera.
View App.js
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>
@dceddia
dceddia / App.js
Created Jun 15, 2018
Expo-generated App.js file
View App.js
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>
);
@dceddia
dceddia / App.js
Created Jun 15, 2018
Add the takePicture method
View App.js
takePicture = () => {
this.camera.takePictureAsync({
quality: 0.1,
base64: true,
exif: false
}).then(photo => {
this.setState({ photo });
})
}
@dceddia
dceddia / App.js
Created Jun 15, 2018
Upload each picture as it is taken
View App.js
// 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);
}
@dceddia
dceddia / App.js
Created Jun 15, 2018
Importing Camera and rendering based on permissions.
View App.js
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
@dceddia
dceddia / App.js
Created Jun 15, 2018
Using Autoshoot inside App
View App.js
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>
@dceddia
dceddia / App.js
Created Jun 15, 2018
Render the Camera, or the last photo.
View App.js
render() {
const { photo } = this.state;
return (
<View style={{ flex: 1, width: '100%' }}>
{photo ? (
<ImageBackground
style={{ flex: 1 }}
source={{ uri: photo.uri }} />
) : (
View Counter.js
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' });
You can’t perform that action at this time.