Skip to content

Commit

Permalink
update variable name, change type import
Browse files Browse the repository at this point in the history
  • Loading branch information
pasyukevich committed Dec 19, 2023
1 parent 00ae1e6 commit 8053058
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/Popover/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ type PopoverProps = BaseModalProps & {

type PopoverWithWindowDimensionsProps = PopoverProps & WindowDimensionsProps;

export type {PopoverProps, PopoverWithWindowDimensionsProps, AnchorAlignment, PopoverDimensions};
export type {PopoverProps, PopoverWithWindowDimensionsProps};
18 changes: 7 additions & 11 deletions src/components/PopoverWithMeasuredContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import PopoverWithMeasuredContentUtils from '@libs/PopoverWithMeasuredContentUtils';
import CONST from '@src/CONST';
import type {AnchorPosition} from '@src/styles';
import Popover from './Popover';
import {PopoverProps} from './Popover/types';

type AnchorPosition = {
horizontal: number;
vertical: number;
};

type PopoverWithMeasuredContentProps = Omit<PopoverProps, 'anchorPosition'> & {
/** The horizontal and vertical anchors points for the popover */
anchorPosition: AnchorPosition;
Expand Down Expand Up @@ -45,18 +41,18 @@ function PopoverWithMeasuredContent({
const [popoverWidth, setPopoverWidth] = useState(popoverDimensions.width);
const [popoverHeight, setPopoverHeight] = useState(popoverDimensions.height);
const [isContentMeasured, setIsContentMeasured] = useState(popoverWidth > 0 && popoverHeight > 0);
const [isCurrentVisible, setIsCurrentVisible] = useState(false);
const [isPopoverVisible, setIsPopoverVisible] = useState(false);

/**
* When Popover becomes visible, we need to recalculate the Dimensions.
* Skip render on Popover until recalculations have done by setting isContentMeasured false as early as possible.
* Skip render on Popover until recalculations are done by setting isContentMeasured to false as early as possible.
*/
if (!isCurrentVisible && isVisible) {
if (!isPopoverVisible && isVisible) {
// When Popover is shown recalculate
setIsContentMeasured(popoverDimensions.width > 0 && popoverDimensions.height > 0);
setIsCurrentVisible(true);
} else if (isCurrentVisible && !isVisible) {
setIsCurrentVisible(false);
setIsPopoverVisible(true);
} else if (isPopoverVisible && !isVisible) {
setIsPopoverVisible(false);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/libs/calculateAnchorPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
import {View} from 'react-native';
import {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import type {AnchorPosition} from '@src/styles';

type AnchorOrigin = {
horizontal: ValueOf<typeof CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL>;
vertical: ValueOf<typeof CONST.MODAL.ANCHOR_ORIGIN_VERTICAL>;
shiftVertical?: number;
};

type AnchorPosition = {
horizontal: number;
vertical: number;
};

/**
* Gets the x,y position of the passed in component for the purpose of anchoring another component to it.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4054,4 +4054,4 @@ const defaultStyles = styles(defaultTheme);

export default styles;
export {defaultStyles};
export type {Styles, ThemeStyles, StatusBarStyle, ColorScheme};
export type {Styles, ThemeStyles, StatusBarStyle, ColorScheme, AnchorPosition};

0 comments on commit 8053058

Please sign in to comment.