Skip to content

Temporarily support string for Badge size #1580

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

Merged
merged 1 commit into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generatedTypes/src/components/avatar/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ declare class Avatar extends PureComponent<AvatarProps> {
getRibbonStyle(): StyleProp<ViewStyle>;
getBadgeBorderWidth: () => any;
getBadgeColor(): any;
getBadgeSize: () => number;
getBadgeSize: () => string | number;
getBadgePosition: () => object;
renderBadge(): JSX.Element | undefined;
renderRibbon(): JSX.Element | undefined;
Expand Down
6 changes: 3 additions & 3 deletions generatedTypes/src/components/badge/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export declare type BadgeProps = ViewProps & TouchableOpacityProps & {
/**
* the badge size
*/
size?: number;
size?: number | string;
/**
* Press handler
*/
Expand Down Expand Up @@ -83,7 +83,7 @@ declare class Badge extends PureComponent<BadgeProps> {
accessibilityRole: string;
accessibilityLabel: string;
};
get size(): number;
get size(): string | number;
isSmallBadge(): boolean;
getBadgeSizeStyle(): any;
getFormattedLabel(): any;
Expand Down Expand Up @@ -343,7 +343,7 @@ declare const _default: React.ComponentClass<ViewProps & TouchableOpacityProps &
/**
* the badge size
*/
size?: number | undefined;
size?: string | number | undefined;
/**
* Press handler
*/
Expand Down
1 change: 1 addition & 0 deletions src/components/avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class Avatar extends PureComponent<AvatarProps> {
const radius = size / 2;
const x = Math.sqrt(radius ** 2 * 2);
const y = x - radius;
// @ts-expect-error TODO: once badge size will stop supporting string type this should be resolved
const shift = Math.sqrt(y ** 2 / 2) - (this.getBadgeSize() + this.getBadgeBorderWidth() * 2) / 2;
const badgeLocation = _.split(_.toLower(badgePosition), '_', 2);
const badgeAlignment = {position: 'absolute', [badgeLocation[0]]: shift, [badgeLocation[1]]: shift};
Expand Down
2 changes: 1 addition & 1 deletion src/components/badge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type BadgeProps = ViewProps &
/**
* the badge size
*/
size?: number;
size?: number | string;
/**
* Press handler
*/
Expand Down