-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from yssk22/revert-163-revert-159-develop
Revert "Revert "[expo] implement push notification handler""
- Loading branch information
Showing
7 changed files
with
134 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import PushNotificationHandler, { PushNotificationData } from './internals/PushNotificationHandler'; | ||
import usePushNotificationToken from './internals/usePushNotificationToken'; | ||
import usePushNotificationTokenUpdator from './internals/usePushNotificationTokenUpdator'; | ||
|
||
export { usePushNotificationToken, usePushNotificationTokenUpdator }; | ||
export { usePushNotificationToken, usePushNotificationTokenUpdator, PushNotificationHandler, PushNotificationData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { logEvent } from '@hpapp/system/firebase'; | ||
import * as Notifications from 'expo-notifications'; | ||
import React, { useEffect, useRef } from 'react'; | ||
|
||
type Subscription = ReturnType<typeof Notifications.addNotificationResponseReceivedListener>; | ||
|
||
export type PushNotificationData = { | ||
id: string; | ||
timestamp: Date; | ||
body: { | ||
type: string; | ||
payload: { [key: string]: any }; | ||
}; | ||
}; | ||
|
||
export type PushNotificationHandlerProps = { | ||
children: React.ReactElement; | ||
onData?: (data: PushNotificationData) => void; | ||
}; | ||
|
||
export default function PushNotificationHandler({ children, onData }: PushNotificationHandlerProps) { | ||
const responseSubscription = useRef<Subscription>(); | ||
useEffect(() => { | ||
(async () => { | ||
responseSubscription.current = Notifications.addNotificationResponseReceivedListener((response) => { | ||
const body = response.notification.request.content.data as { | ||
type: string; | ||
payload: string; | ||
}; | ||
logEvent('respond_to_notification', { | ||
body | ||
}); | ||
onData?.({ | ||
id: response.notification.request.identifier, | ||
timestamp: new Date(response.notification.date), | ||
body: { | ||
type: body.type, | ||
payload: JSON.parse(body.payload) | ||
} | ||
}); | ||
}); | ||
return () => { | ||
if (responseSubscription.current) { | ||
Notifications.removeNotificationSubscription(responseSubscription.current); | ||
} | ||
}; | ||
})(); | ||
}, [onData]); | ||
return <>{children}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,4 +218,5 @@ jest.mock('@hpapp/features/app/storybook', () => { | |
} | ||
}; | ||
}); | ||
|
||
jest.setTimeout(30000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters