/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, { Component } from 'react';
import {
  View,
} from 'react-native';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { pop } from '../../BasicNavigator/actions';
import NavigationBar from '../../components/NavigationBar';
import BackButton from '../../components/BackButton';
import Button from '../../components/ThemeButton';
import Styles from '../../theme/Styles';
import Text from '../../components/Text';
type Props = {
  routes: Array,
  popTo: () => void
};
class NativePage extends Component<Props> {
  render() {
    //console.log('NativePage props from lastPage', this.props.navigation.state);
    return (
      <View style={Styles.container}>
        <NavigationBar
          left={<BackButton />}
          title="ThemeDemo"
        />
        <View style={[Styles.container, { justifyContent: 'center' }]}>
          <Text style={Styles.instructions}>第二个页面</Text>
          <Button
            containerStyle={{ height: 40, margin: 10 }}
            onPress={() => {
              console.log('onPress', this.props);
              this.props.popTo('TabPage');
            }}
            title="返回首页"
          />
        </View>
      </View>

    );
  }
}

function propsMapping(props) {
  const { nav } = props;
  return {
    routes: nav ? nav.routes : [],
  };
}
function actionMapping(dispatch) {
  return {
    popTo: compose(dispatch, pop),
  };
}
//const mapDispatchToProps = dispatch => (bindActionCreators({goNext}, dispatch))

export default connect(propsMapping, actionMapping)(NativePage);
