-
Notifications
You must be signed in to change notification settings - Fork 3.9k
92969: Add "expand" button overlay to charts for full-screen mode #95249
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
Open
abbasifaizan70
wants to merge
16
commits into
Expensify:main
Choose a base branch
from
abbasifaizan70:92969
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
876b9b5
92969: Add 'expand' button overlay to charts for full-screen mode
abbasifaizan70 9472088
Merge branch 'main' into 92969
abbasifaizan70 a01e219
fix: scale expanded chart to fit modal and constrain inline chart wra…
abbasifaizan70 6bca919
Merge branch 'main' into 92969
abbasifaizan70 71565b9
fixed FMT issues
abbasifaizan70 bb9bb9f
Merge branch 'Expensify:main' into 92969
abbasifaizan70 45f1e90
fix: use standard icon button for chart expand and address review fee…
abbasifaizan70 5914bf2
Merge branch 'Expensify:main' into 92969
abbasifaizan70 463f4ea
Fixed esLint issues
abbasifaizan70 6338c11
Merge branch '92969' of https://github.com/abbasifaizan70/Expensify i…
abbasifaizan70 159724a
implement hover button
abbasifaizan70 1ab3291
Merge branch 'main' into 92969
abbasifaizan70 3948b52
fix: address review feedback - theme-resolved modal background, polar…
abbasifaizan70 5d81dfb
Fixed lint issu
abbasifaizan70 836997e
Merge branch 'Expensify:main' into 92969
abbasifaizan70 aa02f48
test: add deviceHasHoverSupport to useHover mocks
abbasifaizan70 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...EngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartExpandButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import Button from '@components/ButtonComposed'; | ||
| import Tooltip from '@components/Tooltip'; | ||
|
|
||
| import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
|
|
||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
|
|
||
| type VictoryChartExpandButtonProps = { | ||
| /** Called when the user presses the expand button */ | ||
| onPress: () => void; | ||
|
|
||
| /** Whether the button should be visible. It stays mounted (hidden via opacity) so hover in/out doesn't reflow the chart. */ | ||
| shouldShow: boolean; | ||
| }; | ||
|
|
||
| function VictoryChartExpandButton({onPress, shouldShow}: VictoryChartExpandButtonProps) { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const icons = useMemoizedLazyExpensifyIcons(['Expand']); | ||
|
|
||
| return ( | ||
| <Tooltip text={translate('common.expand')}> | ||
| {/* Overlays the chart's top-right corner without affecting the chart's layout. When visible, the | ||
| button intentionally captures pointer events in that corner, suppressing any underlying chart | ||
| gesture layer — acceptable since charts render nothing interactive there. While hidden it | ||
| ignores pointer events entirely so an invisible button can never swallow presses. */} | ||
| <View | ||
| style={[styles.pAbsolute, styles.t0, styles.r0, styles.m3, !shouldShow && styles.opacity0]} | ||
| pointerEvents={shouldShow ? 'auto' : 'none'} | ||
| > | ||
| <Button | ||
| size={CONST.BUTTON_SIZE.SMALL} | ||
| onPress={onPress} | ||
| accessibilityLabel={translate('common.expand')} | ||
| sentryLabel={CONST.SENTRY_LABEL.HTML_RENDERER.VICTORY_CHART_EXPAND_BUTTON} | ||
| > | ||
| <Button.Icon src={icons.Expand} /> | ||
| </Button> | ||
| </View> | ||
| </Tooltip> | ||
| ); | ||
| } | ||
|
|
||
| VictoryChartExpandButton.displayName = 'VictoryChartExpandButton'; | ||
|
|
||
| export default VictoryChartExpandButton; |
131 changes: 131 additions & 0 deletions
131
...LEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartExpandModal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
| import {CHART_TYPE, POLAR_CONTAINER_HEIGHT_RATIO} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/constants'; | ||
| import {useVictoryChartContext} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/context/VictoryChartContext'; | ||
| import {resolveChartContainerBgColor} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/resolveChartThemeColor'; | ||
| import Modal from '@components/Modal'; | ||
|
|
||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useStyleUtils from '@hooks/useStyleUtils'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
|
|
||
| import type {LayoutChangeEvent} from 'react-native'; | ||
|
|
||
| import React, {useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
|
|
||
| import VictoryChartContent from './VictoryChartContent'; | ||
|
|
||
| type VictoryChartExpandModalProps = { | ||
| /** Whether the modal is visible */ | ||
| isVisible: boolean; | ||
|
|
||
| /** Called when the modal should close */ | ||
| onClose: () => void; | ||
|
|
||
| /** Called once the modal's closing animation has finished */ | ||
| onModalHide?: () => void; | ||
| }; | ||
|
|
||
| /** | ||
| * Centered full-screen modal that re-renders the current chart scaled up to the viewport. | ||
| * Must be rendered inside a VictoryChartProvider so VictoryChartContent can read the parsed chart context. | ||
| * | ||
| * The chart is rendered at its design size and uniformly transform-scaled to fit the modal — | ||
| * the same technique the inline scaled container uses to shrink charts. This keeps the canvas | ||
| * and the absolutely-positioned label/legend overlays (whose coordinates are design-based) | ||
| * perfectly aligned, so the expanded chart looks identical to the inline one, only larger. | ||
| * Rendering fluidly instead would resize only the canvas and leave labels at design coordinates, | ||
| * misplacing them (and potentially overlaying the header, blocking the back button). | ||
| */ | ||
| function VictoryChartExpandModal({isVisible, onClose, onModalHide}: VictoryChartExpandModalProps) { | ||
| const styles = useThemeStyles(); | ||
| const StyleUtils = useStyleUtils(); | ||
| const theme = useTheme(); | ||
| const {translate} = useLocalize(); | ||
| const {chartContentStyles, chartContainerStyles, type} = useVictoryChartContext(); | ||
| const [availableSize, setAvailableSize] = useState({width: 0, height: 0}); | ||
|
|
||
| const onContainerLayout = (event: LayoutChangeEvent) => { | ||
| const {width, height} = event.nativeEvent.layout; | ||
| // Avoid re-render churn when the layout callback fires without an actual size change. | ||
| setAvailableSize((prev) => (prev.width === width && prev.height === height ? prev : {width, height})); | ||
| }; | ||
|
|
||
| const designWidth = typeof chartContentStyles.width === 'number' ? chartContentStyles.width : undefined; | ||
| const designHeight = typeof chartContentStyles.height === 'number' ? chartContentStyles.height : undefined; | ||
| const hasDesignDimensions = !!designWidth && !!designHeight; | ||
| const isMeasured = availableSize.width > 0 && availableSize.height > 0; | ||
|
|
||
| // Match the inline container: polar charts are clipped to hide the dead space at the | ||
| // bottom of their design canvas, so the expanded chart centers the same way inline does. | ||
| const isPolar = type === CHART_TYPE.POLAR; | ||
| const effectiveDesignHeight = designHeight !== undefined && isPolar ? designHeight * POLAR_CONTAINER_HEIGHT_RATIO : designHeight; | ||
|
|
||
| // Uniform scale that fits the chart's (clipped) design box inside the available modal area (may be > 1). | ||
| const scale = hasDesignDimensions && effectiveDesignHeight !== undefined && isMeasured ? Math.min(availableSize.width / designWidth, availableSize.height / effectiveDesignHeight) : 1; | ||
|
|
||
| // Visual styles parsed from the chart HTML — resolved and applied the same way | ||
| // VictoryChartContainerFixed does inline, so the expanded chart keeps the same | ||
| // (theme-aware) background and rounding. | ||
| const backgroundColor = resolveChartContainerBgColor(chartContainerStyles.backgroundColor, theme); | ||
| const borderRadius = chartContainerStyles.borderRadius; | ||
|
|
||
| return ( | ||
| <Modal | ||
| isVisible={isVisible} | ||
| type={CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE} | ||
| onClose={onClose} | ||
| onModalHide={onModalHide} | ||
| enableEdgeToEdgeBottomSafeAreaPadding | ||
| > | ||
| <HeaderWithBackButton | ||
| title={translate('common.details')} | ||
| onBackButtonPress={onClose} | ||
| shouldShowBackButton | ||
| /> | ||
| <View | ||
| style={[styles.flex1, styles.justifyContentCenter, styles.alignItemsCenter, styles.ph5]} | ||
| onLayout={onContainerLayout} | ||
| > | ||
| {isMeasured && | ||
| (hasDesignDimensions && effectiveDesignHeight !== undefined ? ( | ||
| // Clip the container (not the content) so polar dead space is hidden while the chart renders at full fidelity. | ||
| <View | ||
| style={[ | ||
| StyleUtils.getWidthAndHeightStyle(designWidth * scale, effectiveDesignHeight * scale), | ||
| typeof borderRadius === 'number' && isPolar && StyleUtils.getBorderRadiusStyle(borderRadius), | ||
| styles.overflowHidden, | ||
| ]} | ||
| > | ||
| {/* Fixed design-size box so the fluid chart renders at design size, then scaled uniformly. */} | ||
| <View | ||
| style={[ | ||
| chartContentStyles, | ||
| StyleUtils.getWidthAndHeightStyle(designWidth, designHeight), | ||
| backgroundColor !== undefined && StyleUtils.getBackgroundColorStyle(backgroundColor), | ||
| typeof borderRadius === 'number' && StyleUtils.getBorderRadiusStyle(borderRadius), | ||
| styles.overflowHidden, | ||
| styles.chartExpandedContent, | ||
| StyleUtils.getTransformScaleStyle(scale), | ||
| ]} | ||
| > | ||
| <VictoryChartContent /> | ||
| </View> | ||
| </View> | ||
| ) : ( | ||
| // Charts without design dimensions have no design-based label coordinates, so fluid rendering is safe. | ||
| <View style={[styles.w100, styles.flex1]}> | ||
| <VictoryChartContent /> | ||
| </View> | ||
| ))} | ||
| </View> | ||
| </Modal> | ||
| ); | ||
| } | ||
|
|
||
| VictoryChartExpandModal.displayName = 'VictoryChartExpandModal'; | ||
|
|
||
| export default VictoryChartExpandModal; |
67 changes: 67 additions & 0 deletions
67
...MLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartExpandable.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import useHover from '@hooks/useHover'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
|
||
| import type {ReactNode} from 'react'; | ||
|
|
||
| import React, {useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
|
|
||
| import VictoryChartExpandButton from './VictoryChartExpandButton'; | ||
| import VictoryChartExpandModal from './VictoryChartExpandModal'; | ||
|
|
||
| type VictoryChartExpandableProps = { | ||
| /** The inline chart to overlay the expand affordance on */ | ||
| children: ReactNode; | ||
| }; | ||
|
|
||
| /** | ||
| * Wraps an inline chart with the expand affordance: a hover-revealed button overlaid on the | ||
| * chart's top-right corner and a full-screen modal that renders the chart enlarged. | ||
| * | ||
| * Hover/expand state lives here — below the chart renderer — so the chart subtree (passed as | ||
| * `children` with a stable element identity) does not re-render on mouse enter/leave. | ||
| * The modal is only mounted after the first expand (and unmounted after its closing animation) | ||
| * because mounting a Modal per chart on the chat path would be needlessly expensive. | ||
| */ | ||
| function VictoryChartExpandable({children}: VictoryChartExpandableProps) { | ||
| const styles = useThemeStyles(); | ||
| const {hovered, deviceHasHoverSupport, bind: hoverBind} = useHover(); | ||
| const [isExpanded, setIsExpanded] = useState(false); | ||
| const [shouldRenderModal, setShouldRenderModal] = useState(false); | ||
|
|
||
| const openModal = () => { | ||
| setShouldRenderModal(true); | ||
| setIsExpanded(true); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| {/* Wrapper anchors the absolutely-positioned expand button to the chart's corner. | ||
| mw100 keeps it from sizing to the chart's design width, so the responsive | ||
| container's onLayout measures the real available width (e.g. in the side panel). */} | ||
| <View | ||
| style={styles.mw100} | ||
| onMouseEnter={hoverBind.onMouseEnter} | ||
| onMouseLeave={hoverBind.onMouseLeave} | ||
| > | ||
| {children} | ||
| {/* Shown on hover only (like receipt actions) on devices with hover support; always shown on touch devices. */} | ||
| <VictoryChartExpandButton | ||
| onPress={openModal} | ||
| shouldShow={hovered || !deviceHasHoverSupport} | ||
| /> | ||
| </View> | ||
| {shouldRenderModal && ( | ||
| <VictoryChartExpandModal | ||
| isVisible={isExpanded} | ||
| onClose={() => setIsExpanded(false)} | ||
| onModalHide={() => setShouldRenderModal(false)} | ||
| /> | ||
| )} | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| VictoryChartExpandable.displayName = 'VictoryChartExpandable'; | ||
|
|
||
| export default VictoryChartExpandable; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.