@@ -68,10 +68,17 @@ function Components(_: {||}) {
6868 ) ;
6969}
7070
71- const RESIZE_DIRECTIONS = {
71+ type HorizontalResizeDirection = 'HORIZONTAL ';
72+ type VerticalResizeDirection = 'VERTICAL ';
73+
74+ const RESIZE_DIRECTIONS : { |
75+ HORIZONTAL : HorizontalResizeDirection ,
76+ VERTICAL : VerticalResizeDirection ,
77+ | } = {
7278 HORIZONTAL : 'HORIZONTAL' ,
7379 VERTICAL : 'VERTICAL' ,
7480} ;
81+
7582const LOCAL_STORAGE_RESIZE_ELEMENT_PERCENTAGE_HORIZONTAL_KEY = `React::DevTools::resizedElementPercentage::${ RESIZE_DIRECTIONS . HORIZONTAL } ` ;
7683const LOCAL_STORAGE_RESIZE_ELEMENT_PERCENTAGE_VERTICAL_KEY = `React::DevTools::resizedElementPercentage::${ RESIZE_DIRECTIONS . VERTICAL } ` ;
7784
@@ -92,6 +99,16 @@ function ComponentResizer({children}): {|children: Function|} {
9299 const componentsWrapperRef = useRef < HTMLDivElement > ( null ) ;
93100 const resizeElementRef = useRef < HTMLElement > ( null ) ;
94101 const [ resizeElementStyles , setResizeElementStyles ] = useState < Object > ( { } ) ;
102+ const getResizeDirection : Function = useCallback ( ( ) => {
103+ if ( componentsWrapperRef . current === null ) {
104+ return RESIZE_DIRECTIONS . HORIZONTAL ;
105+ }
106+ const { width} = componentsWrapperRef . current . getBoundingClientRect ( ) ;
107+
108+ return width > 600
109+ ? RESIZE_DIRECTIONS . HORIZONTAL
110+ : RESIZE_DIRECTIONS . VERTICAL ;
111+ } , [ componentsWrapperRef ] ) ;
95112
96113 const onResizeStart = useCallback ( ( ) => {
97114 setIsResizing ( true ) ;
@@ -119,8 +136,7 @@ function ComponentResizer({children}): {|children: Function|} {
119136 left,
120137 top,
121138 } = componentsWrapperRef . current . getBoundingClientRect ( ) ;
122- const resizeDirection =
123- width > 600 ? RESIZE_DIRECTIONS . HORIZONTAL : RESIZE_DIRECTIONS . VERTICAL ;
139+ const resizeDirection = getResizeDirection ( ) ;
124140 const currentMousePosition : number =
125141 resizeDirection === RESIZE_DIRECTIONS . HORIZONTAL
126142 ? e . clientX - left
@@ -165,7 +181,7 @@ function ComponentResizer({children}): {|children: Function|} {
165181
166182 useLayoutEffect ( ( ) => {
167183 if ( componentsWrapperRef . current !== null ) {
168- if ( componentsWrapperRef . current . getBoundingClientRect ( ) . width > 600 ) {
184+ if ( getResizeDirection ( ) === RESIZE_DIRECTIONS . HORIZONTAL ) {
169185 setResizeElementStyles ( {
170186 flexBasis : `${ horizontalPercentage } %` ,
171187 } ) ;
0 commit comments