Skip to content

Commit

Permalink
Opening Notifications on Beeps
Browse files Browse the repository at this point in the history
Now the app opens on the new beep irrelevant of where in the app the person left. This now eliminates the navigation to the beep screen.
  • Loading branch information
sarajaksa committed May 16, 2019
1 parent 2b4158f commit c850124
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
32 changes: 29 additions & 3 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import React, {Component} from "react";
import {Image, StyleSheet, View, Header} from "react-native";
import {createStackNavigator, createAppContainer} from "react-navigation";
import {
Image,
StyleSheet,
View,
Header,
Alert,
PushNotificationIOS,
} from "react-native";
import {
createStackNavigator,
createAppContainer,
NavigationActions,
} from "react-navigation";
import PushNotification from "react-native-push-notification";

import NavigationService from "./NavigationService.js";
import List from "./src/List.js";
import Questions from "./src/Questions.js";
import Question from "./src/Question.js";
Expand Down Expand Up @@ -66,10 +79,23 @@ const AppNavigator = createStackNavigator(
},
);

PushNotification.configure({
onNotification: function(notification) {
NavigationService.navigate("Index");
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
});

const AppContainer = createAppContainer(AppNavigator);

export default class App extends React.Component {
render() {
return <AppContainer />;
return (
<AppContainer
ref={navigatorRef => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
/>
);
}
}
21 changes: 21 additions & 0 deletions NavigationService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {NavigationActions} from "react-navigation";

let _navigator;

function setTopLevelNavigator(navigatorRef) {
_navigator = navigatorRef;
}

function navigate(routeName, params) {
_navigator.dispatch(
NavigationActions.navigate({
routeName,
params,
}),
);
}

export default {
navigate,
setTopLevelNavigator,
};
3 changes: 2 additions & 1 deletion src/functions/notifications.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, {Component} from "react";
import PushNotification from "react-native-push-notification";

import {getDataFromStorage, setDataToStorage} from "./data.js";
Expand All @@ -7,6 +7,7 @@ import {getDataFromStorage, setDataToStorage} from "./data.js";

export const createNotification = (date = new Date()) => {
let id = date.getTime();

PushNotification.localNotificationSchedule({
id: id,
date: date,
Expand Down

0 comments on commit c850124

Please sign in to comment.