/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from 'react'; import { StyleSheet, Text, TouchableOpacity, View, Clipboard } from 'react-native'; import FCM from "react-native-fcm"; import PushController from "./PushController"; import firebaseClient from "./FirebaseClient"; export default class App extends Component { constructor(props) { super(props); this.state = { token: "", tokenCopyFeedback: "" } } componentDidMount(){ FCM.getInitialNotification().then(notif => { this.setState({ initNotif: notif }) }); } showLocalNotification() { FCM.presentLocalNotification({ vibrate: 500, title: 'Hello', body: 'Test Notification', priority: "high", show_in_foreground: true, picture: 'https://firebase.google.com/_static/af7ae4b3fc/images/firebase/lockup.png' }); } scheduleLocalNotification() { FCM.scheduleLocalNotification({ id: 'testnotif', fire_date: new Date().getTime()+5000, vibrate: 500, title: 'Hello', body: 'Test Scheduled Notification', priority: "high", show_in_foreground: true, picture: 'https://firebase.google.com/_static/af7ae4b3fc/images/firebase/lockup.png' }); } render() { let { token, tokenCopyFeedback } = this.state; return ( this.setState({token: token || ""})} /> Welcome to Simple Fcm Client! Init notif: {JSON.stringify(this.state.initNotif)} this.setClipboardContent(this.state.token)} style={styles.instructions}> Token: {this.state.token} {this.state.tokenCopyFeedback} firebaseClient.sendNotification(token)} style={styles.button}> Send Notification firebaseClient.sendData(token)} style={styles.button}> Send Data firebaseClient.sendNotificationWithData(token)} style={styles.button}> Send Notification With Data this.showLocalNotification()} style={styles.button}> Send Local Notification this.scheduleLocalNotification()} style={styles.button}> Schedule Notification in 5s ); } setClipboardContent(text) { Clipboard.setString(text); this.setState({tokenCopyFeedback: "Token copied to clipboard."}); setTimeout(() => {this.clearTokenCopyFeedback()}, 2000); } clearTokenCopyFeedback() { this.setState({tokenCopyFeedback: ""}); } } 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', marginBottom: 2, }, feedback: { textAlign: 'center', color: '#996633', marginBottom: 3, }, button: { backgroundColor: "teal", paddingHorizontal: 20, paddingVertical: 10, marginVertical: 15, borderRadius: 10 }, buttonText: { color: "white", backgroundColor: "transparent" }, });