-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added icon with badge example
- Loading branch information
Showing
7 changed files
with
145 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { memo, useMemo, useState, useEffect } from 'react'; | ||
import { View, StyleSheet, Text } from 'react-native'; | ||
|
||
interface BadgeProps { | ||
iconSize: number; | ||
} | ||
|
||
const BADGE_SIZE = 10; | ||
|
||
const BadgeComponent = ({ iconSize }: BadgeProps) => { | ||
const [count, setCount] = useState(1); | ||
const containerStyle = useMemo( | ||
() => ({ | ||
...styles.container, | ||
transform: [ | ||
{ translateX: (iconSize - BADGE_SIZE / 1.5) / 2 }, | ||
{ translateY: (iconSize - BADGE_SIZE / 1.5) / -2 }, | ||
], | ||
}), | ||
[iconSize] | ||
); | ||
|
||
useEffect(() => { | ||
const intervalId = setInterval(() => setCount(state => state + 1), 2500); | ||
return () => { | ||
clearInterval(intervalId); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<View style={containerStyle}> | ||
<Text style={styles.count}>{count}</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
const Badge = memo(BadgeComponent); | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
position: 'absolute', | ||
alignSelf: 'center', | ||
minWidth: BADGE_SIZE, | ||
minHeight: BADGE_SIZE, | ||
borderRadius: BADGE_SIZE, | ||
backgroundColor: 'red', | ||
}, | ||
count: { | ||
color: 'white', | ||
fontWeight: 'bold', | ||
textAlign: 'center', | ||
margin: 1, | ||
lineHeight: BADGE_SIZE, | ||
fontSize: 6, | ||
}, | ||
}); | ||
|
||
export default Badge; |
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 @@ | ||
export { default } from './Badge'; |
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,17 @@ | ||
import React, { memo } from 'react'; | ||
import HomeSVG from '../../svg/HomeSVG'; | ||
import Badge from '../badge'; | ||
import { SVGProps } from '../../svg/types'; | ||
|
||
const IconWithBadgeComponent = (props: SVGProps) => { | ||
return ( | ||
<> | ||
<HomeSVG {...props} /> | ||
<Badge iconSize={props.size} /> | ||
</> | ||
); | ||
}; | ||
|
||
const IconWithBadge = memo(IconWithBadgeComponent); | ||
|
||
export default IconWithBadge; |
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 @@ | ||
export { default } from './IconWithBadge'; |
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