-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
badge support #70
Merged
Merged
badge support #70
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
55501ff
badge support
ShayanJavadi 246a2e6
remove react-native-material-ui
ShayanJavadi 12dfe07
Added Badge.js
ShayanJavadi f51f54c
updated prop types
ShayanJavadi 8d8c6eb
removed old prop type
ShayanJavadi ff505da
documented badge changes
ShayanJavadi cff8403
fixed isBadgeVisible documentation
ShayanJavadi 99ed535
Final changes
ShayanJavadi 6d2d59f
final changes
ShayanJavadi 3f70221
removed extra dependencies
ShayanJavadi d1566fa
android compatibility
ShayanJavadi 30c1f93
android compatibility
ShayanJavadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Material badge for showing notifications, maybe more functionality in the future | ||
* @flow | ||
*/ | ||
|
||
import React, { Component } from 'react' | ||
import { | ||
View, | ||
Text, | ||
StyleSheet | ||
} from 'react-native'; | ||
|
||
type BProps = { | ||
text: string, | ||
size: number, | ||
children: Array<ReactElement<*>>, | ||
style: any, | ||
isVisible: boolean, | ||
} | ||
|
||
const defaultProps = { | ||
size: 20, | ||
isVisible: true, | ||
style: {}, | ||
} | ||
|
||
export default class Badge extends Component { | ||
static defaultProps: typeof defaultProps | ||
props: BProps | ||
static defaultProps = defaultProps | ||
|
||
createStyles() { | ||
const { size, style } = this.props; | ||
const container = Object.assign( | ||
{}, | ||
{ | ||
position: "absolute", | ||
width: size, | ||
height: size, | ||
borderRadius: size / 2, | ||
alignItems: "center", | ||
justifyContent: "center", | ||
backgroundColor: "#F50057", | ||
zIndex: 9999, | ||
bottom: 10, | ||
}, | ||
style.container | ||
); | ||
|
||
const text = Object.assign( | ||
{}, | ||
{ | ||
color: "#fff", | ||
fontWeight: "500", | ||
fontSize: 12, | ||
}, | ||
style.text | ||
) | ||
|
||
return StyleSheet.create({ | ||
container, | ||
text, | ||
}) | ||
} | ||
|
||
render() { | ||
const { children, text, isVisible } = this.props; | ||
const styles = this.createStyles(); | ||
if (!isVisible) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<View> | ||
<View style={styles.container}> | ||
<Text style={styles.text}>{text}</Text> | ||
</View> | ||
</View> | ||
) | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For android compatibility: Remove the isVisible check, lines 70-72. The check is already done in Tab.js
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.
So the check
badgeText === undefined && !isBadgeVisible
is to prevent the badge from rendering when there is no text. The check in here is for the user to be able to hide a badge even when there is text. We should keep this checkThere 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.
Ok, I see.