해당 코드입니다
export class AddCarScreen extends React.Component {
constructor(props) {
super(props);
this.state = {
refreshing: false,
image: null,
image2: null
};
}
static navigationOptions = ({ navigation }) => {
const params = navigation.state.params || {};
return {
title: "Add Car"
};
};
//이미지 불러오기 함수
_pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [4, 3]
});
alert(result.uri);
console.log(result);
if (!result.cancelled) {
this.setState({ image: result.uri });
}
};
// 파일등 여러가지 불러오기 함수
_pickDocument = async () => {
let result = await DocumentPicker.getDocumentAsync({
type: "image/*",
copyToCacheDirectory: true
});
alert(result.uri);
console.log(result);
if (!result.cancelled) {
this.setState({ image2: result.uri });
}
};
render() {
let { image } = this.state;
let { image2 } = this.state;
return (
<View style={styles.container}>
<View style={{ alignItems: "center", paddingBottom: 50 }}>
{image && (
<Image
source={{ uri: image }}
style={{ width: "70%", height: 250, resizeMode: "stretch" }}
/>
)}
<Button title="사진 불러오기" onPress={this._pickImage} />
<Button title="Select Document" onPress={this._pickDocument} />
{image2 && (
<Image
source={{ uri: image2 }}
style={{ width: "70%", height: 100, resizeMode: "stretch" }}
/>
)}
</View>
<View
style={{ flexDirection: "row", alignItems: "center", padding: 5 }}
>
<Text
style={{
fontSize: 18,
justifyContent: "center",
alignItems: "center",
width: "20%",
color: "#fff"
}}
>
Vin:
</Text>
<TextInput
secureTextEntry={true}
style={{
backgroundColor: "#fff",
borderColor: "#fff",
borderRadius: 15,
borderWidth: 2,
height: 40,
width: "70%",
paddingHorizontal: 10
}}
placeholder="Vin 넘버를 입력하세요"
/>
</View>
<View
style={{ flexDirection: "row", alignItems: "center", padding: 5 }}
>
<Text
style={{
fontSize: 18,
justifyContent: "center",
alignItems: "center",
width: "20%",
color: "#fff"
}}
>
Model:
</Text>
<TextInput
secureTextEntry={true}
style={{
backgroundColor: "#fff",
borderColor: "#fff",
borderRadius: 15,
borderWidth: 2,
height: 40,
width: "70%",
paddingHorizontal: 10
}}
placeholder="Model명를 입력하세요"
/>
</View>
<View
style={{ flexDirection: "row", alignItems: "center", padding: 5 }}
>
<Text
style={{
fontSize: 18,
justifyContent: "center",
alignItems: "center",
width: "20%",
color: "#fff"
}}
>
차량회사:
</Text>
<TextInput
secureTextEntry={true}
style={{
backgroundColor: "#fff",
borderColor: "#fff",
borderRadius: 15,
borderWidth: 2,
height: 40,
width: "70%",
paddingHorizontal: 10
}}
placeholder="차량 회사명을 입력하세요"
/>
</View>
<View
style={{ flexDirection: "row", alignItems: "center", padding: 5 }}
>
<Text
style={{
fontSize: 18,
justifyContent: "center",
alignItems: "center",
width: "20%",
color: "#fff"
}}
>
year:
</Text>
<TextInput
secureTextEntry={true}
style={{
backgroundColor: "#fff",
borderColor: "#fff",
borderRadius: 15,
borderWidth: 2,
height: 40,
width: "70%",
paddingHorizontal: 10
}}
placeholder="차량 연식을 입력하세요"
keyboardType="number-pad"
/>
</View>
<View
style={{ flexDirection: "row", alignItems: "center", padding: 5 }}
>
<Text
style={{
fontSize: 18,
justifyContent: "center",
alignItems: "center",
width: "20%",
color: "#fff"
}}
>
image:
</Text>
<TouchableOpacity
style={[
{
width: "10%",
height: 30,
borderColor: "#fff",
borderWidth: 1,
borderRadius: 10,
alignItems: "center",
justifyContent: "center",
backgroundColor: "#fff"
}
]}
onPress={() => {}}
>
<Ionicons name={"ios-add"} size={35} color={"gray"} />
</TouchableOpacity>
</View>
<View style={{ alignItems: "center", padding: 5 }}>
<TouchableOpacity
style={{
width: "100%",
height: 30,
borderColor: "#fff",
borderWidth: 1,
borderRadius: 10,
alignItems: "center",
justifyContent: "center",
backgroundColor: "#74b9ff"
}}
onPress={() => {}}
>
<Text style={{ fontSize: 17, color: "#fff" }}> 차량 추가</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#74b9ff",
justifyContent: "center"
}
});
이 코드가 이미지 불러오는 코드인데 안드로이드는 되는데 아이폰에서 되질 않습니다.