Commit 16d4fdc9 by Giang Tran

control notification

parent 85e40365
......@@ -31,7 +31,7 @@
</activity>
<activity
android:name="com.zoontek.rnbootsplash.RNBootSplashActivity"
android:theme="@style/BootTheme"
android:theme="@style/BootTheme"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
......@@ -5,51 +5,16 @@ import {connect} from 'react-redux';
import StackNavigation from './routers/StackNavigation';
import Modal from 'react-native-modal';
import {SkypeIndicator} from 'react-native-indicators';
import {HEIGHT, HEIGHTXD} from './Config/Functions';
import R from './assets/R';
import messaging from '@react-native-firebase/messaging';
import FirebaseNotification from './helper/FirebaseNotification';
import {enableScreens} from 'react-native-screens';
import AsyncStorage from '@react-native-community/async-storage';
import KEY from './assets/AsynStorage';
enableScreens();
const RootView = (props) => {
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Message handled in the background!', remoteMessage);
});
useEffect(() => {
requestUserPermission();
const unsubscribe = messaging().onMessage(async (remoteMessage) => {
console.log('A new FCM message arrived!', remoteMessage);
});
return unsubscribe;
}, []);
const requestUserPermission = async () => {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
getFcmToken();
console.log('Authorization status:', authStatus);
}
};
const getFcmToken = async () => {
let fcmToken = await AsyncStorage.getItem(KEY.FIREBASE);
console.log('Dat tao', fcmToken);
if (!fcmToken) {
fcmToken = await messaging().getToken();
console.log('Vua tao', fcmToken);
if (fcmToken) {
AsyncStorage.setItem(KEY.FIREBASE, fcmToken);
}
}
};
return (
<View style={{flex: 1}}>
<FirebaseNotification />
<Modal isVisible={props.loadingModal.isVisible}>
<SkypeIndicator color={'white'} />
</Modal>
......
......@@ -67,17 +67,29 @@ const Success = (props) => {
return (
<View style={{flex: 1}}>
<FlatList
keyExtractor={(item) => item.transection_id + 'a'}
refreshing={isRefresh}
onRefresh={onRefresh}
onEndReachedThreshold={0.01}
onEndReached={(info) => {
onLoadMore();
}}
data={data}
renderItem={({item}) => <Item item={item} />}
/>
{data.length == 0 ? (
<View style={{justifyContent: 'center', alignItems: 'center', flex: 1}}>
<Text
style={{
fontSize: 18,
fontWeight: 'bold',
}}>
Không có thông báo nào!
</Text>
</View>
) : (
<FlatList
keyExtractor={(item) => item.transection_id + 'a'}
refreshing={isRefresh}
onRefresh={onRefresh}
onEndReachedThreshold={0.01}
onEndReached={(info) => {
onLoadMore();
}}
data={data}
renderItem={({item}) => <Item item={item} />}
/>
)}
</View>
);
};
......
......@@ -3,16 +3,21 @@ import {View, Text, FlatList} from 'react-native';
import HeaderBack from '../../../../components/Header/HeaderBack';
import Item from './Item';
import {getListTransaction} from '../../../../apis/Functions/Widthdraw';
import {useNavigation} from '@react-navigation/native';
const Watting = (props) => {
const [page, setPage] = useState(1);
const [data, setData] = useState([]);
const [tottalPage, setTotalPage] = useState(1);
const [isRefresh, setisRefresh] = useState(false);
const navigation = useNavigation();
useEffect(() => {
getData();
}, []);
const unsubscribe = navigation.addListener('focus', () => {
getData();
});
return unsubscribe;
}, [navigation]);
const getData = async () => {
setisRefresh(true);
......@@ -67,17 +72,29 @@ const Watting = (props) => {
return (
<View style={{flex: 1}}>
<FlatList
keyExtractor={(item) => item.transection_id + 'a'}
refreshing={isRefresh}
onRefresh={onRefresh}
onEndReachedThreshold={0.01}
onEndReached={(info) => {
onLoadMore();
}}
data={data}
renderItem={({item}) => <Item item={item} />}
/>
{data.length == 0 ? (
<View style={{justifyContent: 'center', alignItems: 'center', flex: 1}}>
<Text
style={{
fontSize: 18,
fontWeight: 'bold',
}}>
Không có thông báo nào!
</Text>
</View>
) : (
<FlatList
keyExtractor={(item) => item.transection_id + 'a'}
refreshing={isRefresh}
onRefresh={onRefresh}
onEndReachedThreshold={0.01}
onEndReached={(info) => {
onLoadMore();
}}
data={data}
renderItem={({item}) => <Item item={item} />}
/>
)}
</View>
);
};
......
......@@ -62,7 +62,7 @@ const FeedbackView = (props) => {
keyboardVerticalOffset={-50}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={{flex: 1}}>
<HeaderBack isWhite={true} title={'GỬI FEEDBACK'} />
<HeaderBack isWhite={true} title={'Gửi phản hồi'} />
<View style={styles.container}>
<Text style={styles.txt}>Đánh giá dch v ca DCV Invest</Text>
......@@ -149,7 +149,7 @@ const FeedbackView = (props) => {
<View style={styles.containerBtn}>
<Button
onClick={() => console.log('hello')}
title={'Gửi feedback'}
title={'Gửi phản hồi'}
/>
</View>
</View>
......
......@@ -9,7 +9,7 @@ const Customer = (props) => {
const navigate = useNavigation();
return (
<View style={{flex: 1}}>
<HeaderBack title={'Kinh doanh chung'} />
<HeaderBack title={'Khách hàng'} />
<View style={styles.container}>
<Text
style={{
......
......@@ -113,11 +113,11 @@ const GeneralInfor = (props) => {
<View style={{height: 40}} />
<View style={{justifyContent: 'center', alignItems: 'center'}}>
{/* <TouchableOpacity
onPress={() => console.log('Hello')}
style={styles.btn}>
<Text style={styles.txtBtn}>Cập nhật</Text>
</TouchableOpacity> */}
<TouchableOpacity
onPress={() => console.log('Hello')}
style={styles.btn}>
<Text style={styles.txtBtn}>Cp nht</Text>
</TouchableOpacity>
</View>
</View>
</ScrollView>
......
......@@ -70,7 +70,7 @@ const AddMethodPay = (props) => {
platform: Platform.OS,
bank_id: bank_id.id,
branch_name,
account_name,
account_name: account_name.toUpperCase(),
account_no,
});
props.hideLoading();
......
......@@ -37,16 +37,16 @@ const NewFeed = (props) => {
const scrollToCurrent = () => {
const date = new Date();
let index = 0;
const today = convertTimeApi(date);
if (data.length > 0) {
for (var i = 0; i < data.length; i++) {
if (data[i].start_date.substring(0, 10) == today) {
index = i;
break;
} else {
index = 30 - today.substring(8);
}
}
setTimeout(() => {
ListDayRef.current.scrollToIndex({
animated: true,
......@@ -58,7 +58,7 @@ const NewFeed = (props) => {
const getItemLayout = (data, index) => ({
length: 100,
offset: 70 * index,
offset: 60 * index,
index,
});
......
......@@ -35,7 +35,7 @@ const styles = StyleSheet.create({
},
right: {
marginLeft: 20,
paddingVertical: 20,
paddingVertical: 10,
borderTopWidth: 0.6,
borderBottomWidth: 0.6,
borderColor: '#CECECE',
......@@ -52,7 +52,7 @@ const styles = StyleSheet.create({
backgroundColor: R.colors.main,
borderRadius: 5,
marginLeft: -5,
marginTop: 25,
marginTop: 15,
},
txtTitle: {
fontSize: getFontXD(42),
......
......@@ -38,11 +38,11 @@ const Item = (props) => {
</ImageBackground>
<View style={styles.wrapRight}>
<View style={{flex: 1}}>
<Text style={styles.txtTitle} numberOfLines={2}>
<Text style={styles.txtTitle} numberOfLines={4}>
{title}
</Text>
</View>
<Text>{published_at}</Text>
<Text style={{color: '#8E8C8C'}}>{published_at}</Text>
</View>
</TouchableOpacity>
);
......
......@@ -68,7 +68,7 @@ const NotificaitonView = (props) => {
<View style={{justifyContent: 'center', alignItems: 'center', flex: 1}}>
<Text
style={{
fontSize: getFontXD(46),
fontSize: 18,
fontWeight: 'bold',
}}>
Không có thông báo nào!
......
import {
PUSHNOTI,
HIDENOTI
} from './actionTypes';
import {PUSHNOTI, HIDENOTI} from './actionTypes';
export const showNotificaton = (data) => {
return {
type: PUSHNOTI,
data
data,
};
};
export const hideNotification = () => {
return {
type: HIDENOTI
type: HIDENOTI,
};
};
......@@ -77,7 +77,7 @@ const Drawer = (props) => {
navigate.navigate(PROFILE);
}}>
<Text style={styles.txtTop}>{props.user.fullname}</Text>
<Text>{props.user.sponsor_id}</Text>
<Text>{props.user.user_id}</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
......
......@@ -18,6 +18,7 @@ import LinearGradient from 'react-native-linear-gradient';
import {connect} from 'react-redux';
import {HEIGHTXD} from '../../Config/Functions';
import {useNavigation} from '@react-navigation/native';
import SnackBar from '../SnackBar';
const HeaderHome = (props) => {
const {title, isWhite} = props;
const navigate = useNavigation();
......@@ -26,6 +27,7 @@ const HeaderHome = (props) => {
imageStyle={{resizeMode: 'stretch'}}
style={[styles.img, isWhite ? {backgroundColor: 'white'} : {}]}
source={R.images.bgHeader}>
<SnackBar />
<StatusBar backgroundColor="transparent" translucent={true} />
<View style={styles.headerContainer}>
<TouchableOpacity onPress={() => navigate.goBack()}>
......
......@@ -19,7 +19,7 @@ import {connect} from 'react-redux';
import {HEIGHTXD} from '../../Config/Functions';
import Modal from 'react-native-modal';
import Drawer from './Drawer';
import SnackBar from '../SnackBar';
const HeaderDrawer = (props) => {
const {title, isWhite} = props;
const [isModalVisible, setModalVisible] = useState(false);
......@@ -33,7 +33,9 @@ const HeaderDrawer = (props) => {
imageStyle={{resizeMode: 'stretch'}}
style={[styles.img, isWhite ? {backgroundColor: 'white'} : {}]}
source={R.images.bgHeader}>
<SnackBar />
<StatusBar backgroundColor="transparent" translucent={true} />
<View style={styles.headerContainer}>
<TouchableOpacity onPress={toggleModal}>
<Image source={R.images.iconMenu} style={styles.imgIcon} />
......
......@@ -17,7 +17,7 @@ import LinearGradient from 'react-native-linear-gradient';
import {connect} from 'react-redux';
import {HEIGHTXD, toPriceVnd} from '../../Config/Functions';
import Clipboard from '@react-native-clipboard/clipboard';
import SnackBar from '../SnackBar';
import {useNavigation} from '@react-navigation/native';
import {
WITHDRAW,
......@@ -117,6 +117,7 @@ const HeaderHome = (props) => {
return (
<View style={styles.container}>
<SnackBar />
<StatusBar backgroundColor="transparent" translucent={true} />
<View
style={{
......
......@@ -18,7 +18,7 @@ import {getFontXD, HEIGHT, WIDTHXD} from '../../Config/Functions';
import LinearGradient from 'react-native-linear-gradient';
import {connect} from 'react-redux';
import {HEIGHTXD} from '../../Config/Functions';
import SnackBar from '../SnackBar';
import Icon from 'react-native-vector-icons/Ionicons';
import {useNavigation} from '@react-navigation/native';
......@@ -39,6 +39,7 @@ const HeaderSearch = (props) => {
style={[styles.img, isWhite ? {backgroundColor: 'white'} : {}]}
source={R.images.bgHeader}>
<StatusBar backgroundColor="transparent" translucent={true} />
<SnackBar />
<View style={styles.headerContainer}>
<TouchableOpacity onPress={() => navigate.goBack()}>
<Image source={R.images.iconBack} style={styles.imgIcon} />
......
import React,{useState,useEffect} from 'react';
import {View,Text,StyleSheet,TouchableOpacity,StatusBar,TouchableWithoutFeedback} from 'react-native';
import R from '../assets/R'
import Block from './Block'
import {getFontXD,HEIGHTXD} from "../config/Functions";
import LinearGradient from "react-native-linear-gradient";
import React, {useState, useEffect} from 'react';
import {
View,
Text,
StyleSheet,
TouchableOpacity,
StatusBar,
TouchableWithoutFeedback,
} from 'react-native';
import R from '../assets/R';
import Block from './Block';
import {getFontXD, HEIGHTXD} from '../Config/Functions';
import LinearGradient from 'react-native-linear-gradient';
import Modal from 'react-native-modal';
import SnackReducer from "../reducers/SnackReducer";
import {connect} from 'react-redux'
import {showNotificaton,hideNotification} from '../actions/SnackBarAction'
import {connect} from 'react-redux';
import {showNotificaton, hideNotification} from '../actions/SnackBarAction';
import {useNavigation} from '@react-navigation/native';
const SnackBar=(props)=>{
const SnackBar = (props) => {
const navigate = useNavigation();
const {isOpen, title, content, screen, id_record} = props.snackReducer;
useEffect(() => {
console.log('Reducer', props.snackReducer);
if (isOpen)
setTimeout(() => {
props.hideNotification();
}, 10000);
}, [props.snackReducer]);
const navigation = useNavigation();
const {isOpen,title,content,screen,id_record}=props.snackReducer
useEffect(()=>{
if(isOpen)
setTimeout(()=>{
props.hideNotification()
},10000)
},[props.snackReducer])
return(
<Modal style={{padding:0,margin:0}} animationInTiming={1500} animationOutTiming={800} backdropOpacity={0}
animationIn={'slideInDown'} animationOut={'slideOutUp'} isVisible={isOpen} >
<View style={styles.container} >
<View style={{flex:1}}>
<Text style={styles.txtTitle}>{title}</Text>
<Text numberOfLines={2} style={styles.txt} >{content}</Text>
</View>
<View style={styles.row}>
<TouchableOpacity onPress={ ()=>props.hideNotification()} style={styles.btn} >
<Text style={styles.txtBtn}>Đóng</Text>
</TouchableOpacity>
<TouchableOpacity onPress={()=>{
props.hideNotification()
navigation.navigate(screen,{id:id_record})
}
} style={[styles.btn,{marginLeft:20}]}>
<Text style={styles.txtBtn} >Chi tiết</Text>
</TouchableOpacity>
</View>
return (
<Modal
style={{padding: 0, margin: 0}}
animationInTiming={1500}
animationOutTiming={800}
backdropOpacity={0}
animationIn={'slideInDown'}
animationOut={'slideOutUp'}
isVisible={isOpen}>
<View style={styles.container}>
<View style={{flex: 1}}>
<Text style={styles.txtTitle}>{title}</Text>
<Text numberOfLines={2} style={styles.txt}>
{content}
</Text>
</View>
<TouchableWithoutFeedback onPress={ ()=>props.hideNotification()} >
<View style={{flex:1}}>
<View style={styles.row}>
<TouchableOpacity
onPress={() => props.hideNotification()}
style={styles.btn}>
<Text style={styles.txtBtn}>Đóng</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
props.hideNotification();
navigate.navigate(screen, {id: id_record});
}}
style={[styles.btn, {marginLeft: 20}]}>
<Text style={styles.txtBtn}>Chi tiết</Text>
</TouchableOpacity>
</View>
</View>
<TouchableWithoutFeedback onPress={() => props.hideNotification()}>
<View style={{flex: 1}}></View>
</TouchableWithoutFeedback>
</Modal>
);
};
)
}
const mapStateToProps =(state) => {
const mapStateToProps = (state) => {
return {
snackReducer: state.SnackReducer,
};
};
export default connect(mapStateToProps, {showNotificaton,hideNotification})(SnackBar);
export default connect(mapStateToProps, {showNotificaton, hideNotification})(
SnackBar,
);
const styles=StyleSheet.create({
container:{
marginTop:10,
height:HEIGHTXD(380),
backgroundColor:R.colors.white,
marginHorizontal:10,
borderRadius:10,
paddingVertical:10,
paddingHorizontal:10,
const styles = StyleSheet.create({
container: {
marginTop: 10,
height: HEIGHTXD(380),
backgroundColor: R.colors.white,
marginHorizontal: 10,
borderRadius: 10,
paddingVertical: 10,
paddingHorizontal: 10,
shadowColor: '#000',
shadowOffset: {
width: 0,
......@@ -83,21 +95,21 @@ const styles=StyleSheet.create({
shadowRadius: 3.84,
elevation: 3,
},
row:{
flexDirection:'row',
justifyContent:'flex-end',
row: {
flexDirection: 'row',
justifyContent: 'flex-end',
},
txt:{
color:R.colors.black
txt: {
color: R.colors.black,
},
txtBtn:{
fontSize:getFontXD(42),
color:R.colors.txtMain,
fontWeight: 'bold'
txtBtn: {
fontSize: getFontXD(42),
color: R.colors.txtMain,
fontWeight: 'bold',
},
txtTitle:{
fontSize :getFontXD(42),
txtTitle: {
fontSize: getFontXD(42),
color: R.colors.black,
fontWeight:'bold'
}
})
fontWeight: 'bold',
},
});
/* eslint-disable no-console */
import React from 'react';
import React, {useEffect} from 'react';
import {Platform, View, Alert} from 'react-native';
import firebase from '@react-native-firebase/app';
import sampleaudio from '../../sampleaudio.mp3';
import messaging from '@react-native-firebase/messaging';
import AsyncStorage from '@react-native-community/async-storage';
import KEY from '../assets/AsynStorage';
class FirebaseNotification extends React.PureComponent {
checkPermission = () => {
firebase
.messaging()
.hasPermission()
.then((enabled) => {
if (enabled) {
this.getToken();
} else {
this.requestPermission();
}
import {showNotificaton, updateNotification} from '../actions/SnackBarAction';
import {connect} from 'react-redux';
const FirebaseNotification = (props) => {
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Message handled in the background!', remoteMessage);
});
useEffect(() => {
requestUserPermission();
const unsubscribe = messaging().onMessage(async (remoteMessage) => {
console.log('A new FCM message arrived!', remoteMessage);
props.showNotificaton({
title: 'Title',
content: 'Content notification',
screen: 'NOTIFICATION',
id_record: 9,
});
};
});
return unsubscribe;
}, []);
requestPermission = async () => {
try {
await firebase.messaging().requestPermission();
this.getToken();
} catch (error) {}
};
const requestUserPermission = async () => {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
getToken = async () => {
if (enabled) {
getFcmToken();
}
};
const getFcmToken = async () => {
let fcmToken = await AsyncStorage.getItem(KEY.FIREBASE);
console.log('Dat tao', fcmToken);
if (!fcmToken) {
fcmToken = await firebase.messaging().getToken();
console.log('Vua tao', fcmToken);
fcmToken = await messaging().getToken();
if (fcmToken) {
AsyncStorage.setItem(KEY.FIREBASE, fcmToken);
}
}
};
return <View />;
};
async componentDidMount() {
this.checkPermission();
this.createNotificationListeners();
this.removeNotificationDisplayedListener = firebase
.notifications()
.onNotificationDisplayed((notification) => {
console.log('Can alert', notification);
this.props.onReceived(notification);
// Process your notification as required
// ANDROID: Remote notifications do not contain the channel ID. You will have to specify this manually if you'd like to re-display the notification.
});
}
componentWillUnmount() {
this.removeNotificationDisplayedListener;
this.notificationListener;
this.notificationOpenedListener;
}
async createNotificationListeners() {
/*
* Triggered when a particular notification has been received in foreground
* */
console.log('Notification log');
const channel = new firebase.notifications.Android.Channel(
'500',
'Channel Name 1001',
firebase.notifications.Android.Importance.Max,
)
.setDescription('A natural description of the channel')
.setSound('default');
firebase.notifications().android.createChannel(channel);
this.notificationListener = firebase
.notifications()
.onNotification((notification) => {
console.log('notificaiton', notification);
if (Platform.OS === 'android') {
const localNotification = new firebase.notifications.Notification({
sound: sampleaudio,
show_in_foreground: true,
})
.setSound('default')
.setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setBody(notification.body)
.setData(notification.data)
.android.setChannelId('default_notification_channel_id') // e.g. the id you chose above
// .android.setSmallIcon('@mipmap/ic_launcher') // create this icon in Android Studio
// .android.setColor('red') // you can set a color here
.android.setPriority(firebase.notifications.Android.Priority.High)
.android.setVibrate([300])
.android.setDefaults([
firebase.notifications.Android.Defaults.Vibrate,
]);
console.log('Notification:', localNotification);
firebase
.notifications()
.displayNotification(localNotification)
.catch((err) => console.error('Chay vao day android', err));
} else if (Platform.OS === 'ios') {
const localNotification = new firebase.notifications.Notification()
.setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setSubtitle(notification.subtitle)
.setBody(notification.body)
.setData(notification.data)
.ios.setBadge(notification.ios.badge)
.ios.setLaunchImage('@mipmap/ic_stat_ic_notification');
firebase
.notifications()
.displayNotification(localNotification)
.catch((err) => console.error('Chay vao day', err));
}
// this.getNotifyNumber();
});
/*
* If your app is in background, you can listen for when a notification is clicked / tapped / opened as follows:
* */
this.notificationOpenedListener = firebase
.notifications()
.onNotificationOpened((notificationOpen) => {
this.props.onOpened(notificationOpen.notification);
});
/*
* If your app is closed, you can check if it was opened by a notification being clicked / tapped / opened as follows:
* */
const notificationOpen = await firebase
.notifications()
.getInitialNotification();
if (notificationOpen) {
this.props.onOpened(notificationOpen.notification);
}
/*
* Triggered for data only payload in foreground
* */
this.messageListener = firebase.messaging().onMessage((message) => {
// process data message
console.log('message---', message);
this.props.onReceived(message);
});
}
render() {
return <View />;
}
}
const mapStateToProps = (state) => {
return {
loadingModal: state.ModalLoadingReducer,
};
};
export default FirebaseNotification;
export default connect(mapStateToProps, {showNotificaton, updateNotification})(
FirebaseNotification,
);
......@@ -43,6 +43,7 @@ import LegaDocument from '../Screens/LegalDocument/LegalDocument';
import Business from '../Screens/LegalDocument/Business';
import Customer from '../Screens/LegalDocument/Customer';
import Partner from '../Screens/LegalDocument/Partner';
import SnackBar from '../components/SnackBar';
import * as ScreenName from './ScreenNames';
......
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