Advertisement
Guest User

RN View Error

a guest
Dec 12th, 2016
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict'
  2. import React, { Component, Firebase } from 'react'
  3. import { AppRegistry, StyleSheet, Text, View, TextInput, Dimensions, Image, TouchableOpacity, Navigator, Linking } from 'react-native'
  4. import Icon from 'react-native-vector-icons/Ionicons'
  5. import * as firebase from 'firebase';
  6. var Platform = require('react-native').Platform;
  7. var ImagePicker = require('react-native-image-picker');
  8.  
  9. import Index from '../Index'
  10. import RegisterScreen from './RegisterScreen'
  11.  
  12. /* Variables */
  13. var strEmail = ""
  14. var strPassword = ""
  15. let ScreenWidth = Dimensions.get("window").width;
  16. let ScreenHeight = Dimensions.get("window").height;
  17.  
  18. var txtMail = <TextInput />
  19. var txtPassword = <TextInput />
  20. var provider = new firebase.auth.FacebookAuthProvider();
  21. provider.addScope('public_profile');
  22. provider.addScope('email');
  23.  
  24. var allergies = []
  25.  
  26. module.exports = class LoginScreen extends Component {
  27.   constructor(props) {
  28.     super(props)
  29.  
  30.     global.registering = false
  31.  
  32.     this.state = {
  33.       loaded: true,
  34.       strEmail: '',
  35.       strPassword: '',
  36.       uid: '',
  37.     };
  38.   }
  39.  
  40.   componentDidMount() {
  41.     this.findAllergies()
  42.  
  43.     firebase.auth().onAuthStateChanged((user) => {
  44.       if (user) {
  45.         global.userID = user.uid
  46.         var naviRef = this.refs.NavRef
  47.  
  48.         if (global.registering) {
  49.           var user = firebase.database().ref("users").child(global.userID)
  50.           user.child("city").set(global.txtRegisterCity)
  51.           user.child("country").set(global.txtRegisterCountry)
  52.           user.child("name").set(global.txtRegisterName)
  53.           user.child("surname").set(global.txtRegisterSurname)
  54.           user.child("role").set("user")
  55.           user.child("pushID").set("empty")
  56.           user.child("email").set(global.txtRegisterEmail)
  57.           user.child("phoneNumber").set(global.phoneNumber)
  58.  
  59.           var stats = user.child("stats")
  60.           var arrayStats = {"organised" : 0, "participated" : 0, "totalAccueil" : 0, "totalAmbiance" : 0, "totalGuest" : 0, "totalHygiene" : 0, "totalPresentation" : 0, "totalQuality" : 0, "totalRatingsGuest" : 0, "totalRatingsOrganisator" : 0}
  61.           stats.set(arrayStats)
  62.  
  63.           var allergiesSet = user.child("allergies")
  64.           allergiesSet.set(allergies)
  65.  
  66.           naviRef.push({
  67.             ident: 'Home'
  68.           })
  69.         } else {
  70.           naviRef.push({
  71.             ident: 'Home'
  72.           })
  73.         }
  74.       } else {
  75.         // No user logged in
  76.       }
  77.  
  78.     });
  79.   }
  80.  
  81.   findAllergies() {
  82.     firebase.database().ref("allergies").on("value", (snap) => {
  83.       snap.forEach((child) => {
  84.         allergies[child.key] = false
  85.       })
  86.     })
  87.   }
  88.  
  89.   digitsLogin() {
  90.     alert("uuu")
  91.   }
  92.  
  93.   _renderScene = (route, navigator) => {
  94.     var globalNavigatorProps = { navigator }
  95.  
  96.     var navigationView = (
  97.       <View style={{flex: 1, backgroundColor: '#fff'}}>
  98.         <Text style={{margin: 30, fontSize: 15, textAlign: 'left'}}>Menu</Text>
  99.       </View>
  100.     );
  101.  
  102.     switch(route.ident) {
  103.       case "Login":
  104.         if (this.state.uid == '') {
  105.           return(
  106.             <View style={styles.mainContainer}>
  107.               <Image source={require('../res/images/LoginScreenBackground.jpg')} style={styles.backgroundz}>
  108.               <View style={styles.container}>
  109.                 <View style={styles.titleView}>
  110.                   <Image source={require('../res/images/LETSeat.png')} style={{width: 200, height: 200, marginBottom: 50}} />
  111.                   <View style={{ borderBottomColor: '#fff', borderBottomWidth: 1, paddingLeft: 5, flexDirection: 'row'}}>
  112.                   <Icon name="ios-contact" size={25} color="#fff" />
  113.                   <TextInput
  114.                     ref={function(input) {
  115.                       if (input != null) {
  116.                         txtMail = input;
  117.                       }
  118.                     }}
  119.                     style={{paddingLeft: 5, backgroundColor: 'rgba(0,0,0,0)', color: 'white', flex: 1, marginBottom: 5}}
  120.                     placeholderStyle={{ color: 'red' }}
  121.                     onChangeText={(text) => strEmail = text}
  122.                     returnKeyType='done'
  123.                     onFocus={this._MailFocus}
  124.                     onEndEditing={this._ReleaseFocus}
  125.                     keyboardType='email-address'
  126.                     placeholder="Adresse email"
  127.                     placeholderTextColor='white'
  128.                   />
  129.                   </View>
  130.                   <View style={{ borderBottomColor: '#fff', borderBottomWidth: 1, flexDirection: 'row', paddingLeft: 7, marginTop: 5}}>
  131.                   <View style={{alignItems: 'center'}}>
  132.                     <Icon name="ios-lock" size={25} color="#fff" />
  133.                   </View>
  134.                   <TextInput
  135.                     ref={function(input) {
  136.                       if (input != null) {
  137.                         txtPassword = input;
  138.                       }
  139.                     }}
  140.                     style={{color: 'white', paddingLeft: 7, borderColor: 'white', backgroundColor: 'rgba(0,0,0,0)', flex: 1, marginBottom: 5}}
  141.                     onChangeText={(text) => strPassword = text}
  142.                     returnKeyType='done'
  143.                     onFocus={this._PasswordFocus}
  144.                     onEndEditing={this._ReleaseFocus}
  145.                     secureTextEntry={true}
  146.                     placeholder="Mot de passe"
  147.                     placeholderTextColor='white'
  148.                   />
  149.                   </View>
  150.                   <TouchableOpacity onPress={() => this.digitsLogin()} style={{backgroundColor: '#3b5998', height: 30, paddingLeft: 5, paddingRight: 5, alignItems: 'center', justifyContent: 'center', marginTop: 10, borderRadius: 5}}>
  151.                     <Text style={{color: 'white'}}>Natel login</Text>
  152.                   </TouchableOpacity>
  153.                   {/* <View style={{width: 200, marginTop: 10, alignItems: 'center', justifyContent: 'center'}}>
  154.                       <Icon.Button name="logo-facebook" backgroundColor="#3b5998" onPress={() => this._FacebookLogin()}>
  155.                         <Text style={{fontFamily: 'Arial', fontSize: 15, color: 'white'}}>Login with Facebook</Text>
  156.                       </Icon.Button>
  157.                   </View> */}
  158.                 </View>
  159.  
  160.                 <View style={styles.buttonsView}>
  161.                   <View style={styles.borderedView}>
  162.                     <TouchableOpacity
  163.                       style={styles.loginButton}
  164.                       styleDisabled={{color: 'red'}}
  165.                       onPress={() => this._Connexion()}>
  166.                       <Text style={{color: 'white', size: 20}}>Connexion</Text>
  167.                     </TouchableOpacity>
  168.                   </View>
  169.                   <View style={{backgroundColor: 'rgba(0,0,0,0)', flexDirection: 'row', height: 40, justifyContent: 'center',
  170.                       alignItems: 'center', textAlign: 'center'}}>
  171.                     <Text style={{color: 'white', marginRight: 5}}>Pas encore inscrit ?</Text>
  172.                     <TouchableOpacity onPress={() => this._Inscription()}>
  173.                       <Text style={{color: '#344a8d', fontWeight: 'bold'}}>Inscrivez-vous</Text>
  174.                     </TouchableOpacity>
  175.                   </View>
  176.                 </View>
  177.               </View>
  178.               </Image>
  179.             </View>
  180.           )
  181.         } else {
  182.           <Index />
  183.         }
  184.       case "Home":
  185.         return(
  186.           <Index />
  187.         )
  188.       case "Register":
  189.         return(
  190.           <RegisterScreen {...globalNavigatorProps}/>
  191.         )
  192.     }
  193.   }
  194.  
  195.   _Connexion() {
  196.     firebase.auth().signInWithEmailAndPassword(strEmail, strPassword).catch(function(error) {
  197.       alert('Mauvaise adresse mail ou mot de passe !');
  198.     });
  199.  
  200.     /*var naviRef = this.refs.NavRef
  201.     naviRef.push({
  202.       ident: 'Home'
  203.     })*/
  204.   }
  205.  
  206.   _Inscription() {
  207.     var naviRef = this.refs.NavRef
  208.     naviRef.push({
  209.       ident: 'Register'
  210.     })
  211.   }
  212.  
  213.   _MailFocus() {
  214.     txtMail.setNativeProps({placeholder:''})
  215.   }
  216.  
  217.   _ReleaseFocus() {
  218.     txtMail.setNativeProps({placeholder: 'Adresse email'})
  219.     txtPassword.setNativeProps({placeholder: 'Mot de passe'})
  220.   }
  221.  
  222.   _PasswordFocus() {
  223.     txtPassword.setNativeProps({placeholder:''})
  224.   }
  225.  
  226.   render() {
  227.     firebase.auth().onAuthStateChanged(function(user) {
  228.       if (user) {
  229.         // User is signed in
  230.         global.userID = user.uid
  231.       }
  232.     });
  233.  
  234.     return (
  235.       <Navigator
  236.         initialRoute={{ident: "Login"}}
  237.         ref="NavRef"
  238.         renderScene={this._renderScene}
  239.         style={{height: global.ScreenHeight}}/>
  240.     );
  241.   }
  242. }
  243.  
  244. /* Styles */
  245. const styles = StyleSheet.create({
  246.   toolbarTitle: {
  247.       textAlign:'center',
  248.       fontWeight:'bold',
  249.       flex: 1,
  250.       color: 'white',
  251.   },
  252.   mainContainer: {
  253.     height: ScreenHeight,
  254.   },
  255.   container: {
  256.     justifyContent: 'center',
  257.     flex:1,
  258.   },
  259.   toolbar: {
  260.     flexDirection:'row',
  261.     alignItems:'center',
  262.   },
  263.   title: {
  264.     fontSize: 60,
  265.     textAlign: 'center',
  266.     alignItems: 'center',
  267.     color: 'white',
  268.     fontFamily: 'Avenir Next',
  269.     fontWeight: '300',
  270.   },
  271.   titleView: {
  272.       flex: 1,
  273.       justifyContent:'center',
  274.       alignItems: 'center',
  275.       backgroundColor: 'rgba(0,0,0,0)',
  276.   },
  277.   subtitle: {
  278.     textAlign: 'center',
  279.     fontSize: 20,
  280.     color: 'white',
  281.     fontFamily: 'Avenir Next',
  282.     fontWeight: '300',
  283.     marginBottom: 60,
  284.   },
  285.   borderedView: {
  286.     backgroundColor: '#344a8d',
  287.     height: 50,
  288.     justifyContent: 'center',
  289.     alignItems: 'center'
  290.   },
  291.   loginButton: {
  292.     color: 'white',
  293.     width: ScreenWidth,
  294.     textAlign: 'center',
  295.     alignItems: 'center',
  296.     justifyContent: 'center'
  297.   },
  298.   buttonsView: {
  299.     alignItems: 'center',
  300.     justifyContent: 'flex-end',
  301.   },
  302.   backgroundz: {
  303.     resizeMode: 'cover',
  304.     width: ScreenWidth,
  305.     height: ScreenHeight,
  306.   },
  307. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement