Giter Site home page Giter Site logo

Comments (9)

BernardoFBBraga avatar BernardoFBBraga commented on August 16, 2024 4

I managed to get it working in a different approach, without touching the source


        componentDidMount () {
            window.addEventListener('resize', this.updateSize)
        }

        componentWillUnmount () {
            window.removeEventListener('resize', this.updateSize)
        }

        componentDidUpdate () {
            if (this.state.windowResize) this.setState({windowResize: false})
        }

        updateSize = () => this.setState({windowResize: true})

        onChange = () => {
            const draggedSize = _.get(this.splitpane.current, 'state.draggedSize')

            if (draggedSize && this.splitpane.current.splitPane.clientHeight) {
                const percentage = draggedSize / this.splitpane.current.splitPane.clientHeight

                this.setState({panelSize: `${percentage * 100}%`})
            }
        }

and on the render function there's something like

<SplitPane
    ref={this.splitpane}
    split="horizontal"
    minSize={50}
    maxSize={-50}
    defaultSize={this.state.panelSize}
    size={this.state.windowResize ? this.state.panelSize : undefined}
    onChange={this.onChange}
>

Rationale is this: when the window updates, I set the boolean so on the render function the splitpane is updated with the size prop. In the next render, the componentDidUpdate function sets the boolean to false, meaning the drag is back online

from react-split-pane.

davidmason avatar davidmason commented on August 16, 2024 3

I think the container size would be best.

I have managed to get something working with this, but I had to reach in and mess with some of the internals from the parent component - super fragile but it works. I did these things:

  • onDragFinished: look up this.refs.mySplitPane.state.draggedSize and save as a percentage of my height (e.g. percentageSize = draggedSize / window.innerHeight might give 0.33)
  • listen to window resize events to tweak the size to the percentage size (var pixelHeight = window.innerHeight * percentageSize)
  • update the size with this.refs.mySplitPane.setState({ draggedSize: pixelHeight }) since I could not find any other way to override the size after a drag resize
  • this.forceUpdate() to force a rerender

so what I did would be a lot easier if I had a callback that triggered whenever the container size changed, and gave me the current element size, previous container size and next container size and let me return the size I want it to use. The default implementation would just return the current element size:

function onContainerSizeChange (elementPixelSize, previousContainerSize, currentContainerSize) {
  // default could just be this:
  // return elementPixelSize

  // my case would just be this:
  return elementPixelSize * (currentContainerSize / previousContainerSize)
}

from react-split-pane.

Nantris avatar Nantris commented on August 16, 2024 1

True, it's mostly helpful in that case, but it is helpful as a pure CSS solution that gives your body and wrapper a defined height so height: 100% has some use inside of them when needed.

from react-split-pane.

damassi avatar damassi commented on August 16, 2024 1

Thanks @BernardoFBBraga, with some slight modifications that worked great 👍

My slightly less dynamic version:

 onChange = () => {
    const draggedSize = this.splitpane.state.pane1Size

    if (draggedSize && this.splitpane.pane1.clientWidth) {
      const percentage = draggedSize / window.innerWidth
      const panelSize = `${percentage * 100}%`
      this.setState({ panelSize })
    }
  }

from react-split-pane.

zerkms avatar zerkms commented on August 16, 2024

If one really needs that, I think the better alternative would be to introduce another attribute flex (as the similarly named from a css flexbox model) which would conflict with the defaultSize (so that it was only valid to specify either).

It is also not clear whether to rely on the window size, or the current document size or the current element container size. I tend to think the latter is the most acceptable one.

Thoughts?

from react-split-pane.

Nantris avatar Nantris commented on August 16, 2024

I haven't reached a 100% working solution yet, but setting the panes to:
window.innerHeight / 2

and setting widths of divs to 100% and heights to 100vh has me pretty close.

Just learned about vh. They are like magic: http://stackoverflow.com/a/16837667/6025788

from react-split-pane.

zerkms avatar zerkms commented on August 16, 2024

vh might only be useful when your pane occupies the whole width of the height (or both), in other cases it would not work.

from react-split-pane.

Nantris avatar Nantris commented on August 16, 2024

image

from react-split-pane.

yotamberk avatar yotamberk commented on August 16, 2024

Is there a plan to do this natively in this component?

from react-split-pane.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.