Я новичок в firebase, в каждой моей функции он показывает какое-то предупреждение, например необработанное отклонение обещания, не уверенный, как именно это исправить. Предупреждение о pickImage:
[Отклонение необработанного обещания: ошибка типа: undefined не является функцией (рядом с '... ImagePicker.launchImageLibaryAsync ...')]
Вызывает также ошибку при вызове функции saveContact:
[Отклонение необработанного обещания: TypeError: firebase.storage.ref не является функцией. (В 'firebase.storage.ref ()' 'firebase.storage.ref' не определено)]
import React, { Component } from "react";
import {
View,
StyleSheet,
Text,
TouchableWithoutFeedback,
TouchableOpacity,
Keyboard,
KeyboardAvoidingView,
ScrollView,
ActivityIndicator,
Image
} from "react-native";
import uuid from 'uuid';
import { Form, Item, Input, Label, Button } from "native-base";3
import ImagePicker from "expo-image-picker";
import Promise from 'expo';
import { Header } from "react-navigation-stack";
import * as firebase from 'firebase';
export default class AddNewContactScreen extends Component {
static navigationOptions = {
title: "Add Contact"
};
constructor (props){
super(props);
this.state = {
fname : "",
lname : "",
phone : "",
email : "",
address : "",
image : "empty",
imageURL: "empty",
isUploading : false
}
}
//TODO: savecontact method
saveContact = async () => {
if(
this.state.fname !== "" &&
this.state.lname !== "" &&
this.state.email !== "" &&
this.state.phone !== "" &&
this.state.address !== ""
) {
this.setState({isUploading: false})
const dbReference = firebase.database().ref();
const storageRef = firebase.storage.ref();
if(this.state.image !== "empty"){
const downloadURL = await this.uploadImageAsync(this.state.image, storageRef);
this.setState({imageURL: downloadURL})
}
var contact = {
fname: this.state.fname,
lname: this.state.lname,
phone: this.state.phone,
email: this.state.email,
imageURL: this.state.imageURL
}
await dbReference.push(contact, error => {
if(!error){
return this.props.navigation.goBack();
}
})
}
};
// pick image from gallery
pickImage = async () => {
let result = await ImagePicker.launchImageLibaryAsync({
quality: 0.2,
base64: true,
allowEditing: true,
aspect: [1,1],
});
if(!result.cancelled){
this.setState({ image: result.uri })
}
};
uploadImageAsync = async (uri, storageRef) => {
const parts = uri.split(".");
const fileExtension = parts[parts.length -1]
//create blob
const blob = await new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.onload = function(){
resolve(xhr.response)
}
xhr.onerror = function(e){
console.log(e)
reject(new TypeError("Network Request Failed"))
};
xhr.responseType = "blob";
xhr.open("GET", uri, true);
xhr.send(null)
})
const ref = storageRef
.child("ContactImages")
.child(uuid.v4() + "." + fileExtension);
const snapshot = await ref.put(blob);
blob.close()
return await snapshot.ref.getDownloadURL()
};