Skip to content

Commit

Permalink
Merge pull request #35460 from tienifr/fix/34961
Browse files Browse the repository at this point in the history
Fix: Web - Settings - The same text is also displayed as tooltips
  • Loading branch information
stitesExpensify authored Feb 5, 2024
2 parents e287420 + a9adf81 commit e37afd2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 44 deletions.
31 changes: 9 additions & 22 deletions src/components/SelectionList/RadioListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import {View} from 'react-native';
import Text from '@components/Text';
import Tooltip from '@components/Tooltip';
import TextWithTooltip from '@components/TextWithTooltip';
import useThemeStyles from '@hooks/useThemeStyles';
import type {RadioListItemProps} from './types';

Expand All @@ -10,30 +9,18 @@ function RadioListItem({item, showTooltip, textStyles, alternateTextStyles}: Rad

return (
<View style={[styles.flex1, styles.alignItemsStart]}>
<Tooltip
shouldRender={showTooltip}
<TextWithTooltip
shouldShowTooltip={showTooltip}
text={item.text}
>
<Text
style={textStyles}
numberOfLines={1}
>
{item.text}
</Text>
</Tooltip>
textStyles={textStyles}
/>

{!!item.alternateText && (
<Tooltip
shouldRender={showTooltip}
<TextWithTooltip
shouldShowTooltip={showTooltip}
text={item.alternateText}
>
<Text
style={alternateTextStyles}
numberOfLines={1}
>
{item.alternateText}
</Text>
</Tooltip>
textStyles={alternateTextStyles}
/>
)}
</View>
);
Expand Down
31 changes: 9 additions & 22 deletions src/components/SelectionList/UserListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import {View} from 'react-native';
import SubscriptAvatar from '@components/SubscriptAvatar';
import Text from '@components/Text';
import Tooltip from '@components/Tooltip';
import TextWithTooltip from '@components/TextWithTooltip';
import useThemeStyles from '@hooks/useThemeStyles';
import type {UserListItemProps} from './types';

Expand All @@ -18,29 +17,17 @@ function UserListItem({item, textStyles, alternateTextStyles, showTooltip, style
/>
)}
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch, styles.optionRow]}>
<Tooltip
shouldRender={showTooltip}
<TextWithTooltip
shouldShowTooltip={showTooltip}
text={item.text}
>
<Text
style={[textStyles, style]}
numberOfLines={1}
>
{item.text}
</Text>
</Tooltip>
textStyles={[textStyles, style]}
/>
{!!item.alternateText && (
<Tooltip
shouldRender={showTooltip}
<TextWithTooltip
shouldShowTooltip={showTooltip}
text={item.alternateText}
>
<Text
style={[alternateTextStyles, style]}
numberOfLines={1}
>
{item.alternateText}
</Text>
</Tooltip>
textStyles={[alternateTextStyles, style]}
/>
)}
</View>
{!!item.rightElement && item.rightElement}
Expand Down
18 changes: 18 additions & 0 deletions src/components/TextWithTooltip/index.native.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import Text from '@components/Text';
import type TextWithTooltipProps from './types';

function TextWithTooltip({text, textStyles}: TextWithTooltipProps) {
return (
<Text
style={textStyles}
numberOfLines={1}
>
{text}
</Text>
);
}

TextWithTooltip.displayName = 'TextWithTooltip';

export default TextWithTooltip;
41 changes: 41 additions & 0 deletions src/components/TextWithTooltip/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, {useState} from 'react';
import Text from '@components/Text';
import Tooltip from '@components/Tooltip';
import type TextWithTooltipProps from './types';

type LayoutChangeEvent = {
target: HTMLElement;
};

function TextWithTooltip({text, shouldShowTooltip, textStyles}: TextWithTooltipProps) {
const [showTooltip, setShowTooltip] = useState(false);

return (
<Tooltip
shouldRender={showTooltip}
text={text}
>
<Text
style={textStyles}
numberOfLines={1}
onLayout={(e) => {
const target = (e.nativeEvent as unknown as LayoutChangeEvent).target;
if (!shouldShowTooltip) {
return;
}
if (target.scrollWidth > target.offsetWidth) {
setShowTooltip(true);
return;
}
setShowTooltip(false);
}}
>
{text}
</Text>
</Tooltip>
);
}

TextWithTooltip.displayName = 'TextWithTooltip';

export default TextWithTooltip;
9 changes: 9 additions & 0 deletions src/components/TextWithTooltip/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {StyleProp, TextStyle} from 'react-native';

type TextWithTooltipProps = {
text: string;
shouldShowTooltip: boolean;
textStyles?: StyleProp<TextStyle>;
};

export default TextWithTooltipProps;

0 comments on commit e37afd2

Please sign in to comment.