Run prettier.

This commit is contained in:
Dylan Vann 2017-04-18 01:52:09 -04:00
parent d36b4b5c4b
commit d36ad2d351
8 changed files with 71 additions and 86 deletions

View File

@ -1,33 +1,33 @@
// @flow
import React from 'react'
import {
TabNavigator,
TabView,
} from 'react-navigation';
import { TabNavigator, TabView } from 'react-navigation'
import FastImageExample from './FastImageExample'
import FastImageGrid from './FastImageGrid'
import DefaultImageGrid from './DefaultImageGrid'
const App = TabNavigator({
fastImageExample: {
screen: FastImageExample,
},
image: {
screen: DefaultImageGrid,
},
fastImage: {
screen: FastImageGrid,
},
}, {
tabBarComponent: TabView.TabBarBottom,
tabBarPosition: 'bottom',
swipeEnabled: false,
animationEnabled: false,
tabBarOptions: {
style: {
backgroundColor: 'white',
const App = TabNavigator(
{
fastImageExample: {
screen: FastImageExample,
},
image: {
screen: DefaultImageGrid,
},
fastImage: {
screen: FastImageGrid,
},
},
})
{
tabBarComponent: TabView.TabBarBottom,
tabBarPosition: 'bottom',
swipeEnabled: false,
animationEnabled: false,
tabBarOptions: {
style: {
backgroundColor: 'white',
},
},
},
)
export default App

View File

@ -4,13 +4,10 @@ import { Image } from 'react-native'
import Icon from 'react-native-vector-icons/Ionicons'
import ImageGrid from './ImageGrid'
const DefaultImageGrid = () =>
<ImageGrid
ImageComponent={Image}
/>
const DefaultImageGrid = () => <ImageGrid ImageComponent={Image} />
DefaultImageGrid.navigationOptions = {
tabBarLabel: "Image Grid",
tabBarLabel: 'Image Grid',
tabBarIcon: ({ focused, tintColor }) => {
if (focused) return <Icon name="ios-image" size={26} color={tintColor} />
return <Icon name="ios-image-outline" size={26} color={tintColor} />

View File

@ -1,12 +1,6 @@
// @flow
import React, { Component } from 'react'
import {
View,
Text,
StyleSheet,
ScrollView,
StatusBar,
} from 'react-native'
import { View, Text, StyleSheet, ScrollView, StatusBar } from 'react-native'
import Icon from 'react-native-vector-icons/Ionicons'
import FastImage from 'react-native-fast-image'
import timeout from 'react-timeout'
@ -32,17 +26,18 @@ class FastImageExample extends Component {
// Busting image cache.
const bust = `?bust=${key}`
return (
<View
style={styles.container}
key={key}
>
<StatusBar translucent barStyle="dark-content" backgroundColor="transparent" />
<View style={styles.container} key={key}>
<StatusBar
translucent
barStyle="dark-content"
backgroundColor="transparent"
/>
<ScrollView
style={styles.scrollContainer}
contentContainerStyle={styles.scrollContentContainer}
>
<View style={styles.textContainer} >
<Text style={styles.bold} >FastImage</Text>
<View style={styles.textContainer}>
<Text style={styles.bold}>FastImage</Text>
<Text> priority (low, normal, high)</Text>
<Text> authentication (token)</Text>
</View>
@ -87,8 +82,11 @@ FastImageExample = timeout(FastImageExample)
FastImageExample.navigationOptions = {
tabBarLabel: 'FastImage Example',
tabBarIcon: ({ focused, tintColor }) => {
if (focused) return <Icon name="ios-information-circle" size={26} color={tintColor} />
return <Icon name="ios-information-circle-outline" size={26} color={tintColor} />
if (focused)
return <Icon name="ios-information-circle" size={26} color={tintColor} />
return (
<Icon name="ios-information-circle-outline" size={26} color={tintColor} />
)
},
}

View File

@ -4,13 +4,10 @@ import FastImage from 'react-native-fast-image'
import Icon from 'react-native-vector-icons/Ionicons'
import ImageGrid from './ImageGrid'
const FastImageGrid = () =>
<ImageGrid
ImageComponent={FastImage}
/>
const FastImageGrid = () => <ImageGrid ImageComponent={FastImage} />
FastImageGrid.navigationOptions = {
tabBarLabel: "FastImage Grid",
tabBarLabel: 'FastImage Grid',
tabBarIcon: ({ focused, tintColor }) => {
if (focused) return <Icon name="ios-photos" size={26} color={tintColor} />
return <Icon name="ios-photos-outline" size={26} color={tintColor} />

View File

@ -1,22 +1,17 @@
// @flow
import React, { Component } from 'react'
import {
StyleSheet,
View,
FlatList,
Platform,
StatusBar,
} from 'react-native'
import { StyleSheet, View, FlatList, Platform, StatusBar } from 'react-native'
const getImageUrl = (id, width, height) => `https://unsplash.it/${width}/${height}?image=${id}`
const getImageUrl = (id, width, height) =>
`https://unsplash.it/${width}/${height}?image=${id}`
class ImageGrid extends Component {
constructor(props: Object) {
super(props)
fetch('https://unsplash.it/list')
.then(res => res.json())
.then(this._onFetchImagesSuccess)
.then(res => res.json())
.then(this._onFetchImagesSuccess)
}
state = {
@ -24,14 +19,14 @@ class ImageGrid extends Component {
itemHeight: 0,
}
_onLayout = (e) => {
_onLayout = e => {
const width = e.nativeEvent.layout.width
this.setState({
itemHeight: width / 4,
})
}
_onFetchImagesSuccess = (images) => {
_onFetchImagesSuccess = images => {
this.setState({
images,
})
@ -46,16 +41,13 @@ class ImageGrid extends Component {
const ImageComponent = this.props.ImageComponent
const uri = getImageUrl(item.id, 100, 100)
return (
<View style={styles.imageContainer} >
<ImageComponent
source={{ uri }}
style={styles.image}
/>
<View style={styles.imageContainer}>
<ImageComponent source={{ uri }} style={styles.image} />
</View>
)
}
_extractKey = (item) => {
_extractKey = item => {
return item.id
}
@ -65,7 +57,10 @@ class ImageGrid extends Component {
<FlatList
onLayout={this._onLayout}
style={styles.list}
columnWrapperStyle={[styles.columnWrapper, { height: this.state.itemHeight }]}
columnWrapperStyle={[
styles.columnWrapper,
{ height: this.state.itemHeight },
]}
data={this.state.images}
renderItem={this._renderItem}
numColumns={4}
@ -116,7 +111,7 @@ const styles = StyleSheet.create({
imageContainer: {
flex: 1,
alignItems: 'stretch',
}
},
})
export default ImageGrid

View File

@ -1,3 +1,3 @@
import { AppRegistry } from 'react-native';
import App from './App';
AppRegistry.registerComponent('FastImage', () => App);
import { AppRegistry } from 'react-native'
import App from './App'
AppRegistry.registerComponent('FastImage', () => App)

View File

@ -1,3 +1,3 @@
import { AppRegistry } from 'react-native';
import App from './App';
AppRegistry.registerComponent('FastImage', () => App);
import { AppRegistry } from 'react-native'
import App from './App'
AppRegistry.registerComponent('FastImage', () => App)

View File

@ -1,28 +1,26 @@
const path = require('path')
const express = require('express')
const bodyParser = require('body-parser')
const morgan = require('morgan')
const path = require('path')
const express = require('express')
const bodyParser = require('body-parser')
const morgan = require('morgan')
const app = express()
const app = express()
const port = process.env.PORT || 8080;
const port = process.env.PORT || 8080
const welcome = 'Test images API at http://localhost:' + port
console.log(welcome)
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(morgan('dev'))
app.get('/', (req, res) => res.send(welcome))
app.listen(port);
app.get('/', (req, res) => res.send(welcome))
app.listen(port)
const authentication = (req, res, next) => {
const token = req.query.token || req.headers['token']
if (token) {
next()
} else {
return res
.status(403)
.send({ success: false })
return res.status(403).send({ success: false })
}
}