i want to open modal when screen load so i am change state when component did mount my code is:
state:
this.state = {
orientation: this.isPortrait() ? 'portrait' : 'landscape',
isModalDate:true
};
component code:
componentDidMount(){
this._onPressAccountdata();
}
Change state function:
_onPressAccountdata() {
//Alert.alert("1");
this.setState({ isModalDate: !this.state.isModalDate });
console.log("modal state"+this.state.isModalDate)
}
render modal
<Modal
isVisible={this.state.isModalDate}
onSwipe={() => this.setState({ isModalDate: false })}
swipeDirection="left"
style={styles.modal_css}
supportedOrientations={['portrait', 'landscape']}
>
{...}
</Modal>
Modal open when button click it work perfectly but when screen load it not working what's wrong in my code
Thank's in advance
i solved this problem using simple tricks i change state after 1 seconds when componentDidMount. Code:
componentDidMount() {
this.timer = setTimeout(() => {
this.setState({ isModalDate: !this.state.isModalDate });
}, 1000);
}