diff --git a/packages/yoga/src/Avatar/native/Avatar.jsx b/packages/yoga/src/Avatar/native/Avatar.jsx index f0d0653fd9..e2a186a76e 100644 --- a/packages/yoga/src/Avatar/native/Avatar.jsx +++ b/packages/yoga/src/Avatar/native/Avatar.jsx @@ -50,7 +50,6 @@ const Avatar = forwardRef( borderRadius, width, height, - onLayout, ...props }, ref, @@ -64,7 +63,6 @@ const Avatar = forwardRef( justifyContent="center" width={width} height={height} - onLayout={onLayout} overflow="hidden" borderRadius={borderRadius} {...props} diff --git a/packages/yoga/src/Result/native/Result/TextWithBadge/__snapshots__/index.test.tsx.snap b/packages/yoga/src/Result/native/Result/TextWithBadge/__snapshots__/index.test.tsx.snap index 266b506ce2..a4c6aa8f73 100644 --- a/packages/yoga/src/Result/native/Result/TextWithBadge/__snapshots__/index.test.tsx.snap +++ b/packages/yoga/src/Result/native/Result/TextWithBadge/__snapshots__/index.test.tsx.snap @@ -2,15 +2,11 @@ exports[`TextWithBadge should match snapshot 1`] = ` Text with badge @@ -146,15 +134,11 @@ exports[`TextWithBadge should match snapshot 1`] = ` exports[`TextWithBadge should match snapshot with long title 1`] = ` This is an example of a very long title that should be truncated @@ -290,15 +266,11 @@ exports[`TextWithBadge should match snapshot with long title 1`] = ` exports[`TextWithBadge should match snapshot without badgeIcon 1`] = ` Title without Badge diff --git a/packages/yoga/src/Result/native/Result/TextWithBadge/index.tsx b/packages/yoga/src/Result/native/Result/TextWithBadge/index.tsx index 7f2da21545..5fcb52f7a3 100644 --- a/packages/yoga/src/Result/native/Result/TextWithBadge/index.tsx +++ b/packages/yoga/src/Result/native/Result/TextWithBadge/index.tsx @@ -1,57 +1,18 @@ -import React, { ReactNode, useCallback, useState } from 'react'; -import { useWindowDimensions } from 'react-native'; +import React, { ReactNode } from 'react'; import Badge from '../../Badge'; import { StyledBoxContainer, StyledText } from './styles'; interface TextWithBadgeProps { - avatarWidth: number; badgeIcon: ReactNode; title: string; } -const SCREEN_PADDINGS = 20; -const CONTENT_MARGINS = 20; -const AVATAR_CONTENT_MARGINS = 16; -const BADGE_LIMIT = 20; - -const TextWithBadge = ({ - avatarWidth, - badgeIcon, - title, -}: TextWithBadgeProps) => { - const [textSize, setTextSize] = useState(0); - const { width: windowWidth } = useWindowDimensions(); - - const textMaxSize = - windowWidth - - (SCREEN_PADDINGS + CONTENT_MARGINS + AVATAR_CONTENT_MARGINS + avatarWidth); - const shouldTruncate = textSize >= textMaxSize - BADGE_LIMIT; - const containerWidth = shouldTruncate ? null : textSize; - const textWidth = shouldTruncate ? '100%' : null; - - const onTextLayout = useCallback( - ({ - nativeEvent: { - layout: { width }, - }, - }) => { - if (textSize === 0) { - setTextSize(width); - } - }, - [textSize], - ); - +const TextWithBadge = ({ badgeIcon, title }: TextWithBadgeProps) => { return ( - - + + {title} ` - ${({ containerWidth }) => - css` - flex-direction: row; - align-items: center; - justify-content: flex-end; - position: relative; - width: ${containerWidth}px; - `} +export const StyledBoxContainer = styled(Box)` + flex-direction: row; + align-items: center; `; export const StyledText = styled(Text.Body1)<{ - onLayout: ({ nativeEvent: { layout } }) => void; - textWidth?: string | null; numberOfLines: number; bold: boolean; children: React.ReactNode; }>` - ${({ - textWidth, - theme: { - yoga: { - spacing: { medium }, - }, - }, - }) => - css` - position: absolute; - left: 0; - padding-right: ${medium}; - flex: 1; - width: ${textWidth}; - `} + flex-shrink: 1; `; diff --git a/packages/yoga/src/Result/native/Result/__snapshots__/index.test.jsx.snap b/packages/yoga/src/Result/native/Result/__snapshots__/index.test.jsx.snap index ce7ef18058..472495dcd2 100644 --- a/packages/yoga/src/Result/native/Result/__snapshots__/index.test.jsx.snap +++ b/packages/yoga/src/Result/native/Result/__snapshots__/index.test.jsx.snap @@ -24,7 +24,6 @@ exports[` should match snapshot 1`] = ` display="flex" height={48} justifyContent="center" - onLayout={[Function]} overflow="hidden" style={ [ @@ -1050,7 +1049,6 @@ exports[` should match snapshot without attendence 1`] = ` display="flex" height={48} justifyContent="center" - onLayout={[Function]} overflow="hidden" style={ [ @@ -1561,7 +1559,6 @@ exports[` should match snapshot without limitLabel prop 1`] = ` display="flex" height={48} justifyContent="center" - onLayout={[Function]} overflow="hidden" style={ [ diff --git a/packages/yoga/src/Result/native/Result/index.jsx b/packages/yoga/src/Result/native/Result/index.jsx index 2d06358ae1..12e350fc6c 100644 --- a/packages/yoga/src/Result/native/Result/index.jsx +++ b/packages/yoga/src/Result/native/Result/index.jsx @@ -1,4 +1,4 @@ -import React, { isValidElement, useCallback, useState } from 'react'; +import React, { isValidElement } from 'react'; import { arrayOf, string, shape, func, bool, node } from 'prop-types'; import Text from '../../../Text'; @@ -23,30 +23,9 @@ const Result = ({ attendancesColor, badgeIcon, }) => { - const [avatarWidth, setAvatarWidth] = useState(0); - - const onAvatarLayout = useCallback( - ({ - nativeEvent: { - layout: { width }, - }, - }) => { - setAvatarWidth(width); - }, - [], - ); - return ( - {Avatar && ( - <> - {isValidElement(Avatar) ? ( - React.cloneElement(Avatar, { onLayout: onAvatarLayout }) - ) : ( - - )} - - )} + {Avatar && isValidElement(Avatar) ? Avatar : } {!!attendances?.length && ( )} {badgeIcon ? ( - + ) : (