Skip to content

Commit

Permalink
fix: custom position logic for badgeWrapper (#6864)
Browse files Browse the repository at this point in the history
* Fixed custom position logic for badgeWrapper

* Fixed lint error
  • Loading branch information
brianacnguyen authored Aug 2, 2023
1 parent 9c35255 commit 68c642c
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const styleSheet = (params: {
const { style, anchorElementShape, badgePosition, containerSize } = vars;
let anchoringOffset, positionObj, xOffset, yOffset;
const elementHeight = containerSize?.height || 0;
let isCustomPosition = false;

switch (anchorElementShape) {
case BadgeAnchorElementShape.Circular:
Expand Down Expand Up @@ -75,6 +76,7 @@ const styleSheet = (params: {
break;
default:
positionObj = badgePosition;
isCustomPosition = true;
xOffset = 0;
yOffset = 0;
}
Expand All @@ -84,16 +86,21 @@ const styleSheet = (params: {
{ position: 'relative', alignSelf: 'flex-start' } as ViewStyle,
style,
) as ViewStyle,
badge: {
// This is needed to pass the anchor element's bounding box to the Badge.
position: 'absolute',
height: elementHeight,
aspectRatio: 1,
alignItems: 'center',
justifyContent: 'center',
...positionObj,
transform: [{ translateX: xOffset }, { translateY: yOffset }],
},
badge: isCustomPosition
? {
position: 'absolute',
...positionObj,
}
: {
// This is needed to pass the anchor element's bounding box to the Badge.
position: 'absolute',
height: elementHeight,
aspectRatio: 1,
alignItems: 'center',
justifyContent: 'center',
...positionObj,
transform: [{ translateX: xOffset }, { translateY: yOffset }],
},
});
};

Expand Down

0 comments on commit 68c642c

Please sign in to comment.