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

Feature: Tooltip for QAB #40066

Merged
merged 62 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
35a5ce1
tooltip for qab
tienifr Apr 11, 2024
766a444
Merge branch 'main' into feature/tooltip-for-qab
tienifr Apr 11, 2024
5acd1c7
left align the tooltip
tienifr Apr 11, 2024
850b665
show tooltip on native
tienifr Apr 11, 2024
d1b9af2
add Spanish copy
tienifr Apr 11, 2024
4aa688e
fix typecheck
tienifr Apr 11, 2024
5efedaa
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Apr 12, 2024
77b2701
modify bold text on android
tienifr Apr 12, 2024
ea8719d
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Apr 12, 2024
2fa14e6
update font size
tienifr Apr 12, 2024
5c671c0
update color
tienifr Apr 12, 2024
e9f8545
Merge branch 'main' into feature/tooltip-for-qab
tienifr Apr 16, 2024
7b3cfc4
fix lint
tienifr Apr 16, 2024
7b21d6b
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Apr 19, 2024
ce51809
refactor basetooltip component
tienifr Apr 19, 2024
ee9b05c
fix lint
tienifr Apr 19, 2024
3fff71e
remove redundatn files
tienifr Apr 19, 2024
47ee590
fix typecheck
tienifr Apr 19, 2024
9fb96b9
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Apr 21, 2024
3222b20
refactor tooltip component tree to separate educationaltooltip and no…
tienifr Apr 21, 2024
4fdcb0f
rename TooltipRenderedOnPageBody to BaseGenericTooltip
tienifr Apr 22, 2024
b560b24
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Apr 22, 2024
dac74ad
get the available ref
tienifr Apr 22, 2024
b10224b
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Apr 23, 2024
c6fe70b
Merge branch 'main' into feature/tooltip-for-qab
tienifr Apr 24, 2024
c4b0c41
Resolve minor comments
tienifr Apr 24, 2024
f5a42e9
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Apr 24, 2024
9f1b0d7
Merge branch 'main' into feature/tooltip-for-qab
tienifr Apr 25, 2024
6f7a13a
move get bounding rect to platform-specific files
tienifr Apr 25, 2024
271510f
Merge branch 'main' into feature/tooltip-for-qab
tienifr May 2, 2024
e055182
fix android tooltip flickering
tienifr May 2, 2024
55be439
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr May 6, 2024
6aad7d9
remove redundant type cast
tienifr May 6, 2024
e662a0c
Merge branch 'main' into feature/tooltip-for-qab
tienifr May 7, 2024
f16f974
Merge branch 'main' into feature/tooltip-for-qab
tienifr May 7, 2024
76676da
fix lint
tienifr May 7, 2024
4b2008d
Merge branch 'main' into feature/tooltip-for-qab
tienifr May 14, 2024
ed21534
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr May 15, 2024
5085fae
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr May 15, 2024
9e314cb
animate tooltip on Web
tienifr May 15, 2024
7bbc2b0
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr May 17, 2024
afc084a
fix lint
tienifr May 17, 2024
584a98e
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr May 28, 2024
516c117
fix tooltip not unmount when children unmounts on mweb
tienifr May 28, 2024
d97caf8
render qab tooltip base on isFirstQuickAction
tienifr May 28, 2024
79c35c4
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr May 28, 2024
c7bd199
fix lint
tienifr May 28, 2024
d482636
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr May 29, 2024
0dc9cef
check for mobile browser to remove createPortal
tienifr May 29, 2024
e19dd31
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr May 30, 2024
2dfd7ae
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Jun 4, 2024
db11129
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Jun 5, 2024
f5f7316
resolve conflicts
tienifr Jun 5, 2024
baa8d0f
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Jun 6, 2024
b641092
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Jun 10, 2024
8714827
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Jun 12, 2024
28f8583
fix lint
tienifr Jun 12, 2024
bfab75d
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Jun 13, 2024
1373c0c
hide tooltip during popover animation out
tienifr Jun 13, 2024
84096b7
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Jun 13, 2024
eb35978
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Jun 14, 2024
6ef72be
Merge branch 'main' of https://github.com/tienifr/App into feature/to…
tienifr Jun 18, 2024
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
489 changes: 261 additions & 228 deletions src/components/MenuItem.tsx

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/components/PopoverMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ function PopoverMenu({
shouldShowSubscriptRightAvatar={item.shouldShowSubscriptRightAvatar}
disabled={item.disabled}
onFocus={() => setFocusedIndex(menuIndex)}
shouldRenderTooltip={item.shouldRenderTooltip}
shouldForceRenderingTooltipLeft={item.shouldForceRenderingTooltipLeft}
tooltipWrapperStyle={item.tooltipWrapperStyle}
renderTooltipContent={item.renderTooltipContent}
/>
))}
</View>
Expand Down
132 changes: 132 additions & 0 deletions src/components/Tooltip/BaseGenericTooltip/index.native.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import React, {useEffect, useMemo, useRef, useState} from 'react';
import {Animated, View} from 'react-native';
// eslint-disable-next-line no-restricted-imports
import type {Text as RNText, View as RNView} from 'react-native';
import Text from '@components/Text';
import useStyleUtils from '@hooks/useStyleUtils';
import textRef from '@src/types/utils/textRef';
import viewRef from '@src/types/utils/viewRef';
import type {BaseGenericTooltipProps} from './types';

