Commit ec4e9c22 by Giang Tran

logo noti android

parent 23ed3c8c
...@@ -8,6 +8,8 @@ import RootView from './src/RootView'; ...@@ -8,6 +8,8 @@ import RootView from './src/RootView';
import createSagaMiddleware from 'redux-saga'; import createSagaMiddleware from 'redux-saga';
import rootSaga from './src/Saga/rootSaga'; import rootSaga from './src/Saga/rootSaga';
import FirebaseNotification from './src/helper/FirebaseNotification';
let bootSplashLogo = require('./src/assets/images/iconSplash.png'); let bootSplashLogo = require('./src/assets/images/iconSplash.png');
let fakeApiCallWithoutBadNetwork = (ms) => let fakeApiCallWithoutBadNetwork = (ms) =>
...@@ -58,6 +60,7 @@ let App = () => { ...@@ -58,6 +60,7 @@ let App = () => {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Provider store={store}> <Provider store={store}>
<FirebaseNotification />
<RootView /> <RootView />
</Provider> </Provider>
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application <application
android:name=".MainApplication" android:name=".MainApplication"
android:label="@string/app_name" android:label="@string/app_name"
...@@ -20,6 +20,10 @@ ...@@ -20,6 +20,10 @@
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
> >
<!-- <meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/bootsplash_background" /> -->
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
...@@ -38,7 +42,7 @@ ...@@ -38,7 +42,7 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" /> <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application> </application>
......
<resources> <resources>
<color name="bootsplash_background">#1C6AF6</color> <color name="bootsplash_background">#1C6AF6</color>
<color name="white">#1C6AF6</color>
</resources> </resources>
...@@ -9,6 +9,17 @@ import { ...@@ -9,6 +9,17 @@ import {
import moment from 'moment'; import moment from 'moment';
import _ from 'lodash'; import _ from 'lodash';
import {DETAILNEW, NOTIFICATION} from '../routers/ScreenNames';
export const convertScreen = (name) => {
switch (name) {
case 'CUSTOMER_NEWS':
return DETAILNEW;
default:
return DETAILNEW;
}
};
export const requestCameraPermission = async () => { export const requestCameraPermission = async () => {
try { try {
const granted = await PermissionsAndroid.request( const granted = await PermissionsAndroid.request(
......
import {NEW_SCREEN, CLEAR_SCREEN} from '../actions/actionTypes';
const initialState = {
screen: null,
id: null,
};
// @ts-ignore
export default function ScreenInitReducer(state = initialState, action) {
switch (action.type) {
case NEW_SCREEN: {
console.log('action', action);
return {screen: action.body.screen, id: action.body.id_record};
}
default:
return state;
}
}
...@@ -2,12 +2,14 @@ import userReducer from './userReducer'; ...@@ -2,12 +2,14 @@ import userReducer from './userReducer';
import {combineReducers} from 'redux'; import {combineReducers} from 'redux';
import ModalLoadingReducer from './ModalLoading'; import ModalLoadingReducer from './ModalLoading';
import SnackReducer from './SnackReducer'; import SnackReducer from './SnackReducer';
import ScreenInitReducer from './ScreenInit';
// @ts-ignore // @ts-ignore
const rootReducer = combineReducers({ const rootReducer = combineReducers({
userReducer, userReducer,
ModalLoadingReducer, ModalLoadingReducer,
SnackReducer, SnackReducer,
ScreenInitReducer,
}); });
export default rootReducer; export default rootReducer;
...@@ -5,7 +5,6 @@ import {connect} from 'react-redux'; ...@@ -5,7 +5,6 @@ import {connect} from 'react-redux';
import StackNavigation from './routers/StackNavigation'; import StackNavigation from './routers/StackNavigation';
import Modal from 'react-native-modal'; import Modal from 'react-native-modal';
import {SkypeIndicator} from 'react-native-indicators'; import {SkypeIndicator} from 'react-native-indicators';
import FirebaseNotification from './helper/FirebaseNotification';
import {enableScreens} from 'react-native-screens'; import {enableScreens} from 'react-native-screens';
enableScreens(); enableScreens();
...@@ -13,8 +12,6 @@ enableScreens(); ...@@ -13,8 +12,6 @@ enableScreens();
const RootView = (props) => { const RootView = (props) => {
return ( return (
<View style={{flex: 1}}> <View style={{flex: 1}}>
<FirebaseNotification />
<Modal isVisible={props.loadingModal.isVisible}> <Modal isVisible={props.loadingModal.isVisible}>
<SkypeIndicator color={'white'} /> <SkypeIndicator color={'white'} />
</Modal> </Modal>
......
...@@ -6,6 +6,7 @@ import {WebView} from 'react-native-webview'; ...@@ -6,6 +6,7 @@ import {WebView} from 'react-native-webview';
import {root} from '../../apis/url'; import {root} from '../../apis/url';
const DepositView = (props) => { const DepositView = (props) => {
console.log(props.route);
return ( return (
<View style={{flex: 1}}> <View style={{flex: 1}}>
<HeaderBack isWhite={true} title={'Chi tiết'} /> <HeaderBack isWhite={true} title={'Chi tiết'} />
......
import {NEW_SCREEN} from './actionTypes';
export const newScreenInit = (body) => {
return {
type: NEW_SCREEN,
body,
};
};
...@@ -17,3 +17,6 @@ export const UPDATE_REPORT_SUCCESSED = 'UPDATE_REPORT_SUCCESSED'; ...@@ -17,3 +17,6 @@ export const UPDATE_REPORT_SUCCESSED = 'UPDATE_REPORT_SUCCESSED';
export const UPDATE_REPORT = 'UPDATE_REPORT'; export const UPDATE_REPORT = 'UPDATE_REPORT';
export const SAVENAVIGATE = 'SAVENAVIGATE'; export const SAVENAVIGATE = 'SAVENAVIGATE';
export const NEW_SCREEN = 'NEW_SCREEN';
export const CLEAR_SCREEN = 'CLEAR_SCREEN';
...@@ -6,26 +6,60 @@ import AsyncStorage from '@react-native-community/async-storage'; ...@@ -6,26 +6,60 @@ import AsyncStorage from '@react-native-community/async-storage';
import KEY from '../assets/AsynStorage'; import KEY from '../assets/AsynStorage';
import {showNotificaton, updateNotification} from '../actions/SnackBarAction'; import {showNotificaton, updateNotification} from '../actions/SnackBarAction';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import {newScreenInit} from '../actions/ScreenInitAction';
import {convertScreen} from '../Config/Functions';
const FirebaseNotification = (props) => { const FirebaseNotification = (props) => {
messaging().setBackgroundMessageHandler(async (remoteMessage) => { messaging().setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Message handled in the background!', remoteMessage); console.log('Message handled in the background!', remoteMessage);
}); });
messaging().onNotificationOpenedApp(async (remoteMessage) => { messaging().onNotificationOpenedApp(async (remoteMessage) => {
console.log('Message handled in the background!', remoteMessage); console.log('On notifi open app-----', remoteMessage);
}); });
useEffect(() => { useEffect(() => {
requestUserPermission(); requestUserPermission();
const unsubscribe = messaging().onMessage(async (remoteMessage) => { const unsubscribe = messaging().onMessage(async (remoteMessage) => {
console.log('A new FCM message arrived!', remoteMessage.data); console.log('A new FCM message arrived!', remoteMessage.data);
const {action_type, body, title, record_id} = remoteMessage.data;
props.showNotificaton({ props.showNotificaton({
title: 'Title', title,
content: 'Content notification', content: body,
screen: 'NOTIFICATION', screen: convertScreen(action_type),
id_record: 9, id_record: record_id,
}); });
}); });
(async () => await messaging().registerDeviceForRemoteMessages())();
messaging().onNotificationOpenedApp((remoteMessage) => {
console.log(
'Notification caused app to open from background state:',
remoteMessage,
);
const {action_type, body, title, record_id} = remoteMessage.data;
props.newScreenInit({
screen: convertScreen(action_type),
id_record: record_id,
});
});
messaging()
.getInitialNotification()
.then((remoteMessage) => {
console.log(remoteMessage);
if (remoteMessage) {
console.log(
'Notification caused app to open from quit state:',
remoteMessage.data,
);
const {action_type, body, title, record_id} = remoteMessage.data;
props.newScreenInit({
screen: convertScreen(action_type),
id_record: record_id,
});
}
});
return unsubscribe; return unsubscribe;
}, []); }, []);
...@@ -43,6 +77,7 @@ const FirebaseNotification = (props) => { ...@@ -43,6 +77,7 @@ const FirebaseNotification = (props) => {
let fcmToken = await AsyncStorage.getItem(KEY.FIREBASE); let fcmToken = await AsyncStorage.getItem(KEY.FIREBASE);
console.log(fcmToken); console.log(fcmToken);
if (!fcmToken) { if (!fcmToken) {
console.log(fcmToken);
fcmToken = await messaging().getToken(); fcmToken = await messaging().getToken();
if (fcmToken) { if (fcmToken) {
AsyncStorage.setItem(KEY.FIREBASE, fcmToken); AsyncStorage.setItem(KEY.FIREBASE, fcmToken);
...@@ -58,6 +93,8 @@ const mapStateToProps = (state) => { ...@@ -58,6 +93,8 @@ const mapStateToProps = (state) => {
}; };
}; };
export default connect(mapStateToProps, {showNotificaton, updateNotification})( export default connect(mapStateToProps, {
FirebaseNotification, showNotificaton,
); newScreenInit,
updateNotification,
})(FirebaseNotification);
...@@ -30,6 +30,18 @@ const TabNavigator = (props) => { ...@@ -30,6 +30,18 @@ const TabNavigator = (props) => {
}, 3000); }, 3000);
}, []); }, []);
useEffect(() => {
checkScreenInit();
}, [props.screenInit]);
const checkScreenInit = () => {
if (props.screenInit.screen) {
const {screen, id} = props.screenInit;
console.log(screen, id);
navigate.navigate(screen, {id: id});
}
};
const showPopUp = () => { const showPopUp = () => {
if (props.user.status == 1) { if (props.user.status == 1) {
return confirmAlert( return confirmAlert(
...@@ -115,6 +127,7 @@ const mapStateToProps = (state) => { ...@@ -115,6 +127,7 @@ const mapStateToProps = (state) => {
return { return {
user: state.userReducer, user: state.userReducer,
notifi: state.CountNotificationReducer, notifi: state.CountNotificationReducer,
screenInit: state.ScreenInitReducer,
}; };
}; };
......
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