Skip to content

Commit

Permalink
feat: DevTools - Fixed orientation change issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
hristo-kanchev committed Feb 25, 2020
1 parent 3ba1909 commit 554f7e8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.TreeWrapper {
flex: 0 0 65%;
flex: 0 0 var(--horizontal-resize-percentage);
overflow: auto;
}

Expand All @@ -24,7 +24,7 @@

@media screen and (max-width: 600px) {
.TreeWrapper {
flex: 0 0 50%;
flex: 0 0 var(--vertical-resize-percentage);
}

.SelectedElementWrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import * as React from 'react';
import {Suspense, Fragment } from 'react';
import {Suspense, Fragment} from 'react';
import Tree from './Tree';
import SelectedElement from './SelectedElement';
import {InspectedElementContextController} from './InspectedElementContext';
Expand All @@ -30,10 +30,7 @@ function Components(_: {||}) {
<ComponentsResizer>
{({resizeElementRef, onResizeStart}) => (
<Fragment>
<div
ref={resizeElementRef}
className={styles.TreeWrapper}
>
<div ref={resizeElementRef} className={styles.TreeWrapper}>
<Tree />
</div>
<div className={styles.ResizeBarWrapper}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type Props = {|
|};

export default function ComponentsResizer({children}: Props) {
const wrapperElementRef = useRef<HTMLDivElement>(null);
const resizeElementRef = useRef<HTMLElement>(null);
const wrapperElementRef = useRef(null);
const resizeElementRef = useRef(null);
const [state, dispatch] = createResizeReducer(
wrapperElementRef,
resizeElementRef,
Expand Down Expand Up @@ -67,10 +67,12 @@ export default function ComponentsResizer({children}: Props) {
orientation === 'horizontal'
? 'ACTION_SET_HORIZONTAL_PERCENTAGE'
: 'ACTION_SET_VERTICAL_PERCENTAGE';
const percentage = (currentMousePosition / resizedElementDimension) * 100;

resizeElement.style.flexBasis = `${(currentMousePosition /
resizedElementDimension) *
100}%`;
resizeElement.style.setProperty(
`--${orientation}-resize-percentage`,
`${percentage}%`,
);

dispatch({
type: actionType,
Expand Down Expand Up @@ -166,11 +168,7 @@ function getOrientation(
}

function createResizeReducer(wrapperElementRef, resizeElementRef) {
const [state, dispatch] = useReducer<ResizeState, ResizeAction>(
resizeReducer,
null,
initResizeState,
);
const [state, dispatch] = useReducer(resizeReducer, null, initResizeState);
const {horizontalPercentage, verticalPercentage} = state;
const orientationRef = useRef(null);

Expand All @@ -185,7 +183,11 @@ function createResizeReducer(wrapperElementRef, resizeElementRef) {
? horizontalPercentage
: verticalPercentage;
const resizeElement = resizeElementRef.current;
resizeElement.style.flexBasis = `${percentage * 100}%`;

resizeElement.style.setProperty(
`--${orientation}-resize-percentage`,
`${percentage * 100}%`,
);
}
});

Expand Down

0 comments on commit 554f7e8

Please sign in to comment.