Commit 68612dd5 authored by Afid's avatar Afid

notification sekarang bisa navigate

parent 7446a597
...@@ -17,6 +17,9 @@ import { AppLoading, Notifications } from 'expo'; ...@@ -17,6 +17,9 @@ import { AppLoading, Notifications } from 'expo';
import * as Font from 'expo-font'; import * as Font from 'expo-font';
import * as Sentry from 'sentry-expo'; import * as Sentry from 'sentry-expo';
import Constants from 'expo-constants'; import Constants from 'expo-constants';
import { navigationRef } from './helper/RootNavigation';
import * as RootNavigation from './helper/RootNavigation';
Sentry.init({ Sentry.init({
dsn: 'https://ae2449ac801244d99f170140c7cd6d0a@o392471.ingest.sentry.io/5239999', dsn: 'https://ae2449ac801244d99f170140c7cd6d0a@o392471.ingest.sentry.io/5239999',
...@@ -58,28 +61,13 @@ export default function App() { ...@@ -58,28 +61,13 @@ export default function App() {
await Font.loadAsync(customFonts); await Font.loadAsync(customFonts);
}; };
const handleNotification = notification => { const routing = (data) => {
Vibration.vibrate();
console.log('Notification Payload Data : ' + JSON.stringify(notification.data))
const data = notification.data;
Alert.alert(
data.title,
data.body,
[
{
text: 'Close',
onPress: () => console.log('Close'),
style: 'cancel',
},
{
text: 'View', onPress: () => {
console.log('Pindah Halaman')
if (data.action_type == 'Rewards') { if (data.action_type == 'Rewards') {
// props.navigation.navigate('Reward Detail', { rewardId: data.data_id }) RootNavigation.navigate('Reward Detail', { rewardId: data.data_id });
} else if (data.action_type == 'Inbox') { } else if (data.action_type == 'Inbox') {
} else if (data.action_type == 'Transaction') { } else if (data.action_type == 'Transaction') {
RootNavigation.navigate('Transaction Detail', {idTrans:data.data_id});
} else if (data.action_type == 'Review') { } else if (data.action_type == 'Review') {
} else if (data.action_type == 'WebView') { } else if (data.action_type == 'WebView') {
...@@ -90,12 +78,37 @@ export default function App() { ...@@ -90,12 +78,37 @@ export default function App() {
} }
} }
const handleNotification = notification => {
// console.log('Notification Origin : ' + JSON.stringify(notification.origin))
// console.log('Notification Payload Data : ' + JSON.stringify(notification.data))
const origin = notification.origin;
const data = notification.data;
if (origin == 'selected') {
routing(data)
} else {
Vibration.vibrate();
Alert.alert(
data.title,
data.body,
[
{
text: 'Close',
style: 'cancel',
},
{
text: 'View', onPress: () => {
routing(data)
}
}, },
], ],
{ cancelable: false }, { cancelable: false },
) )
} }
}
useEffect(() => { useEffect(() => {
console.log('===> Did Mount'); console.log('===> Did Mount');
...@@ -111,7 +124,7 @@ export default function App() { ...@@ -111,7 +124,7 @@ export default function App() {
return ( return (
<Provider store={store}> <Provider store={store}>
<PersistGate loading={null} persistor={persistor}> <PersistGate loading={null} persistor={persistor}>
<NavigationContainer> <NavigationContainer ref={navigationRef}>
<Auth /> <Auth />
</NavigationContainer> </NavigationContainer>
</PersistGate> </PersistGate>
......
import * as React from 'react';
export const navigationRef = React.createRef();
export function navigate(name, params) {
navigationRef.current?.navigate(name, params);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment