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

Bug: programmatically set size results in different flexGrow #147

Open
akphi opened this issue Aug 16, 2021 · 11 comments
Open

Bug: programmatically set size results in different flexGrow #147

akphi opened this issue Aug 16, 2021 · 11 comments

Comments

@akphi
Copy link
Contributor

akphi commented Aug 16, 2021

Hi,

I programmatically set the size for a panel and have a button to toggle minimizing it. What I see is the size of the panel changes when I toggle the panel. See the videos below:

In this video, you can see Iconsole.log out the size and it stays the same at 300

size.stay.the.same.mov

In this video, I repeat the same experiment, but observe the flex in style, it changes

flex.changes.mov
@akphi
Copy link
Contributor Author

akphi commented Sep 14, 2021

@leefsmp Sorry, did you have a chance to take a look at this issue?

@leefsmp
Copy link
Owner

leefsmp commented Sep 22, 2021

I don't have a suggestion from top of my head sorry. Do you have a codepen/sandbox that I could test quickly?

@akphi
Copy link
Contributor Author

akphi commented Sep 22, 2021

@leefsmp I will try to create a minimal repro in a few days!

@akphi
Copy link
Contributor Author

akphi commented Sep 23, 2021

@leefsmp Here's a small repro - https://codesandbox.io/s/wizardly-morse-47b2o
You can click on the blue pad to toggle the size of the left panel and you would see it jumps

Screen.Recording.2021-09-23.at.9.55.39.AM.mov

@akphi
Copy link
Contributor Author

akphi commented Jul 18, 2022

@leefsmp did you have any chance looking at this issue?

@leefsmp
Copy link
Owner

leefsmp commented Jul 27, 2022

I will try to look at it this week ...

@mastercoms
Copy link

mastercoms commented Oct 15, 2022

I found this is a problem with ReflexContainer adjustFlex, for some reason the flex adjustment is different every time

Workaround: I set flex=1 for the visible component and flex=0 for the initially invisible sidebar.

@akphi
Copy link
Contributor Author

akphi commented Oct 16, 2022

@mastercoms thanks! I have tested it out and it does fix my problem

@tachbana
Copy link

I have the same issue.
I am guessing that the reason for this problem is that the new size is calculated relative to the current size.

   newFlex = currentFlex * newSize / currentSize

So if the current size is very small, the error tends to be large.

I modified ReflexElement.js and ReflexContainer.js to not do relative calculations if prop.size changes.
It seems to be working fine for now.

The specific changes are as follows.

ReflexElement.js

@@ -160,6 +160,7 @@
       /*#__PURE__*/
       _regenerator.default.mark(function _callee(prevProps, prevState, snapshot) {
         var directions, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, direction;
+        var _isSetPropSize;
 
         return _regenerator.default.wrap(function _callee$(_context) {
           while (1) {
@@ -167,7 +168,10 @@
               case 0:
                 if (!(prevState.size !== this.state.size)) {
                   _context.next = 28;
+                  _isSetPropSize = false;
                   break;
+                } else {
+                  _isSetPropSize = true;
                 }
 
                 directions = toArray(this.props.direction);
@@ -188,7 +192,8 @@
                 return this.props.events.emit('element.size', {
                   index: this.props.index,
                   size: this.props.size,
-                  direction: direction
+                  direction: direction,
+                  isSetPropSize: _isSetPropSize
                 });
 
               case 11:

ReflexContainer.js

@@ -150,7 +150,7 @@
           var splitterIdx = idx + dir;
 
           var availableOffset = _this.computeAvailableOffset(splitterIdx, dir * offset);
-
+          _this.state.isSetPropSize = data.isSetPropSize;
           _this.elements = null;
 
           if (availableOffset) {
@@ -168,6 +168,7 @@
           // TODO handle exception ...
           console.log(ex);
         }
+        delete _this.state.isSetPropSize;
       });
     });
     _this.events = new _ReflexEvents.default();
@@ -503,7 +504,7 @@
       var size = this.getSize(element);
       var idx = element.props.index;
       var newSize = Math.max(size + offset, 0);
-      var currentFlex = this.state.flexData[idx].flex;
+      var currentFlex = this.state.isSetPropSize ? 0 : this.state.flexData[idx].flex;
       var newFlex = currentFlex > 0 ? currentFlex * newSize / size : this.computePixelFlex() * newSize;
       this.state.flexData[idx].flex = !isFinite(newFlex) || isNaN(newFlex) ? 0 : newFlex;
     } /////////////////////////////////////////////////////////

@leefsmp
Copy link
Owner

leefsmp commented Nov 21, 2022

could you submit a PR with modified code from the source in src/lib not the transpiled code.

tachbana added a commit to tachbana/Re-Flex that referenced this issue Nov 21, 2022
@LFdeWeb
Copy link

LFdeWeb commented May 31, 2023

I found this is a problem with ReflexContainer adjustFlex, for some reason the flex adjustment is different every time

Workaround: I set flex=1 for the visible component and flex=0 for the initially invisible sidebar.

sorry at this link #147 (comment) , I can not fix it, by

          <ReflexElement  flex={0} size={size} direction={1}>
            <div className="App__side"></div>
          </ReflexElement>
          <ReflexSplitter />
          <ReflexElement flex={1} >
            <div className="App__panel"></div>
          </ReflexElement>
        </ReflexContainer> 

May I have a more complete code? please. @akphi @mastercoms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants