我正在尝试通过单击按钮来启动模式,但无论出于何种原因,模式似乎都没有启动
import React, { PropTypes } from 'react'
import { View, Alert, ScrollView, Text, Modal, TouchableHighlight } from 'react-native'
import { connect } from 'react-redux'
import Actions from '../Actions/Creators'
import { Actions as NavigationActions } from 'react-native-router-flux'
import CartRow from '../Components/CartRow'
import CartTotal from '../Components/CartTotal'
import RoundedButton from '../Components/RoundedButton'
// Styles
import styles from './Styles/CartAndCheckoutStyle'
class CartAndCheckout extends React.Component {
constructor (props) {
super(props)
this.state = {
modalVisible: false
}
}
setModalVisible(visible) {
this.setState({modalVisible: visible});
console.log(visible)
}
static propTypes = {
items: PropTypes.array,
}
render () {
return (
<View style={styles.container}>
<View style={styles.currentBalance}>
<Text style={styles.currentBalanceTitle}>CURRENT BALANCE</Text>
<Text style={styles.currentBalanceAmount}>$0.00</Text>
</View>
<ScrollView>
<Modal
animationType={"slide"}
transparent={false}
visible={this.state.modalVisible}
onRequestClose={() => {Alert.alert("Modal has been closed.")}}
>
<View style={{marginTop: 22}}>
<View>
<Text>Hello World!</Text>
</View>
</View>
</Modal>
<View style={styles.cartItems}>
{(this.props.items||[]).map((section,i) => (
<CartRow key={i} action={this.setQty} index={i} element={section} />
))}
</View>
<CartTotal items={this.props.items||[]} />
</ScrollView>
<RoundedButton onPress={()=>{this.setModalVisible(true)}} text='Place Order' />
</View>
)
}
}
CartAndCheckout.propTypes = {
updateCart: PropTypes.func,
}
const mapStateToProps = (state) => {
return {
// items: state.cart.items,
}
}
const mapDispatchToProps = (dispatch) => {
return {
updateCart: (index,qty) => dispatch(Actions.updateCart(index,qty)),
}
}
export default connect(mapStateToProps, mapDispatchToProps)(CartAndCheckout)