OptionChoose.js 2.87 KB
import React from "react"
import {View, StyleSheet, Text, Image, TouchableWithoutFeedback, TouchableOpacity} from "react-native"
import {line} from "./AddChildrenTask";
import ImagePicker from 'react-native-image-crop-picker';

const styles = StyleSheet.create({
	container: {
		flex: 1,
		justifyContent: 'flex-end',
		backgroundColor: "rgba(0,0,0,0.5)"
	},
	content: {
		paddingHorizontal: 10,
		paddingBottom: 10,
	},
	chooseView: {
		height: 158,
		backgroundColor: 'white',
		borderRadius: 8,
		overflow: 'hidden',
		marginBottom: 10,
	},
	titleView: {
		borderTopLeftRadius: 8,
		borderTopRightRadius: 8,
		height: 45,
		borderBottomWidth: line,
		borderBottomColor: "#999999",
		alignItems: 'center',
		justifyContent: 'center',
	},
	title: {
		color: "#999999",
		fontSize: 14,
	},
	library: {
		height: 57,
		borderBottomWidth: line,
		borderBottomColor: "#999999",
		alignItems: 'center',
		justifyContent: 'center',
	},
	text: {
		fontSize: 16,
		color: "#0071ff"
	},
	cameraView: {
		flex: 1,
		borderBottomLeftRadius: 8,
		borderBottomRightRadius: 8,
		alignItems: 'center',
		justifyContent: 'center',
	},
	cancelView: {
		height: 55,
		alignItems: 'center',
		justifyContent: 'center',
		borderRadius: 8,
		backgroundColor: 'white',
		overflow: 'hidden'
	}
})
export default class OptionChoose extends React.Component {
	back = () => {
		const {navigation} = this.props
		navigation.goBack()
	}
	openLibrary = async () => {
		try{
			const data = await ImagePicker.openPicker({
				multiple: true,
				compressImageQuality:0.1
			})
			console.log(data)
			const {state,goBack}=this.props.navigation
			state.params.onChange(data)
			// data.map(v=>state.params.onChange(v.sourceURL))
			goBack()
		}catch (e){
			console.log(e)
		}

	}
	openCamera = async () => {
		try{
			const data = await ImagePicker.openCamera({compressImageQuality:0.1})
			console.log(data)
			const {state,goBack}=this.props.navigation
			state.params.onChange(data)
			goBack()
		}catch(e){
			console.log(e)
		}

	}

	render() {
		return (
			<TouchableWithoutFeedback onPress={this.back}>
				<View style={styles.container}>
					<TouchableWithoutFeedback>
						<View style={styles.content}>
							<View style={styles.chooseView}>
								<TouchableOpacity style={styles.titleView}>
									<Text style={styles.title}>添加文件</Text>
								</TouchableOpacity>
								<TouchableOpacity style={styles.library} onPress={this.openLibrary}>
									<Text style={styles.text}>照片库</Text>
								</TouchableOpacity>
								<TouchableOpacity style={styles.cameraView} onPress={this.openCamera}>
									<Text style={styles.text}>相机</Text>
								</TouchableOpacity>
							</View>
							<TouchableOpacity style={styles.cancelView} onPress={this.back}>
								<Text style={styles.text}>取消</Text>
							</TouchableOpacity>
						</View>
					</TouchableWithoutFeedback>
				</View>
			</TouchableWithoutFeedback>
		)
	}
}