Make temp reminder work for android & ios
This commit is contained in:
+17
-1
@@ -1,3 +1,4 @@
|
|||||||
|
import { Platform } from 'react-native'
|
||||||
import {tempReminderObservable, periodReminderObservable} from '../local-storage'
|
import {tempReminderObservable, periodReminderObservable} from '../local-storage'
|
||||||
import Notification from 'react-native-push-notification'
|
import Notification from 'react-native-push-notification'
|
||||||
import Moment from 'moment'
|
import Moment from 'moment'
|
||||||
@@ -9,7 +10,10 @@ import nothingChanged from '../db/db-unchanged'
|
|||||||
export default function setupNotifications(navigate) {
|
export default function setupNotifications(navigate) {
|
||||||
Notification.configure({
|
Notification.configure({
|
||||||
onNotification: (notification) => {
|
onNotification: (notification) => {
|
||||||
if (notification.data.id === '11' || notification.id === '1') {
|
if (Platform.OS === "ios" && notification.data && notification.data.id === '11') {
|
||||||
|
navigate('TemperatureEditView')
|
||||||
|
}
|
||||||
|
else if (Platform.OS === "android" && notification.id === '1') {
|
||||||
navigate('TemperatureEditView')
|
navigate('TemperatureEditView')
|
||||||
} else {
|
} else {
|
||||||
navigate('Home')
|
navigate('Home')
|
||||||
@@ -18,7 +22,11 @@ export default function setupNotifications(navigate) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
tempReminderObservable(reminder => {
|
tempReminderObservable(reminder => {
|
||||||
|
if (Platform.OS === "ios") {
|
||||||
Notification.cancelLocalNotifications({id: '11'})
|
Notification.cancelLocalNotifications({id: '11'})
|
||||||
|
} else {
|
||||||
|
Notification.cancelLocalNotifications({id: '1'})
|
||||||
|
}
|
||||||
if (reminder.enabled) {
|
if (reminder.enabled) {
|
||||||
const [hours, minutes] = reminder.time.split(':')
|
const [hours, minutes] = reminder.time.split(':')
|
||||||
let target = new Moment()
|
let target = new Moment()
|
||||||
@@ -42,14 +50,22 @@ export default function setupNotifications(navigate) {
|
|||||||
}, false)
|
}, false)
|
||||||
|
|
||||||
periodReminderObservable(reminder => {
|
periodReminderObservable(reminder => {
|
||||||
|
if (Platform.OS === "ios") {
|
||||||
Notification.cancelLocalNotifications({id: '22'})
|
Notification.cancelLocalNotifications({id: '22'})
|
||||||
|
} else {
|
||||||
|
Notification.cancelLocalNotifications({id: '2'})
|
||||||
|
}
|
||||||
if (reminder.enabled) setupPeriodReminder()
|
if (reminder.enabled) setupPeriodReminder()
|
||||||
}, false)
|
}, false)
|
||||||
|
|
||||||
getBleedingDaysSortedByDate().addListener((_, changes) => {
|
getBleedingDaysSortedByDate().addListener((_, changes) => {
|
||||||
// the listener fires on setup, so we check if there were actually any changes
|
// the listener fires on setup, so we check if there were actually any changes
|
||||||
if (nothingChanged(changes)) return
|
if (nothingChanged(changes)) return
|
||||||
|
if (Platform.OS === "ios") {
|
||||||
|
Notification.cancelLocalNotifications({id: '22'})
|
||||||
|
} else {
|
||||||
Notification.cancelLocalNotifications({id: '2'})
|
Notification.cancelLocalNotifications({id: '2'})
|
||||||
|
}
|
||||||
if (periodReminderObservable.value.enabled) setupPeriodReminder()
|
if (periodReminderObservable.value.enabled) setupPeriodReminder()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user