Skip to content
Snippets Groups Projects
App.js 1.58 KiB
Newer Older
horpynych-ap's avatar
horpynych-ap committed
import { Navigation } from './src/navigation/navigation';
import { Provider } from 'react-redux';
import { store } from './src/store';
import React, { useState, useRef } from 'react';
import * as Notifications from 'expo-notifications';
import {
  registerForPushNotificationsAsync,
} from './src/notifications/useNotification';
import { ThemeProvider } from 'styled-components';
import { theme } from './src/theme/theme';

Notifications.setNotificationHandler({
  handleNotification: async () => ({
    shouldShowAlert: true,
    shouldPlaySound: false,
    shouldSetBadge: false,
  }),
});

export default function App () {
  const [expoPushToken, setExpoPushToken] = useState('');
  const [notification, setNotification] = useState(false);
  const notificationListener = useRef();
  const responseListener = useRef();

  React.useEffect(() => {

    registerForPushNotificationsAsync().then(token => setExpoPushToken(token));

    notificationListener.current = Notifications.addNotificationReceivedListener(
      notification => {
        setNotification(notification);
        console.log(notification);
      });

    responseListener.current = Notifications.addNotificationResponseReceivedListener(
      response => {
        console.log('response');
      });

    return () => {
      Notifications.removeNotificationSubscription(
        notificationListener.current);
      Notifications.removeNotificationSubscription(responseListener.current);
    };
  }, []);
horpynych-ap's avatar
horpynych-ap committed

  return (
horpynych-ap's avatar
horpynych-ap committed
    <ThemeProvider theme={theme}>
      <Provider store={store}>
        <Navigation/>
      </Provider>
    </ThemeProvider>
horpynych-ap's avatar
horpynych-ap committed
  );
horpynych-ap's avatar
horpynych-ap committed
}