Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Image picker#jpe #78

Merged
merged 12 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ android {
}

dependencies {
implementation project(':react-native-image-picker')
implementation project(':react-native-text-input-mask')
implementation project(':react-native-linear-gradient')
implementation project(':react-native-vector-icons')
Expand All @@ -153,6 +154,7 @@ dependencies {
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.1'
implementation "com.google.firebase:firebase-firestore:18.2.0"
implementation "com.google.firebase:firebase-storage:16.1.0"

}

Expand Down
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
package="com.unichat">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:name=".MainApplication"
Expand Down
6 changes: 5 additions & 1 deletion android/app/src/main/java/com/unichat/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Application;

import com.facebook.react.ReactApplication;
import com.imagepicker.ImagePickerPackage;
import com.RNTextInputMask.RNTextInputMaskPackage;
import com.BV.LinearGradient.LinearGradientPackage;
import com.oblador.vectoricons.VectorIconsPackage;
Expand All @@ -15,6 +16,7 @@
import com.facebook.soloader.SoLoader;
import io.invertase.firebase.auth.RNFirebaseAuthPackage;
import io.invertase.firebase.firestore.RNFirebaseFirestorePackage;
import io.invertase.firebase.storage.RNFirebaseStoragePackage;

import java.util.Arrays;
import java.util.List;
Expand All @@ -31,14 +33,16 @@ public boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ImagePickerPackage(),
new RNTextInputMaskPackage(),
new LinearGradientPackage(),
new VectorIconsPackage(),
new RNFirebasePackage(),
new RNFirebaseAuthPackage(),
new RNFirebaseFirestorePackage(),
new SvgPackage(),
new RNGestureHandlerPackage()
new RNGestureHandlerPackage(),
new RNFirebaseStoragePackage()
);
}

Expand Down
2 changes: 2 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
rootProject.name = 'Unichat'
include ':react-native-image-picker'
project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android')
include ':react-native-text-input-mask'
project(':react-native-text-input-mask').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-text-input-mask/android')
include ':react-native-linear-gradient'
Expand Down
2 changes: 2 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ target 'Unichat' do

pod 'BVLinearGradient', :path => '../node_modules/react-native-linear-gradient'

pod 'react-native-image-picker', :path => '../node_modules/react-native-image-picker'

