App.js 2.55 KB
Newer Older
renato's avatar
renato committed
1 2 3 4 5 6 7 8 9 10 11
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  TouchableOpacity,
12 13
  View,
  Clipboard
renato's avatar
renato committed
14 15 16 17 18 19
} from 'react-native';

import PushController from "./PushController";
import firebaseClient from  "./FirebaseClient";

export default class App extends Component {
20 21 22 23
  constructor(props) {
    super(props);

    this.state = {
24 25
      token: "",
      tokenCopyFeedback: ""
26 27 28
    }
  }

renato's avatar
renato committed
29
  render() {
30
    let { token, tokenCopyFeedback } = this.state;
31

renato's avatar
renato committed
32 33
    return (
      <View style={styles.container}>
34 35 36
        <PushController
          onChangeToken={token => this.setState({token: token || ""})}
        />
renato's avatar
renato committed
37 38 39 40
        <Text style={styles.welcome}>
          Welcome to Simple Fcm Client!
        </Text>

41
        <Text selectable={true} onPress={() => this.setClipboardContent(this.state.token)} style={styles.instructions}>
42 43 44
          Token: {this.state.token}
        </Text>

45 46 47 48
        <Text style={styles.feedback}>
          {this.state.tokenCopyFeedback}
        </Text>

49
        <TouchableOpacity onPress={() => firebaseClient.sendNotification(token)} style={styles.button}>
renato's avatar
renato committed
50 51 52
          <Text style={styles.buttonText}>Send Notification</Text>
        </TouchableOpacity>

53
        <TouchableOpacity onPress={() => firebaseClient.sendData(token)} style={styles.button}>
renato's avatar
renato committed
54 55
          <Text style={styles.buttonText}>Send Data</Text>
        </TouchableOpacity>
renato's avatar
renato committed
56 57 58 59

        <TouchableOpacity onPress={() => firebaseClient.sendNotificationWithData(token)} style={styles.button}>
          <Text style={styles.buttonText}>Send Notification With Data</Text>
        </TouchableOpacity>
renato's avatar
renato committed
60 61 62
      </View>
    );
  }
63 64 65 66 67 68 69 70 71 72

  setClipboardContent(text) {
    Clipboard.setString(text);
    this.setState({tokenCopyFeedback: "Token copied to clipboard."});
    setTimeout(() => {this.clearTokenCopyFeedback()}, 2000);
  }

  clearTokenCopyFeedback() {
    this.setState({tokenCopyFeedback: ""});
  }
renato's avatar
renato committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
90 91 92 93 94 95
    marginBottom: 2,
  },
  feedback: {
    textAlign: 'center',
    color: '#996633',
    marginBottom: 3,
renato's avatar
renato committed
96 97 98 99 100
  },
  button: {
    backgroundColor: "teal",
    paddingHorizontal: 20,
    paddingVertical: 10,
renato's avatar
renato committed
101
    marginVertical: 15,
renato's avatar
renato committed
102 103 104 105 106 107 108
    borderRadius: 10
  },
  buttonText: {
    color: "white",
    backgroundColor: "transparent"
  },
});