// Props will change frequently.
// On every tooltip hover, we update the position in state which will result in re-rendering.
// We also update the state on layout changes which will be triggered often.
// There will be n number of tooltip components in the page.
// It's good to memoize this one.
function BaseGenericTooltip({
animation,
windowWidth,
xOffset,
yOffset,
targetWidth,
targetHeight,
shiftHorizontal = 0,
shiftVertical = 0,
text,
numberOfLines,
maxWidth = 0,
renderTooltipContent,
shouldForceRenderingBelow = false,
shouldForceRenderingLeft = false,
wrapperStyle = {},
}: BaseGenericTooltipProps) {
// The width of tooltip's inner content. Has to be undefined in the beginning
// as a width of 0 will cause the content to be rendered of a width of 0,
// which prevents us from measuring it correctly.
const [contentMeasuredWidth, setContentMeasuredWidth] = useState<number>();
// The height of tooltip's wrapper.
const [wrapperMeasuredHeight, setWrapperMeasuredHeight] = useState<number>();
const textContentRef = useRef<RNText>(null);
const viewContentRef = useRef<RNView>(null);
const rootWrapper = useRef<RNView>(null);

const StyleUtils = useStyleUtils();

useEffect(() => {
if (!textContentRef.current && !viewContentRef.current) {
return;
}
const contentRef = viewContentRef.current ?? textContentRef.current;
contentRef?.measure((x, y, width) => setContentMeasuredWidth(width));
}, []);

const {animationStyle, rootWrapperStyle, textStyle, pointerWrapperStyle, pointerStyle} = useMemo(
() =>
StyleUtils.getTooltipStyles({
tooltip: rootWrapper.current,
currentSize: animation,
windowWidth,
xOffset,
yOffset,
tooltipTargetWidth: targetWidth,
tooltipTargetHeight: targetHeight,
maxWidth,
tooltipContentWidth: contentMeasuredWidth,
tooltipWrapperHeight: wrapperMeasuredHeight,
manualShiftHorizontal: shiftHorizontal,
manualShiftVertical: shiftVertical,
shouldForceRenderingBelow,
shouldForceRenderingLeft,
wrapperStyle,
}),
[
StyleUtils,
animation,
windowWidth,
xOffset,
yOffset,
targetWidth,
targetHeight,
maxWidth,
contentMeasuredWidth,
wrapperMeasuredHeight,
shiftHorizontal,
shiftVertical,
shouldForceRenderingBelow,
shouldForceRenderingLeft,
wrapperStyle,
],
);

let content;
if (renderTooltipContent) {
content = <View ref={viewRef(viewContentRef)}>{renderTooltipContent()}</View>;
} else {
content = (
<Text
numberOfLines={numberOfLines}
style={textStyle}
>
<Text
style={textStyle}
ref={textRef(textContentRef)}
>
{text}
</Text>
</Text>
);
}

return (
<Animated.View
ref={viewRef(rootWrapper)}
style={[rootWrapperStyle, animationStyle]}
onLayout={(e) => {
const {height} = e.nativeEvent.layout;
if (height === wrapperMeasuredHeight) {
return;
}
setWrapperMeasuredHeight(height);
}}
>
{content}
<View style={pointerWrapperStyle}>
<View style={pointerStyle} />
</View>
</Animated.View>
);
}

BaseGenericTooltip.displayName = 'BaseGenericTooltip';

