Skip to content

Instantly share code, notes, and snippets.

@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
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
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
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
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
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 / server.js
Created Jun 15, 2018
Handle GET requests
View server.js
// View latest image
app.get('/', (req, res) => {
// Does this session have an image yet?
if(!latestPhoto) {
return res.status(404).send("Nothing here yet");
}
console.log('sending photo');
try {
@dceddia
dceddia / server.js
Created Jun 15, 2018
Bare bones Express server
View server.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
// If your phone has a modern camera (unlike my iPhone 4S)
// you might wanna make this bigger.
app.use(bodyParser.json({ limit: '10mb' }));
// TODO: handle requests
@dceddia
dceddia / App.js
Created Jun 15, 2018
Upload pictures to the server
View App.js
uploadPicture = () => {
return fetch(SERVER_URL, {
body: JSON.stringify({
image: this.state.photo.base64
}),
headers: {
'content-type': 'application/json'
},
method: 'POST'
})
@dceddia
dceddia / App.js
Created Jun 15, 2018
Adding a button to take the picture
View App.js
render() {
const { photo } = this.state;
return (
<Camera
style={{ flex: 1 }}
type={Camera.Constants.Type.back}
ref={cam => this.camera = cam}>
<TouchableOpacity
style={{ flex: 1 }}
You can’t perform that action at this time.