2018-09-23 18:40:18 -04:00
|
|
|
import React, { Component } from 'react'
|
2020-03-12 02:27:37 -04:00
|
|
|
import {
|
|
|
|
|
StyleSheet,
|
|
|
|
|
View,
|
|
|
|
|
Text,
|
|
|
|
|
TouchableOpacity,
|
|
|
|
|
ViewProps,
|
|
|
|
|
} from 'react-native'
|
2018-09-23 18:40:18 -04:00
|
|
|
import withCacheBust from './withCacheBust'
|
2020-07-16 23:31:44 -04:00
|
|
|
import { FastImage, FastImageProps, Source } from 'react-native-fast-image'
|
2018-09-23 18:40:18 -04:00
|
|
|
import Section from './Section'
|
|
|
|
|
import FeatureText from './FeatureText'
|
2020-03-12 02:27:37 -04:00
|
|
|
import FieldsBase64 from './images/fields'
|
2018-09-23 18:40:18 -04:00
|
|
|
import ImagePicker from 'react-native-image-picker'
|
|
|
|
|
import BulletText from './BulletText'
|
|
|
|
|
|
2020-03-12 02:27:37 -04:00
|
|
|
// @ts-ignore
|
|
|
|
|
import FieldsImage from './images/fields.jpg'
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
import FieldsWebP from './images/fields.webp'
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
import JellyfishGIF from './images/jellyfish.gif'
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
import JellyfishWebP from './images/jellyfish.webp'
|
|
|
|
|
|
2019-02-22 00:37:12 -05:00
|
|
|
const options = {
|
2018-09-23 18:40:18 -04:00
|
|
|
title: 'Select Avatar',
|
|
|
|
|
customButtons: [{ name: 'fb', title: 'Choose Photo from Facebook' }],
|
|
|
|
|
storageOptions: {
|
|
|
|
|
skipBackup: true,
|
|
|
|
|
path: 'images',
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 02:27:37 -04:00
|
|
|
const Image = ({ source, ...p }: FastImageProps) => (
|
2018-09-23 18:40:18 -04:00
|
|
|
<FastImage style={styles.imageSquare} source={source} {...p} />
|
|
|
|
|
)
|
|
|
|
|
|
2020-03-12 02:27:37 -04:00
|
|
|
const Row: React.ComponentType<ViewProps> = (p: ViewProps) => (
|
|
|
|
|
<View style={styles.row} {...p} />
|
|
|
|
|
)
|
2018-09-23 18:40:18 -04:00
|
|
|
|
2020-03-12 02:27:37 -04:00
|
|
|
interface ExampleProps {
|
|
|
|
|
name: string
|
|
|
|
|
source: any
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Example = ({ name, source }: ExampleProps) => (
|
2019-02-24 19:52:11 -05:00
|
|
|
<Row>
|
|
|
|
|
<BulletText>{name}</BulletText>
|
|
|
|
|
<Image source={source} />
|
|
|
|
|
</Row>
|
|
|
|
|
)
|
|
|
|
|
|
2020-03-12 02:27:37 -04:00
|
|
|
interface PhotoExampleState {
|
|
|
|
|
image?: Source
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PhotoExample extends Component<{}, PhotoExampleState> {
|
|
|
|
|
state: PhotoExampleState = {}
|
2018-09-23 18:40:18 -04:00
|
|
|
|
|
|
|
|
pick = () => {
|
|
|
|
|
ImagePicker.showImagePicker(options, response => {
|
|
|
|
|
if (response.didCancel) {
|
2020-03-01 15:58:28 -05:00
|
|
|
console.log('ImagePicker - User cancelled.')
|
2018-09-23 18:40:18 -04:00
|
|
|
} else if (response.error) {
|
2020-03-01 15:58:28 -05:00
|
|
|
console.log(`ImagePicker - Error ${response.error}.`)
|
2018-09-23 18:40:18 -04:00
|
|
|
} else if (response.customButton) {
|
2020-03-01 15:58:28 -05:00
|
|
|
console.log(`ImagePicker - Tapped ${response.customButton}`)
|
2018-09-23 18:40:18 -04:00
|
|
|
} else {
|
|
|
|
|
const uri = response.uri
|
|
|
|
|
this.setState({
|
|
|
|
|
image: { uri: uri },
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<Row>
|
|
|
|
|
<BulletText>photo library</BulletText>
|
|
|
|
|
<TouchableOpacity onPress={this.pick}>
|
2020-03-12 02:27:37 -04:00
|
|
|
<Image
|
|
|
|
|
style={styles.imageSquare}
|
|
|
|
|
source={this.state.image || 0}
|
|
|
|
|
>
|
2020-03-01 15:58:28 -05:00
|
|
|
<Text style={styles.pickPhoto}>Pick Photo</Text>
|
2018-09-23 18:40:18 -04:00
|
|
|
</Image>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</Row>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-24 19:52:11 -05:00
|
|
|
const LocalImagesExample = () => (
|
2018-09-23 18:40:18 -04:00
|
|
|
<View>
|
|
|
|
|
<Section>
|
|
|
|
|
<FeatureText>• Local images.</FeatureText>
|
|
|
|
|
</Section>
|
|
|
|
|
<View style={styles.container}>
|
2019-02-24 19:52:11 -05:00
|
|
|
<Example name="Require" source={require('./images/fields.jpg')} />
|
|
|
|
|
<Example name="Import" source={FieldsImage} />
|
|
|
|
|
<Example name="GIF" source={JellyfishGIF} />
|
|
|
|
|
<Example name="Animated WebP" source={JellyfishWebP} />
|
|
|
|
|
<Example name="Base64" source={{ uri: FieldsBase64 }} />
|
|
|
|
|
<Example name="WebP" source={FieldsWebP} />
|
2018-09-23 18:40:18 -04:00
|
|
|
<PhotoExample />
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2020-03-01 15:58:28 -05:00
|
|
|
pickPhoto: { color: 'white', fontWeight: '900' },
|
2018-09-23 18:40:18 -04:00
|
|
|
row: {
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
marginBottom: 20,
|
|
|
|
|
},
|
|
|
|
|
container: {
|
|
|
|
|
backgroundColor: '#eee',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
paddingTop: 10,
|
|
|
|
|
paddingBottom: 10,
|
|
|
|
|
},
|
|
|
|
|
imageSquare: {
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
height: 100,
|
|
|
|
|
backgroundColor: '#ddd',
|
|
|
|
|
margin: 20,
|
|
|
|
|
marginTop: 10,
|
|
|
|
|
width: 100,
|
|
|
|
|
flex: 0,
|
|
|
|
|
},
|
|
|
|
|
plus: {
|
|
|
|
|
width: 30,
|
|
|
|
|
height: 30,
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
bottom: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default withCacheBust(LocalImagesExample)
|