firebase-react-native-sample icon indicating copy to clipboard operation
firebase-react-native-sample copied to clipboard

same times firebase not work!!!!

Open milad1367 opened this issue 7 years ago • 0 comments

firabse worked correctly and after 1-day did not work. I faced this problem there days ago.but it was done without any reason. I having this problem again. I don't know where is the problem from.pls, see my code.

import * as firebase from 'firebase';
 // Initialize Firebase
const firebaseConfig = {
  apiKey: "AIzaSyDYvQaRPag_1pvnBLkxWRQEAOjujYONYu8",
  authDomain: "contactmanager-a73ef.firebaseapp.com",
  databaseURL: "https://contactmanager-a73ef.firebaseio.com",
  storageBucket: "",
};
const myFirebaseApp = firebase.initializeApp(firebaseConfig);

export default myFirebaseApp

import React, { Component } from 'react';
import { Text,TextInput, View , Button } from 'react-native';
import * as firebase from 'firebase';
import myFirebaseApp from './myFirebaseApp';
export default class AddNewContact extends Component {
  constructor(props) {
    super(props);
    this.state = {
      name:"",
      email:"",
      brief:""
    }
    this.itemsRef = this.GetRef().child('users');
  }
  GetRef() {
    return myFirebaseApp.database().ref();
  }
   writeUserData(){
    this.itemsRef.push({
      username: this.state.name,
      email: this.state.email,
      brief : this.state.brief
    }).then(()=>{
      this.props.navigation.goBack(null)
    });
  }
  SaveUser () {
    this.itemsRef.push({
      name: "user.name",
      email: "user.email",
      brief: "user.brief"
    })
  }

  render() {
    const navigation = this.props.navigation;
    return (
      <View>
        <TextInput
          style={{height: 40, borderWidth: 1}}
          onChangeText={(text) => this.setState({name:text})}
          value={this.state.name}
         />
         <TextInput
           style={{height: 40, borderWidth: 1}}
           onChangeText={(text) => this.setState({email:text})}
           value={this.state.email}
         />
         <TextInput
           style={{height: 40, borderWidth: 1}}
           onChangeText={(text) => this.setState({brief:text})}
           value={this.state.brief}
          />
          <Button
            onPress={()=>this.writeUserData()}
            title="add"
            color="#841584"
            accessibilityLabel="Learn more about this purple button"
          />
     </View>
    )
  }
}

import React, { Component } from 'react';

import {
    Platform,
    ScrollView,
    StyleSheet,
    TouchableOpacity,
    Text,
    View,
    Button,
    FlatList
  } from 'react-native';

  import { SafeAreaView, StackNavigator } from 'react-navigation';
  import AddNewContact from './components/AddNewContact';
  import TodoList from './components/TodoList';
  import myFirebaseApp from './components/myFirebaseApp';

class MainScreen extends  Component {
  constructor(props){
    super(props);
    this.state = {
      users:""
    };
    this.itemsRef = this.getRef().child('users');
  }
  getRef() {
    return myFirebaseApp.database().ref();
  }

  componentDidMount() {
     this.itemsRef.on('value',(snap)=>{
       console.log("snap"+snap);
       // get children as an array
     var items = [];
     snap.forEach((child) => {
        items.push({
          username: child.val().username,
         _key: child.key
      });
     });
       this.setState({users:items});
       console.log(items);
     })
  }


  render() {
    const navigation = this.props.navigation;
    return(
    <ScrollView style={{ flex: 1 }} contentInsetAdjustmentBehavior="automatic">
      <View>
        <FlatList
          data= {this.state.users}
          renderItem={({item}) => <Text>{item.username}</Text>}
        />
        <Button
          title="Add New Contact"
          color="#841584"
          accessibilityLabel="Learn more about this purple button"
          onPress={()=>
          navigation.navigate('AddNewContact',{name: 'AddNewContact'})
          }
       />
      </View>
    </ScrollView>
  )
}
}

const AppNavigator = StackNavigator(
    {
      AddNewContact:{
        screen: AddNewContact
      },
      Index: {
        screen: MainScreen,
      },
    },
    {
      initialRouteName: 'Index',
      headerMode: 'none',

      /*
     * Use modal on iOS because the card mode comes from the right,
     * which conflicts with the drawer example gesture
     */
      mode: Platform.OS === 'ios' ? 'modal' : 'card',
    }
  );

  export default AppNavigator

and complete source

milad1367 avatar Dec 20 '17 08:12 milad1367