target 'UnichatTests' do
inherit! :search_paths
# Pods for testing
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"react-native-elements": "^1.1.0",
"react-native-firebase": "^5.3.1",
"react-native-gesture-handler": "^1.1.0",
"react-native-image-picker": "^0.28.1",
"react-native-linear-gradient": "^2.5.4",
"react-native-masked-text": "^1.12.2",
"react-native-power-translator": "^1.1.1",
Expand Down
9 changes: 8 additions & 1 deletion src/Screens/Auth/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ export default class Auth extends Component {
const { navigation } = this.props
firebase.auth().onAuthStateChanged(user => {
if (user) {
const userRef = firebase.firestore().collection("users").doc(user.uid)
this.setState({ loading: false })
navigation.navigate("ChatScreen")
userRef.get().then(doc => {
if(!doc.exists) {
navigation.navigate("PerfilSettings")
} else {
navigation.navigate("Conversas")
}
})
} else {
this.setState({ loading: false })
}
Expand Down
100 changes: 91 additions & 9 deletions src/Screens/PerfilSettings/perfilsettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import {
TouchableOpacity,
Picker,
StyleSheet,
Dimensions
Dimensions,
Alert
} from "react-native"
import { Icon } from "react-native-elements"
import firebase from "react-native-firebase"
import shortid from "shortid"
import LinearGradient from "react-native-linear-gradient"
import ImagePicker from "react-native-image-picker"
import profileImage from "../../assets/imgs/profile-placeholder.png"
import languagelist from "../../assets/languages/languages"

Expand All @@ -22,14 +25,77 @@ export default class PerfilSettings extends Component {
this.state = {
language: [],
code: "",
img: profileImage
img: profileImage,
userName: "",
eMail: "",
profileImageUrl: ""
}
}

componentDidMount() {
this.setState({ language: languagelist })
}

confirmPerfilSettings = () => {
const { navigation } = this.props
const user = firebase.auth().currentUser
const { userName, eMail, code, profileImageUrl } = this.state
firebase
.firestore()
.collection("users")
.doc(user.uid)
.set({
phone: user.phoneNumber,
username: userName,
email: eMail,
language_code: code,
profile_img_url: profileImageUrl
})
navigation.navigate("Conversas")
}

uploadphotos = () => {
const user = firebase.auth().currentUser
const { img } = this.state

firebase
.storage()
.ref(`profile_pics/${user.uid}`)
.putFile(img.path).on(
firebase.storage.TaskEvent.STATE_CHANGED,
snapshot => {
let state = {}
state = {
...state,
progress: (snapshot.bytesTransferred / snapshot.totalBytes) * 100 // Progress bar
}
if(snapshot.state === firebase.storage.TaskState.SUCCESS) {
Alert.alert("Image upload successful.")
state = {
uploading: false,
progress: 0,
profileImageUrl: snapshot.downloadURL
}
}

this.setState(state)
})
}

handleChooseImage = () => {
const options = {
noData: true,
title: "Escolha uma foto",
}

ImagePicker.showImagePicker(options, response => {
if(response.uri) {
this.setState({img: response})
this.uploadphotos()
}
})
}

previewImage = () => {
const { navigation } = this.props
const { img } = this.state
Expand All @@ -48,16 +114,30 @@ export default class PerfilSettings extends Component {
this.previewImage()
}}
>
<Image source={img} style={styles.imagePlaceHolder} />
{img && (
<Image
source={{uri: img.uri}}
style={styles.imagePlaceHolder}
/>
)}
</TouchableOpacity>
<TouchableOpacity style={styles.roundbutton}>
<TouchableOpacity
style={styles.roundbutton}
onPress={this.handleChooseImage}
>
<Icon name="create" />
</TouchableOpacity>
</View>
<Text style={styles.labeltext}>Nome:</Text>
<TextInput style={styles.entrada} placeholder="Digite seu nome" />
<TextInput
style={styles.entrada}
onChangeText={text => this.setState({userName: text})}
placeholder="Digite seu nome" />
<Text style={styles.labeltext}>Email:</Text>
<TextInput style={styles.entrada} placeholder="Digite seu e-mail" />
<TextInput
style={styles.entrada}
onChangeText={text => this.setState({eMail: text})}
placeholder="Digite seu e-mail" />
<Text style={styles.labeltext}>Idiomas:</Text>
<View style={styles.languagePicker}>
<Picker
Expand All @@ -74,9 +154,11 @@ export default class PerfilSettings extends Component {
))}
</Picker>
</View>
<LinearGradient colors={["#547BF0", "#6AC3FB"]} style={styles.button}>
<Text style={styles.textButton}>Avançar</Text>
</LinearGradient>
<TouchableOpacity onPress={this.confirmPerfilSettings}>
<LinearGradient colors={["#547BF0", "#6AC3FB"]} style={styles.button}>
<Text style={styles.textButton}>Cadastrar</Text>
</LinearGradient>
</TouchableOpacity>
</View>
)
}
Expand Down
13 changes: 2 additions & 11 deletions src/Screens/Verification/verification.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { Component } from "react"
import { View, Text, StyleSheet, Linking, TouchableOpacity } from "react-native"
import LinearGradient from "react-native-linear-gradient"
import CodeInput from "react-native-confirmation-code-input"
import firebase from "react-native-firebase"

export default class Verificacao extends Component {
constructor() {
Expand All @@ -22,21 +21,13 @@ export default class Verificacao extends Component {
confirmChoice = code => {
const { navigation } = this.props
const confirmResult = navigation.getParam("confirmResultFirebase")
const phoneNumber = navigation.getParam("phoneNumber")

if (confirmResult && code.length) {
confirmResult
.confirm(code)
// Continuar as rotas se a confirmação ocorrer com sucesso aqui
.then(user => {
firebase
.firestore()
.collection("users")
.doc(user.uid)
.set({
phone: phoneNumber
})
navigation.navigate("Conversas")
.then(() => {
navigation.navigate("PerfilSettings")
})
// Caso dê algum erro, o tratamento é feito aqui
.catch(() => {})
Expand Down
Loading