updated notification texts, added support for navigation

This commit is contained in:
Nouman Tahir 2021-05-26 19:44:46 +05:00
parent 83b2da00e2
commit 00babcca8e
6 changed files with 130 additions and 25 deletions

View File

@ -1,44 +1,84 @@
import { get, isEmpty, some } from 'lodash';
import React, { useEffect, useRef, useState} from 'react'; import React, { useEffect, useRef, useState} from 'react';
import { Animated, Text, View } from 'react-native'; import { Animated, Text, TouchableOpacity, View } from 'react-native';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import { IconButton } from '..'; import { IconButton } from '..';
import { toastNotification } from '../../redux/actions/uiAction'; import { toastNotification } from '../../redux/actions/uiAction';
import UserAvatar from '../userAvatar'; import UserAvatar from '../userAvatar';
import ROUTES from '../../constants/routeNames';
// Styles // Styles
import styles, { CONTAINER_HEIGHT } from './styles'; import styles, { CONTAINER_HEIGHT } from './styles';
import { navigate } from '../../navigation/service';
import { useIntl } from 'react-intl';
interface RemoteMessage {
data:{
id:string;
source:string;
target:string;
permlink1:string;
permlink2:string;
permlink3:string;
type:'reblog'|'reply';
};
notification:{
body:string;
title:string;
}
}
interface Props { interface Props {
title:string; remoteMessage:RemoteMessage
text:string;
usename:string;
} }
const ForegroundNotification = ({text, title, username }:Props) => { const ForegroundNotification = ({remoteMessage}:Props) => {
let hideTimeout = null; let hideTimeout = null;
const dispatch = useDispatch(); const dispatch = useDispatch();
const intl = useIntl();
const [duration] = useState(4000); const [duration] = useState(5000);
const [curText, setCurText] = useState(text); const [activeId, setActiveId] = useState('');
const [isVisible, setIsVisible] = useState(false); const [isVisible, setIsVisible] = useState(false);
const [username, setUsername] = useState('');
const [title, setTitle] = useState('');
const [body, setBody] = useState('');
const animatedValue = useRef(new Animated.Value(-CONTAINER_HEIGHT)).current; const animatedValue = useRef(new Animated.Value(-CONTAINER_HEIGHT)).current;
useEffect(() => { useEffect(() => {
if(text !== curText && text !== ''){
setCurText(text); if(remoteMessage){
show(); const {source, target, type, id} = remoteMessage.data;
if(activeId !== id){
switch(type){
case 'reply':
setTitle(`${intl.formatMessage({id:'notification.reply_on'})} @${target}`);
setBody(intl.formatMessage({id:'notification.reply_body'}));
break;
case 'reblog':
setTitle(`${intl.formatMessage({id:'notification.post_on'})} @${target} ${intl.formatMessage({id:'notification.reblog'})}`);
setBody(intl.formatMessage({id:'notification.reblog_body'}));
break;
}
setActiveId(id);
setUsername(source);
show();
}
} }
return ()=>{ return ()=>{
if(hideTimeout){ if(hideTimeout){
clearTimeout(hideTimeout); clearTimeout(hideTimeout);
} }
} }
}, [text]); }, [remoteMessage]);
const show = () => { const show = () => {
// Will change fadeAnim value to 1 in 5 seconds // Will change fadeAnim value to 1 in 5 seconds
@ -71,6 +111,43 @@ const ForegroundNotification = ({text, title, username }:Props) => {
}; };
const _onPress = () => {
const {data} = remoteMessage;
const fullPermlink =
get(data, 'permlink1', '') + get(data, 'permlink2', '') + get(data, 'permlink3', '');
let params:any = {};
let key = '';
let routeName = '';
switch(data.type){
case 'reblog':
params = {
author: get(remoteMessage, 'target', ''),
permlink: fullPermlink,
};
key = fullPermlink;
routeName = ROUTES.SCREENS.POST;
break;
case 'reply':
params = {
author: get(remoteMessage, 'source', ''),
permlink: fullPermlink,
};
key = fullPermlink;
routeName = ROUTES.SCREENS.POST;
break;
}
if (!some(params, isEmpty)) {
navigate({
routeName,
params,
key,
});
}
}
return ( return (
<Animated.View <Animated.View
@ -81,15 +158,18 @@ const ForegroundNotification = ({text, title, username }:Props) => {
> >
<View style={{flexDirection:'row', justifyContent:'space-between', alignItems:'center', paddingBottom:16, paddingHorizontal:16}}> <View style={{flexDirection:'row', justifyContent:'space-between', alignItems:'center', paddingBottom:16, paddingHorizontal:16}}>
<View style={{flexDirection:'row'}}> <TouchableOpacity onPress={_onPress}>
<UserAvatar username={username}/> <View style={{flexDirection:'row', flex:1, marginRight:24}}>
<UserAvatar username={username}/>
<View>
<Text style={styles.text} numberOfLines={1}>{title}</Text>
<Text style={styles.text} numberOfLines={1}>{body}</Text>
</View>
<View>
<Text style={styles.text}>{title}</Text>
<Text style={styles.text}>{text}</Text>
</View> </View>
</TouchableOpacity>
</View>
<IconButton <IconButton

View File

@ -1,3 +1,4 @@
import { Dimensions } from 'react-native';
import EStyleSheet from 'react-native-extended-stylesheet'; import EStyleSheet from 'react-native-extended-stylesheet';
export const CONTAINER_HEIGHT = 108; export const CONTAINER_HEIGHT = 108;
@ -10,7 +11,7 @@ export default EStyleSheet.create({
maxWidth: '$deviceWidth', maxWidth: '$deviceWidth',
minWidth: '$deviceWidth / 1.9', minWidth: '$deviceWidth / 1.9',
height: CONTAINER_HEIGHT, height: CONTAINER_HEIGHT,
width:'100%', width:Dimensions.get('screen').width,
backgroundColor: '$primaryDarkText', backgroundColor: '$primaryDarkText',
shadowOffset: { shadowOffset: {
height: 5, height: 5,
@ -21,10 +22,10 @@ export default EStyleSheet.create({
top:0, top:0,
}, },
text: { text: {
flex:1,
color: 'white', color: 'white',
fontWeight: 'bold', fontWeight: 'bold',
fontSize: 14, fontSize: 14,
paddingRight: 10,
paddingLeft:16, paddingLeft:16,
}, },
}); });

View File

@ -134,7 +134,11 @@
"replies": "Replies", "replies": "Replies",
"mentions": "Mentions", "mentions": "Mentions",
"reblogs": "Reblogs", "reblogs": "Reblogs",
"noactivity": "No recent activity" "noactivity": "No recent activity",
"post_on":"Post on",
"reply_on":"New reply on",
"reblog_body":"Yay! tap to check all post reblogs...",
"reply_body":"Tap to continue conversation..."
}, },
"leaderboard": { "leaderboard": {
"daily": "DAILY", "daily": "DAILY",

View File

@ -113,6 +113,7 @@ class ApplicationContainer extends Component {
isThemeReady: false, isThemeReady: false,
appState: AppState.currentState, appState: AppState.currentState,
showWelcomeModal: false, showWelcomeModal: false,
foregroundNotificationData: null,
}; };
} }
@ -453,6 +454,7 @@ class ApplicationContainer extends Component {
markActivityAsRead(username, activity_id).then((result) => { markActivityAsRead(username, activity_id).then((result) => {
dispatch(updateUnreadActivityCount(result.unread)); dispatch(updateUnreadActivityCount(result.unread));
}); });
if (!some(params, isEmpty)) { if (!some(params, isEmpty)) {
navigate({ navigate({
routeName, routeName,
@ -480,7 +482,10 @@ class ApplicationContainer extends Component {
firebaseOnMessageListener = messaging().onMessage((remoteMessage) => { firebaseOnMessageListener = messaging().onMessage((remoteMessage) => {
console.log('Notification Received: foreground', remoteMessage); console.log('Notification Received: foreground', remoteMessage);
this._showNotificationToast(remoteMessage); // this._showNotificationToast(remoteMessage);
this.setState({
foregroundNotificationData: remoteMessage,
});
this._pushNavigate(remoteMessage); this._pushNavigate(remoteMessage);
}); });
@ -816,7 +821,13 @@ class ApplicationContainer extends Component {
isPinCodeRequire, isPinCodeRequire,
rcOffer, rcOffer,
} = this.props; } = this.props;
const { isRenderRequire, isReady, isThemeReady, showWelcomeModal } = this.state; const {
isRenderRequire,
isReady,
isThemeReady,
showWelcomeModal,
foregroundNotificationData,
} = this.state;
return ( return (
children && children &&
@ -831,6 +842,7 @@ class ApplicationContainer extends Component {
rcOffer, rcOffer,
toastNotification, toastNotification,
showWelcomeModal, showWelcomeModal,
foregroundNotificationData,
handleWelcomeModalButtonPress: this._handleWelcomeModalButtonPress, handleWelcomeModalButtonPress: this._handleWelcomeModalButtonPress,
}) })
); );

View File

@ -35,6 +35,7 @@ const Application = () => {
toastNotification, toastNotification,
showWelcomeModal, showWelcomeModal,
handleWelcomeModalButtonPress, handleWelcomeModalButtonPress,
foregroundNotificationData,
}) => { }) => {
const _isAppReady = !showAnimation && isReady && isRenderRequire && isThemeReady; const _isAppReady = !showAnimation && isReady && isRenderRequire && isThemeReady;
@ -68,6 +69,7 @@ const Application = () => {
isReady={isReady} isReady={isReady}
isDarkTheme={isDarkTheme} isDarkTheme={isDarkTheme}
rcOffer={rcOffer} rcOffer={rcOffer}
foregroundNotificationData={foregroundNotificationData}
/> />
)} )}
{!_isAppReady && <LaunchScreen />} {!_isAppReady && <LaunchScreen />}

View File

@ -107,7 +107,13 @@ class ApplicationScreen extends Component {
} }
render() { render() {
const { isConnected, isDarkTheme, toastNotification, isReady } = this.props; const {
isConnected,
isDarkTheme,
toastNotification,
isReady,
foregroundNotificationData,
} = this.props;
const { isShowToastNotification, showWelcomeModal } = this.state; const { isShowToastNotification, showWelcomeModal } = this.state;
const barStyle = isDarkTheme ? 'light-content' : 'dark-content'; const barStyle = isDarkTheme ? 'light-content' : 'dark-content';
const barColor = isDarkTheme ? '#1e2835' : '#fff'; const barColor = isDarkTheme ? '#1e2835' : '#fff';
@ -162,7 +168,7 @@ class ApplicationScreen extends Component {
/> />
)} )}
<ForegroundNotification title="New Apvote" text="" username="demo.com" /> <ForegroundNotification remoteMessage={foregroundNotificationData} />
<AccountsBottomSheet /> <AccountsBottomSheet />
<ActionModal /> <ActionModal />
</View> </View>