Skip to content

Commit d59fb29

Browse files
authored
Popover fixes (#1727, #1723)
1 parent 8e7aefd commit d59fb29

File tree

6 files changed

+91
-81
lines changed

6 files changed

+91
-81
lines changed

Diff for: src/components/devsupport/components/measure/measure.component.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ export const MeasureElement: React.FC<MeasureElementProps> = (props): MeasuringE
6464
};
6565

6666
const onUIManagerMeasure = (x: number, y: number, w: number, h: number): void => {
67-
const originY = props.shouldUseTopInsets ? y + StatusBar.currentHeight || 0 : y;
68-
const frame: Frame = bindToWindow(new Frame(x, originY, w, h), Frame.window());
69-
props.onMeasure(frame);
67+
if (!w && !h) {
68+
measureSelf();
69+
} else {
70+
const originY = props.shouldUseTopInsets ? y + StatusBar.currentHeight || 0 : y;
71+
const frame: Frame = bindToWindow(new Frame(x, originY, w, h), Frame.window());
72+
props.onMeasure(frame);
73+
}
7074
};
7175

7276
const measureSelf = (): void => {

Diff for: src/components/ui/popover/placement.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const PLACEMENT_FAMILIES: string[] = [
2222
export class PopoverPlacementService {
2323

2424
public find(preferredValue: PopoverPlacement, options: PlacementOptions): PopoverPlacement {
25-
const placement: PopoverPlacement = this.findRecursive(preferredValue, PLACEMENT_FAMILIES, options);
25+
const placement: PopoverPlacement = this.findRecursive(preferredValue, [...PLACEMENT_FAMILIES], options);
2626

2727
return placement || preferredValue;
2828
}

Diff for: src/components/ui/popover/popover.component.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type PopoverModalProps = Omit<ModalProps, ' children'>;
3636

3737
export interface PopoverProps extends PopoverViewProps, PopoverModalProps, RNModalProps {
3838
children?: React.ReactElement;
39+
placement: PopoverPlacement;
3940
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4041
anchor: RenderFCProp<any>;
4142
fullWidth?: boolean;
@@ -135,7 +136,7 @@ export class Popover extends React.Component<PopoverProps, State> {
135136
}
136137

137138
public static getDerivedStateFromProps(props, state): State {
138-
if (!props.visible) {
139+
if (!props.visible && !Point.outscreen().equals(state.contentPosition)) {
139140
return {
140141
...state,
141142
contentPosition: Point.outscreen(),
@@ -187,7 +188,7 @@ export class Popover extends React.Component<PopoverProps, State> {
187188
<PopoverView
188189
{...this.props}
189190
contentContainerStyle={[this.props.contentContainerStyle, styles.popoverView, this.contentFlexPosition]}
190-
placement={this.state.actualPlacement.reverse()}
191+
layoutDirection={PopoverPlacements.parse(this.state.actualPlacement).flex()}
191192
>
192193
{this.renderContentElement()}
193194
</PopoverView>

Diff for: src/components/ui/popover/popoverView.component.tsx

+3-9
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ import {
2222
StyleType,
2323
} from '../../theme';
2424
import {
25-
PopoverPlacement,
26-
PopoverPlacements,
25+
FlexPlacement,
2726
} from './type';
2827

2928
type AnimatedViewStyle = ViewStyle;
3029

3130
export interface PopoverViewProps extends ViewProps, StyledComponentProps {
3231
contentContainerStyle?: StyleProp<AnimatedViewStyle>;
33-
placement?: PopoverPlacement | string;
32+
layoutDirection?: FlexPlacement;
3433
indicator?: (props: ViewProps) => React.ReactElement;
3534
}
3635

@@ -41,11 +40,6 @@ const INDICATOR_WIDTH = 6;
4140

4241
@styled('Popover')
4342
export class PopoverView extends React.Component<PopoverViewProps> {
44-
45-
private get placement(): PopoverPlacement {
46-
return PopoverPlacements.parse(this.props.placement);
47-
}
48-
4943
private getComponentStyle = (source: StyleType): StyleType => {
5044
const { indicatorWidth, indicatorHeight, indicatorBackgroundColor, ...containerParameters } = source;
5145

@@ -60,7 +54,7 @@ export class PopoverView extends React.Component<PopoverViewProps> {
6054
};
6155

6256
private getDirectionStyle = (): StyleType => {
63-
const { direction, alignment } = this.placement.flex();
57+
const { direction, alignment } = this.props.layoutDirection;
6458

6559
const isVertical: boolean = direction.startsWith('column');
6660
const isStart: boolean = alignment.endsWith('start');

0 commit comments

Comments
 (0)