SHARE
TWEET

Untitled

a guest Jul 15th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react';
  2. import {TextInput, View, Keyboard} from 'react-native';
  3. import {Constants, Notifications, Permissions} from 'expo';
  4.  
  5. export default class Timer extends Component {
  6.     onSubmit(e) {
  7.         Keyboard.dismiss();
  8.  
  9.         const localNotification = {
  10.             title: 'done',
  11.             body: 'done!'
  12.         };
  13.  
  14.         const schedulingOptions = {
  15.             time: (new Date()).getTime() + Number(e.nativeEvent.text)
  16.         }
  17.  
  18.         // Notifications show only when app is not active.
  19.         // (ie. another app being used or device's screen is locked)
  20.         Notifications.scheduleLocalNotificationAsync(
  21.             localNotification, schedulingOptions
  22.         );
  23.     }
  24.  
  25.     handleNotification() {
  26.         console.warn('ok! got your notif');
  27.     }
  28.  
  29.     async componentDidMount() {
  30.         // We need to ask for Notification permissions for ios devices
  31.         let result = await Permissions.askAsync(Permissions.NOTIFICATIONS);
  32.  
  33.         if (Constants.isDevice && result.status === 'granted') {
  34.             console.log('Notification permissions granted.')
  35.         }
  36.  
  37.         // If we want to do something with the notification when the app
  38.         // is active, we need to listen to notification events and
  39.         // handle them in a callback
  40.         Notifications.addListener(this.handleNotification);
  41.     }
  42.  
  43.     render() {
  44.         return (
  45.             <View style={{flex: 1, flexDirection: 'row', justifyContent: 'center'}}>
  46.                 <TextInput
  47.                     onSubmitEditing={this.onSubmit}
  48.                     placeholder={'time in ms'}
  49.                 />
  50.             </View>
  51.         );
  52.     }
  53. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top