-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…-with-multi-row #507 Badge highlight number with multi-row
- Loading branch information
Showing
13 changed files
with
480 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { routeList } from '../navigation/selectors'; | ||
import { generalStrings } from '../localization'; | ||
import { UIDatabase } from '../database'; | ||
|
||
const getBadgeData = routeName => { | ||
const dataType = routeName in routeList ? routeList[routeName] : ''; | ||
|
||
return [ | ||
{ | ||
count: | ||
dataType !== '' ? UIDatabase.objects(dataType).filtered('status != "finalised"').length : 0, | ||
title: `${generalStrings.unfinalised} ${generalStrings[routeName]}`, | ||
}, | ||
]; | ||
}; | ||
|
||
export default getBadgeData; | ||
export { getBadgeData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* Taken from https://github.com/react-native-training/react-native-elements | ||
* since we only need badge component. Tweaked the component class since we do not | ||
* need extra logic present in the code. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
const renderNode = (Component, content, defaultProps) => { | ||
if (content == null || content === false) { | ||
return null; | ||
} | ||
if (React.isValidElement(content)) { | ||
return content; | ||
} | ||
if (typeof content === 'function') { | ||
return content(); | ||
} | ||
// Just in case | ||
if (content === true) { | ||
return <Component {...defaultProps} />; | ||
} | ||
if (typeof content === 'string' || typeof content === 'number') { | ||
return <Component {...defaultProps}>{content}</Component>; | ||
} | ||
return <Component {...defaultProps} {...content} />; | ||
}; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export { renderNode }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* Taken from https://github.com/react-native-training/react-native-elements | ||
* since we only need badge component. Tweaked the component class since we do not | ||
* need extra logic present in the code. | ||
*/ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { StyleSheet, Text, View, TouchableOpacity, ViewPropTypes } from 'react-native'; | ||
import { renderNode } from '../utilities'; | ||
|
||
const Badge = props => { | ||
const { | ||
containerStyle, | ||
textStyle, | ||
badgeStyle, | ||
onPress, | ||
Component = onPress ? TouchableOpacity : View, | ||
value, | ||
...attributes | ||
} = props; | ||
|
||
const element = renderNode(Text, value, { | ||
style: StyleSheet.flatten([styles.text, textStyle && textStyle]), | ||
}); | ||
|
||
return ( | ||
<View style={StyleSheet.flatten([containerStyle && containerStyle])}> | ||
<Component | ||
{...attributes} | ||
style={StyleSheet.flatten([ | ||
styles.badge(), | ||
!element && styles.miniBadge, | ||
badgeStyle && badgeStyle, | ||
])} | ||
onPress={onPress} | ||
> | ||
{element} | ||
</Component> | ||
</View> | ||
); | ||
}; | ||
|
||
/* eslint-disable react/require-default-props */ | ||
Badge.propTypes = { | ||
containerStyle: ViewPropTypes.style, | ||
badgeStyle: ViewPropTypes.style, | ||
textStyle: Text.propTypes.style, | ||
value: PropTypes.node, | ||
onPress: PropTypes.func, | ||
Component: PropTypes.elementType, | ||
}; | ||
|
||
Badge.defaultProps = { | ||
containerStyle: {}, | ||
textStyle: {}, | ||
badgeStyle: {}, | ||
}; | ||
|
||
const size = 18; | ||
const miniSize = 8; | ||
|
||
const styles = { | ||
badge: () => ({ | ||
alignSelf: 'center', | ||
minWidth: size, | ||
height: size, | ||
borderRadius: size / 2, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
backgroundColor: '#FFF', | ||
borderWidth: StyleSheet.hairlineWidth, | ||
borderColor: '#fff', | ||
}), | ||
miniBadge: { | ||
paddingHorizontal: 0, | ||
paddingVertical: 0, | ||
minWidth: miniSize, | ||
height: miniSize, | ||
borderRadius: miniSize / 2, | ||
}, | ||
text: { | ||
fontSize: 12, | ||
color: 'white', | ||
paddingHorizontal: 4, | ||
}, | ||
}; | ||
|
||
export default Badge; |
Oops, something went wrong.