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

How to hide it in the first place? #2

Open
christinehesher opened this issue Jun 8, 2016 · 9 comments
Open

How to hide it in the first place? #2

christinehesher opened this issue Jun 8, 2016 · 9 comments

Comments

@christinehesher
Copy link

Hello there! I can't figure out how to make the body hidden when the component mounts. Please help me out, thanks in advance.

@rikenppatel
Copy link

rikenppatel commented Jun 21, 2016

@crysfel awesome job. working very good with sliding. but facing same issue, its not mount with expanded: false .

please help me out.

@fostertime
Copy link

fostertime commented Jul 19, 2016

I accomplished this by using .measure in componentDidMount().

Example:
First set a timeout on componentDidMount():

componentDidMount() {
    setTimeout( this._setToggleClosed.bind(this) );
}

Then in the _setToggleClosed function, set your min and max heights based on the refs of your two containers, and set the value of your animation to the min height:

_setToggleClosed() {
    this.refs.textContainer.measure((ox, oy, width, height, px, py) => {
        this.setState({
            maxHeight: height
        });
    });
    this.refs.labelContainer.measure((ox, oy, width, height, px, py) => {
        this.setState({
            minHeight: height
        });
        this.state.animation.setValue(height);
    });
}

@Rashhh
Copy link

Rashhh commented Nov 10, 2016

what is refs.textContainer.measure here?

@prasann278
Copy link

@fostertime i have initgrated your code in my code but it is not working

initialy i need toggle to be closed

@hungdev
Copy link

hungdev commented Feb 18, 2017

@prasann278
solution here:
#1 (comment)

 _setMaxHeight(event) {
    if (!this.state.maxHeight) {
      this.setState({
        maxHeight: event.nativeEvent.layout.height,
      });
    }
  }

  _setMinHeight(event) {
    if (!this.state.minHeight) {
      this.setState({
        minHeight: event.nativeEvent.layout.height,
        animation: new Animated.Value(event.nativeEvent.layout.height),
      });
    }
  }

and set expanded to false

@ShaikhKabeer
Copy link

Hey @hungdev , it is working but at the initial panels are showing as expanded and then slowly closing. Any workaround for this ?

@HotSpotNick
Copy link

@ShaikhKabeer Any findings here?

@ShaikhKabeer
Copy link

Hey @HotSpotNick ,used the same code mentioned by @hungdev and it's working fine.

@Poyser1911
Copy link

Got a solution to having it work both ways..

  1. Added accepting an initial prop to set the default value.
state = {
        title: this.props.title,
+      expanded: this.props.initial,
        animation: new Animated.Value()
    }
  1. Modified methods further upon @hungdev's solution
_setMaxHeight(event) {
        if (!this.props.initial && this.state.maxHeight) return
        this.setState({
            maxHeight: event.nativeEvent.layout.height
        })

    }

    _setMinHeight(event) {
        if (!this.props.initial && this.state.minHeight) return
            this.setState({
                minHeight: event.nativeEvent.layout.height,
                animation: !this.props.initial ? new Animated.Value(event.nativeEvent.layout.height) : this.state.animation
            })
    }
  1. Working Fine with example below.
 <Panel title={'Title'} initial>
        <Text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</Text>
 </Panel>

<Panel title={'Title'} initial={false}>
       <Text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</Text>
</Panel>

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

9 participants