-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[#157929923] add-badge-messages #979
Changes from 12 commits
4fa82d7
2c986b9
1f775c1
4f7653e
cc4db3a
740cf3d
3c3eee9
c6076fa
d6c5379
c1c8ff7
1e29f4f
b5163eb
1715e8d
99c794d
571cefb
0e75fd4
31e64be
cb0706a
c6c1a47
15f204f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import * as pot from "italia-ts-commons/lib/pot"; | ||
import { Badge, View } from "native-base"; | ||
import React from "react"; | ||
import { Platform, StyleSheet, Text } from "react-native"; | ||
import { connect } from "react-redux"; | ||
import { lexicallyOrderedMessagesStateSelector } from "../store/reducers/entities/messages"; | ||
import { MessageState } from "../store/reducers/entities/messages/messagesById"; | ||
import { GlobalState } from "../store/reducers/types"; | ||
import variables from "../theme/variables"; | ||
import IconFont from "./ui/IconFont"; | ||
|
||
type OwnProps = { | ||
color?: string; | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
textBadgeStyle: { | ||
fontSize: 10, | ||
fontFamily: "Titillium Web", | ||
fontWeight: "bold", | ||
color: "white", | ||
flex: 1, | ||
position: "absolute", | ||
height: 19, | ||
width: 19, | ||
textAlign: "center", | ||
paddingRight: 3 | ||
}, | ||
badgeStyle: { | ||
backgroundColor: variables.brandPrimary, | ||
borderColor: "white", | ||
borderWidth: 2, | ||
position: "absolute", | ||
elevation: 0.1, | ||
shadowColor: "white", | ||
height: 19, | ||
width: 19, | ||
left: 12, | ||
bottom: 10 | ||
} | ||
}); | ||
|
||
type Props = OwnProps & ReturnType<typeof mapStateToProps>; | ||
|
||
/** | ||
* Filters the list of messages and returns the number of unread messages. | ||
*/ | ||
const getNumberMessagesUnread = ( | ||
potMessagesState: pot.Pot<ReadonlyArray<MessageState>, string> | ||
): number => | ||
pot.getOrElse( | ||
pot.map(potMessagesState, _ => | ||
_.filter(messageState => !messageState.isRead) | ||
), | ||
[] | ||
).length; | ||
|
||
/** | ||
* Message icon add badge. | ||
*/ | ||
class MessagesTabIcon extends React.PureComponent<Props> { | ||
public render() { | ||
const { color, messagesUnread } = this.props; | ||
return ( | ||
<View> | ||
<IconFont | ||
name={"io-messaggi"} | ||
size={variables.iconSize3} | ||
color={color} | ||
/> | ||
{messagesUnread > 0 ? ( | ||
Platform.OS === "ios" ? ( | ||
<Badge style={styles.badgeStyle}> | ||
<Text style={[styles.textBadgeStyle, { top: 0 }]}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No inline style |
||
{messagesUnread} | ||
</Text> | ||
</Badge> | ||
) : ( | ||
<Badge style={styles.badgeStyle}> | ||
<Text style={styles.textBadgeStyle}>{messagesUnread}</Text> | ||
</Badge> | ||
) | ||
) : null} | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state: GlobalState) => ({ | ||
messagesUnread: | ||
getNumberMessagesUnread(lexicallyOrderedMessagesStateSelector(state)) < 99 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are calling the function twice! |
||
? getNumberMessagesUnread(lexicallyOrderedMessagesStateSelector(state)) | ||
: 99 | ||
}); | ||
|
||
export default connect(mapStateToProps)(MessagesTabIcon); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why you removed the comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I didn't even notice it. Most likely I removed it while importing a library There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still removed |
||
* Main navigator, handling the navigation within | ||
* the app *after* the login has occurred. This takes | ||
* care of displaying a tab navigator with the | ||
* appropriate icons | ||
*/ | ||
|
||
import * as React from "react"; | ||
import { Platform, StyleSheet, Text } from "react-native"; | ||
import { | ||
|
@@ -14,7 +7,7 @@ import { | |
NavigationState, | ||
StackActions | ||
} from "react-navigation"; | ||
|
||
import MessagesTabIcon from "../components/MessagesTabIcon"; | ||
import ProfileTabIcon from "../components/ProfileTabIcon"; | ||
import IconFont from "../components/ui/IconFont"; | ||
import I18n from "../i18n"; | ||
|
@@ -25,7 +18,6 @@ import PreferencesNavigator from "./PreferencesNavigator"; | |
import ProfileNavigator from "./ProfileNavigator"; | ||
import ROUTES from "./routes"; | ||
import WalletNavigator from "./WalletNavigator"; | ||
|
||
type Routes = keyof typeof ROUTES; | ||
|
||
type RouteLabelMap = { [key in Routes]?: string }; | ||
|
@@ -87,6 +79,30 @@ const styles = StyleSheet.create({ | |
shadowRadius: variables.footerShadowRadius, | ||
// Android shadow | ||
elevation: variables.footerElevation | ||
}, | ||
textBadgeStyle: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not used anymore? |
||
fontSize: 10, | ||
fontFamily: "Titillium Web", | ||
fontWeight: "bold", | ||
color: "white", | ||
flex: 1, | ||
position: "absolute", | ||
height: 19, | ||
width: 19, | ||
textAlign: "center", | ||
paddingRight: 3 | ||
}, | ||
badgeStyle: { | ||
backgroundColor: variables.brandPrimary, | ||
borderColor: "white", | ||
borderWidth: 2, | ||
position: "absolute", | ||
elevation: 0.1, | ||
shadowColor: "white", | ||
height: 19, | ||
width: 19, | ||
left: 12, | ||
bottom: 10 | ||
} | ||
}); | ||
|
||
|
@@ -113,7 +129,6 @@ const getTabBarVisibility = ( | |
if (NoTabBarRoutes.indexOf(routeName) !== -1) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
|
@@ -166,22 +181,29 @@ const navigation = createBottomTabNavigator( | |
tabBarIcon: (options: { tintColor: string | null; focused: boolean }) => { | ||
const { routeName } = nav.state; | ||
const iconName: string = getIcon(routeName); | ||
|
||
if (routeName === ROUTES.MESSAGES_NAVIGATOR) { | ||
return ( | ||
<MessagesTabIcon | ||
color={options.tintColor === null ? undefined : options.tintColor} | ||
/> | ||
); | ||
} | ||
if (iconName === ROUTE_ICON.PROFILE_NAVIGATOR) { | ||
return ( | ||
<ProfileTabIcon | ||
size={variables.iconSize3} | ||
color={options.tintColor === null ? undefined : options.tintColor} | ||
/> | ||
); | ||
} else { | ||
return ( | ||
<IconFont | ||
name={iconName} | ||
size={variables.iconSize3} | ||
color={options.tintColor === null ? undefined : options.tintColor} | ||
/> | ||
); | ||
} | ||
return ( | ||
<IconFont | ||
name={iconName} | ||
size={variables.iconSize3} | ||
color={options.tintColor === null ? undefined : options.tintColor} | ||
/> | ||
); | ||
}, | ||
tabBarOnPress: options => { | ||
if (options.navigation.state.index > 0) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert this to a redux selector