Advertisement
Guest User

3 madais

a guest
Dec 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import { StyleSheet, Text, View, TouchableOpacity, } from 'react-native';
  3. import Modal from "react-native-modal";
  4. const time = 4000
  5. export default class App extends Component {
  6.     state = {
  7.         visibleModalA: null,
  8.         visibleModalB: null,
  9.         visibleModalC: null,
  10.     };
  11.     _renderButton = (text, onPress) => (
  12.         <TouchableOpacity style={styles.buttonModal} onPress={onPress}>
  13.             <Text style={styles.buttonTextModal}>{text}</Text>
  14.         </TouchableOpacity>
  15.     );
  16.     modal_A_OnPress = () => {
  17.         this.setState({ visibleModalA: null })
  18.         setTimeout(() => {
  19.             this.modal_B_Coming()
  20.         }, time);
  21.     }
  22.     modal_B_Coming = () => {
  23.         this.setState({ visibleModalB: 2 });
  24.         this.timeOutID = this.timerError()
  25.  
  26.     }
  27.     timerError = () => setTimeout(() => {
  28.         this.modal_C_Coming()
  29.     }, time);
  30.     modal_B_Closing = () => {
  31.         this.setState({ visibleModalB: null });
  32.         clearTimeout(this.timeOutID);
  33.         //this.timeOutID= 0;
  34.         console.warn(this.timeOutID)
  35.     }
  36.     modal_C_Coming = () => {
  37.         this.setState({ visibleModalB: null });
  38.         this.setState({ visibleModalC: 2 });
  39.     }
  40.     _renderModalContentA = () => (
  41.         <View style={styles.modalContent}>
  42.             <Text style={styles.modalTextContent}>Este é o modal A</Text>
  43.             {this._renderButton('FECHAR', this.modal_A_OnPress)}
  44.         </View>
  45.     );
  46.     _renderModalContentB = () => (
  47.         <View style={styles.modalContent}>
  48.             <Text style={styles.modalTextContent}>Este é o modal B</Text>
  49.             {this._renderButton('FECHAR', this.modal_B_Closing)}
  50.  
  51.         </View>
  52.     );
  53.     _renderModalContentC = () => (
  54.         <View style={styles.modalContent}>
  55.             <Text style={styles.modalTextContent}>Este é o modal C</Text>
  56.             {this._renderButton('FECHAR', () => this.setState({ visibleModalC: null }))}
  57.  
  58.         </View>
  59.     );
  60.  
  61.     componentDidMount() {
  62.         this.setState({ visibleModalA: 2 })
  63.     }
  64.  
  65.     render() {
  66.         return (
  67.             <View style={styles.container}>
  68.                 <Modal
  69.                     isVisible={this.state.visibleModalA === 2}
  70.                     animationIn={'slideInLeft'}
  71.                     animationOut={'slideOutRight'}
  72.                 >
  73.                     {this._renderModalContentA()}
  74.                 </Modal>
  75.                 <Modal
  76.                     isVisible={this.state.visibleModalB === 2}
  77.                     animationIn={'slideInLeft'}
  78.                     animationOut={'slideOutRight'}
  79.                 >
  80.                     {this._renderModalContentB()}
  81.                 </Modal>
  82.                 <Modal
  83.                     isVisible={this.state.visibleModalC === 2}
  84.                     animationIn={'slideInLeft'}
  85.                     animationOut={'slideOutRight'}
  86.                 >
  87.                     {this._renderModalContentC()}
  88.                 </Modal>
  89.             </View >
  90.         )
  91.     }
  92. }
  93.  
  94. const styles = StyleSheet.create({
  95.     container: {
  96.         alignItems: 'center',
  97.         justifyContent: 'center',
  98.         flex: 1
  99.     },
  100.     buttonTextModal: {
  101.         fontSize: 14,
  102.         fontWeight: '500',
  103.         color: '#fff',
  104.         textAlign: 'center',
  105.     },
  106.     buttonModal: {
  107.         width: '85%',
  108.         backgroundColor: '#38B6D9',
  109.         borderRadius: 1,
  110.         marginVertical: 8,
  111.         paddingVertical: 10,
  112.     },
  113.     modalContent: {
  114.         backgroundColor: 'white',
  115.         padding: 22,
  116.         justifyContent: 'center',
  117.         alignItems: 'center',
  118.         borderRadius: 1,
  119.         borderColor: 'rgba(0, 0, 0, 0.1)',
  120.     },
  121.     modalTextContent: {
  122.         fontSize: 13,
  123.         fontWeight: 'bold',
  124.         textAlign: "center"
  125.     },
  126.     bottomModal: {
  127.         justifyContent: 'flex-end',
  128.         margin: 0,
  129.     },
  130. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement