crysfel / Panels

Expanding/Collapsing a panel with animations in React Native
66 stars 62 forks source link

hide panel as default #1

Open kenchengch opened 8 years ago

kenchengch commented 8 years ago

how to do this on react native? I know display:none is not work.

shally12 commented 7 years ago

+1

MatthiasVervaet commented 7 years ago
  _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

prasann278 commented 7 years ago

@MatthiasVervaet thanks a lot now it is working for me

i have replaced below code in panel .js :-

       _setMaxHeight(event){
        this.setState({
        maxHeight   : event.nativeEvent.layout.height
     });
 }

_setMinHeight(event){
    this.setState({
        minHeight   : event.nativeEvent.layout.height
    });
}

With this code:-

_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),
            });
            }
           }

It is Working fine for me

prasann278 commented 7 years ago

@crysfel @MatthiasVervaet @hungdev When i m keeping the Header under the return

it is not reflecting on the screen

           import React,{AppRegistry,StyleSheet,Text,ScrollView,Header,Button,Title,Icon,View,Image} from                 'react-native';
        import Head from './components/Header'
              import Panel from './components/Panel';

         var Panels = React.createClass({
          render: function() {
              return (
         <View>
            <Head/>

        <ScrollView style={styles.container}>
            <View style={styles.subScroll}>

            <View style={styles.border1}></View>
                        <Panel title="How does Auto Renew Work?" style={{borderBottomWidth:2,borderBottomColor:'blue'}}>
                <Text style={styles.panelCon}>Funko is an American company that manufactures licensed pop culture toys.</Text>
            </Panel>
            <View style={styles.border1}></View>

            <Panel title="What is the difference between subscription plans?" style={{borderBottomWidth:2,borderBottomColor:'blue'}}>
                <Text style={styles.panelCon}>Funko is an American company that manufactures licensed pop culture toys. Funko is most known for producing over 1000 different licensed vinyl figures. In addition Funko produces licensed plush, bobbleheads, action figures, and licensed electronic items such as USB drives, lamps and headphones.</Text>
            </Panel>
            <View style={styles.border1}></View>

this is showing error plzz help