export default React.memo(BaseGenericTooltip);
Original file line number Diff line number Diff line change
@@ -1,47 +1,18 @@
import React, {useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react';
import React, {useLayoutEffect, useMemo, useRef, useState} from 'react';
import ReactDOM from 'react-dom';
import {Animated, View} from 'react-native';
import Text from '@components/Text';
import useStyleUtils from '@hooks/useStyleUtils';
import Log from '@libs/Log';
import textRef from '@src/types/utils/textRef';
import viewRef from '@src/types/utils/viewRef';
import type TooltipProps from './types';

type TooltipRenderedOnPageBodyProps = {
/** Window width */
windowWidth: number;

/** Tooltip Animation value */
animation: Animated.Value;

/** The distance between the left side of the wrapper view and the left side of the window */
xOffset: number;

/** The distance between the top of the wrapper view and the top of the window */
yOffset: number;

/** The width of the tooltip's target */
targetWidth: number;

/** The height of the tooltip's target */
targetHeight: number;

/** Any additional amount to manually adjust the horizontal position of the tooltip.
A positive value shifts the tooltip to the right, and a negative value shifts it to the left. */
shiftHorizontal?: number;

/** Any additional amount to manually adjust the vertical position of the tooltip.
A positive value shifts the tooltip down, and a negative value shifts it up. */
shiftVertical?: number;
} & Pick<TooltipProps, 'renderTooltipContent' | 'maxWidth' | 'numberOfLines' | 'text' | 'shouldForceRenderingBelow'>;
import type {BaseGenericTooltipProps} from './types';

// Props will change frequently.
// On every tooltip hover, we update the position in state which will result in re-rendering.
// We also update the state on layout changes which will be triggered often.
// There will be n number of tooltip components in the page.
// It's good to memoize this one.
function TooltipRenderedOnPageBody({
function BaseGenericTooltip({
animation,
windowWidth,
xOffset,
Expand All @@ -55,7 +26,9 @@ function TooltipRenderedOnPageBody({
maxWidth = 0,
renderTooltipContent,
shouldForceRenderingBelow = false,
}: TooltipRenderedOnPageBodyProps) {
wrapperStyle = {},
shouldForceRenderingLeft = false,
}: BaseGenericTooltipProps) {
// The width of tooltip's inner content. Has to be undefined in the beginning
// as a width of 0 will cause the content to be rendered of a width of 0,
// which prevents us from measuring it correctly.
Expand All @@ -67,13 +40,6 @@ function TooltipRenderedOnPageBody({

const StyleUtils = useStyleUtils();

useEffect(() => {
if (!renderTooltipContent || !text) {
return;
}
Log.warn('Developer error: Cannot use both text and renderTooltipContent props at the same time in <TooltipRenderedOnPageBody />!');
}, [text, renderTooltipContent]);

useLayoutEffect(() => {
// Calculate the tooltip width and height before the browser repaints the screen to prevent flicker
// because of the late update of the width and the height from onLayout.
Expand All @@ -97,6 +63,8 @@ function TooltipRenderedOnPageBody({
manualShiftHorizontal: shiftHorizontal,
manualShiftVertical: shiftVertical,
shouldForceRenderingBelow,
shouldForceRenderingLeft,
wrapperStyle,
}),
[
StyleUtils,
Expand All @@ -112,6 +80,8 @@ function TooltipRenderedOnPageBody({
shiftHorizontal,
shiftVertical,
shouldForceRenderingBelow,
shouldForceRenderingLeft,
wrapperStyle,
],
);

Expand Down Expand Up @@ -154,6 +124,6 @@ function TooltipRenderedOnPageBody({
);
}

TooltipRenderedOnPageBody.displayName = 'TooltipRenderedOnPageBody';
BaseGenericTooltip.displayName = 'BaseGenericTooltip';

export default React.memo(TooltipRenderedOnPageBody);
export default React.memo(BaseGenericTooltip);
33 changes: 33 additions & 0 deletions src/components/Tooltip/BaseGenericTooltip/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type {Animated} from 'react-native';
import type TooltipProps from '@components/Tooltip/types';

type BaseGenericTooltipProps = {
/** Window width */
windowWidth: number;

/** Tooltip Animation value */
animation: Animated.Value;

/** The distance between the left side of the wrapper view and the left side of the window */
xOffset: number;

/** The distance between the top of the wrapper view and the top of the window */
yOffset: number;

/** The width of the tooltip's target */
targetWidth: number;

/** The height of the tooltip's target */
targetHeight: number;

/** Any additional amount to manually adjust the horizontal position of the tooltip.
A positive value shifts the tooltip to the right, and a negative value shifts it to the left. */
shiftHorizontal?: number;

/** Any additional amount to manually adjust the vertical position of the tooltip.
A positive value shifts the tooltip down, and a negative value shifts it up. */
shiftVertical?: number;
} & Pick<TooltipProps, 'renderTooltipContent' | 'maxWidth' | 'numberOfLines' | 'text' | 'shouldForceRenderingBelow' | 'wrapperStyle' | 'shouldForceRenderingLeft'>;

// eslint-disable-next-line import/prefer-default-export
export type {BaseGenericTooltipProps};
Loading
Loading