Skip to content
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

Fix: Web - Settings - The same text is also displayed as tooltips #35460

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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.alignItemsStart, 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;
Loading