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

Remove resize observer #14

Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default () => {
dom.current.innerHTML = 'YOLO';
});
useEffect(() => {
setTimeout(() => setStyles({ display: 'flex' }), 1000);
setTimeout(() => setStyles({ display: 'flex' }), 3000);
}, []);
return (
<EuiResizableContainer style={{ ...styles, height: '200px' }}>
Expand Down
31 changes: 10 additions & 21 deletions src/components/resizable_container/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ export const useContainerCallbacks = ({
};

switch (action.type) {
case 'EUI_RESIZABLE_CONTAINER_INIT': {
return {
...state,
containerSize: getContainerSize(),
};
}
case 'EUI_RESIZABLE_PANEL_REGISTER': {
const { panel } = action.payload;
return {
Expand Down Expand Up @@ -229,19 +223,19 @@ export const useContainerCallbacks = ({

const prevPanelMin = getPanelMinSize(
prevPanel.minSize,
state.containerSize
getContainerSize()
);
const nextPanelMin = getPanelMinSize(
nextPanel.minSize,
state.containerSize
getContainerSize()
);
const prevPanelSize = pxToPercent(
prevPanel.getSizePx() + delta,
state.containerSize
getContainerSize()
);
const nextPanelSize = pxToPercent(
nextPanel.getSizePx() - delta,
state.containerSize
getContainerSize()
);

if (prevPanelSize >= prevPanelMin && nextPanelSize >= nextPanelMin) {
Expand Down Expand Up @@ -271,19 +265,19 @@ export const useContainerCallbacks = ({

const prevPanelMin = getPanelMinSize(
prevPanel.minSize,
state.containerSize
getContainerSize()
);
const nextPanelMin = getPanelMinSize(
nextPanel.minSize,
state.containerSize
getContainerSize()
);
const prevPanelSize = pxToPercent(
prevPanel.getSizePx() - (direction === 'backward' ? 10 : -10),
state.containerSize
getContainerSize()
);
const nextPanelSize = pxToPercent(
nextPanel.getSizePx() - (direction === 'forward' ? 10 : -10),
state.containerSize
getContainerSize()
);

if (prevPanelSize >= prevPanelMin && nextPanelSize >= nextPanelMin) {
Expand Down Expand Up @@ -377,7 +371,7 @@ export const useContainerCallbacks = ({
let newPanelSize = shouldCollapse
? pxToPercent(
!currentPanel.mode ? 0 : 24, // size of the default toggle button
state.containerSize
getContainerSize()
)
: currentPanel.prevSize;

Expand Down Expand Up @@ -408,7 +402,7 @@ export const useContainerCallbacks = ({
Object.values(otherPanels).some(
(panel) =>
panel.size + delta <
getPanelMinSize(panel.minSize, state.containerSize)
getPanelMinSize(panel.minSize, getContainerSize())
)
) {
// A toggling sequence has occurred where a to-be-opened panel is
Expand Down Expand Up @@ -524,7 +518,6 @@ export const useContainerCallbacks = ({
...initialState,
panels: state.panels,
resizers: state.resizers,
containerSize: state.containerSize,
};
}
case 'EUI_RESIZABLE_ONCHANGE': {
Expand All @@ -547,10 +540,6 @@ export const useContainerCallbacks = ({
const actions: EuiResizableContainerActions = useMemo(() => {
return {
reset: () => dispatch({ type: 'EUI_RESIZABLE_RESET' }),
initContainer: () =>
dispatch({
type: 'EUI_RESIZABLE_CONTAINER_INIT',
}),
registerPanel: (panel: EuiResizablePanelController) =>
dispatch({
type: 'EUI_RESIZABLE_PANEL_REGISTER',
Expand Down
19 changes: 1 addition & 18 deletions src/components/resizable_container/resizable_container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import React, {
ReactNode,
ReactElement,
useEffect,
useRef,
useCallback,
CSSProperties,
Expand All @@ -32,7 +31,6 @@ import classNames from 'classnames';

import { CommonProps } from '../common';
import { keys } from '../../services';
import { useResizeObserver } from '../observer/resize_observer';
import { EuiResizableContainerContextProvider } from './context';
import {
EuiResizableButtonProps,
Expand Down Expand Up @@ -118,21 +116,6 @@ export const EuiResizableContainer: FunctionComponent<EuiResizableContainerProps
onPanelWidthChange,
});

const initialize = useCallback(() => {
actions.initContainer();
}, [actions]);

const containerSize = useResizeObserver(
containerRef.current,
isHorizontal ? 'width' : 'height'
);

useEffect(() => {
if (containerSize.width > 0 && containerSize.height > 0) {
initialize();
}
}, [initialize, containerSize]);

const onMouseDown = useCallback(
(event: EuiResizableButtonMouseEvent) => {
const currentTarget = event.currentTarget;
Expand Down Expand Up @@ -275,7 +258,7 @@ export const EuiResizableContainer: FunctionComponent<EuiResizableContainerProps
onTouchMove={onMouseMove}
onTouchEnd={onMouseUp}
{...rest}>
{!!reducerState.containerSize && render()}
{render()}
</div>
</EuiResizableContainerContextProvider>
);
Expand Down
6 changes: 0 additions & 6 deletions src/components/resizable_container/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ interface ActionReset {
type: 'EUI_RESIZABLE_RESET';
}

interface ActionInit {
type: 'EUI_RESIZABLE_CONTAINER_INIT';
}

export interface ActionDragStart {
type: 'EUI_RESIZABLE_DRAG_START';
payload: { prevPanelId: string; nextPanelId: string; position: number };
Expand Down Expand Up @@ -153,7 +149,6 @@ interface ActionOnChange {

export type EuiResizableContainerAction =
| ActionReset
| ActionInit
| ActionRegisterPanel
| ActionDeregisterPanel
| ActionRegisterResizer
Expand All @@ -169,7 +164,6 @@ export type EuiResizableContainerAction =

export interface EuiResizableContainerActions {
reset: () => void;
initContainer: () => void;
registerPanel: (panel: EuiResizablePanelController) => void;
deregisterPanel: (panelId: EuiResizablePanelController['id']) => void;
registerResizer: (resizer: EuiResizableButtonController) => void;
Expand Down