React native 全球国家获胜';t通过调度还原程序进行更新

React native 全球国家获胜';t通过调度还原程序进行更新,react-native,redux,react-redux,redux-thunk,React Native,Redux,React Redux,Redux Thunk,index.js import React from 'react'; import { AppRegistry } from 'react-native' import App from './App'; import { YellowBox } from 'react-native'; YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']); AppReg

index.js

import React from 'react';
import {
  AppRegistry
} from 'react-native'
import App from './App';

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);

AppRegistry.registerComponent('mhagora', () => App);
import React, { Component } from 'react';
import { Provider } from "react-redux";

import store from './app/store';
import { StyleProvider, getTheme } from "native-base";
import Setup from "./app/setup";
import variables from "./app/theme/variables/commonColor";

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <StyleProvider style={getTheme(variables)}>
          <Setup />
        </StyleProvider>
      </Provider>
    );
  }
}
import React, { Component } from "react";
import axios from "axios/index";
import Config from "./config";
import { Root } from "native-base";

import AppNavigator from "./routes";

axios.defaults.baseURL = Config.API_BASE_URL;
axios.defaults.headers.common['Content-Type'] = Config.API_ACCEPT;
axios.defaults.headers.common['Accept'] = Config.API_ACCEPT;
axios.defaults.headers.common['secret'] = Config.API_SECRET;

export default class Setup extends Component {
  render() {
    return (
      <Root>
        <AppNavigator />
      </Root>
    );
  }
}
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import { createLogger } from 'redux-logger';

import reducers from '../reducers';

const logger = createLogger();

export default createStore(reducers, compose(applyMiddleware(thunk, logger)));
import { APP_LOADING, APP_LOADED } from '../actionTypes';

export function appLoading() {
  return (dispatch) => {
    dispatch({type: APP_LOADING});
  }
}

export function appLoaded() {
  return (dispatch) => {
    dispatch({type: APP_LOADED});
  }
}
import { USER_LOADING, USER_LOADED, USER_FAILED, APP_LOADING, APP_LOADED } from "../actionTypes";
import axios from 'axios';
import Config from '../config';

export function userLogin(username, password) {
  return (dispatch) => {
    dispatch({type: USER_LOADING});
    axios
      .post("oauth/token", {
        username: username,
        password: password,
        client_id: Config.API_CLIENT_ID,
        client_secret: Config.API_CLIENT_SECRET,
        grant_type: 'password',
      }, {
        headers: {}
      })
      .then(response => {
        dispatch({
          type: USER_LOADED,
          data: response.data
        });
      })
      .catch(err => {
        dispatch({ type: USER_FAILED, error: err.response.data.message });
        alert(err.response.data.message);
      });
  };
}
import appReducer from './appReducer';
import userReducer from './userReducer';
import { combineReducers } from "redux";

const rootReducer = combineReducers({
  appReducer,
  userReducer
});

export default rootReducer;
import { USER_LOADING, USER_LOADED, USER_FAILED } from '../actionTypes';
const initialState = {
  username: "",
  password: "",
  user: {}
};

export default userReducer = (state = initialState, action) => {
  switch (action.type) {
    case USER_LOADING:
      return Object.assign({}, state, {
        loading: true,
        user: {},
      });
    case USER_LOADED:
      return Object.assign({}, state, {
        loading: false,
        user: action.data
      });
    case USER_FAILED:
      return Object.assign({}, state, {
        loading: false,
      });
    default:
      return state
  }
}
import { APP_LOADING, APP_LOADED } from "../actionTypes";

const initialState = {
  loading: true,
};

export default appReducer = (state = initialState, action) => {
  switch (action.type) {
    case APP_LOADING:
      return Object.assign({}, state, {
        loading: true
      });
    case APP_LOADED:
      return Object.assign({}, state, {
        loading: false
      });
    default:
      return state;
  }
};
'use strict';

import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { SkypeIndicator } from 'react-native-indicators';

import * as Actions from '../actions/index';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text, View } from 'native-base';

class HomeScreen extends Component {
  componentDidMount() {
    /** HERE, the apps should show a loading page forever but it didn't **/
    // setTimeout( _ => {
      // this.props.appLoaded();
    // }, 2000);
  }

  render() {
    if (this.props.loading) {
      return (
        <SkypeIndicator />
      );
    } else {
      return (
        <Container>
          <Header>

          </Header>
          <Body>
            <Button
              onPress={() =>
                this.props.navigation.navigate('LoginScreen')
              }><Text>Login now</Text></Button>
            <Text>Hello</Text>
          </Body>
        </Container>

      );
    }
  }
}

// The function takes data from the app current state,
// and insert/links it into the props of our component.
// This function makes Redux know that this component needs to be passed a piece of the state
function mapStateToProps(state, props) {
  return {
    loading: state.loading,
    user: state.user,
  }
}

// Doing this merges our actions into the component’s props,
// while wrapping them in dispatch() so that they immediately dispatch an Action.
// Just by doing this, we will have access to the actions defined in out actions file (action/homeScreen.js)
function mapDispatchToProps(dispatch) {
  return bindActionCreators(Actions, dispatch);
}

//Connect everything
export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen);
App.js

import React from 'react';
import {
  AppRegistry
} from 'react-native'
import App from './App';

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);

AppRegistry.registerComponent('mhagora', () => App);
import React, { Component } from 'react';
import { Provider } from "react-redux";

import store from './app/store';
import { StyleProvider, getTheme } from "native-base";
import Setup from "./app/setup";
import variables from "./app/theme/variables/commonColor";

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <StyleProvider style={getTheme(variables)}>
          <Setup />
        </StyleProvider>
      </Provider>
    );
  }
}
import React, { Component } from "react";
import axios from "axios/index";
import Config from "./config";
import { Root } from "native-base";

import AppNavigator from "./routes";

axios.defaults.baseURL = Config.API_BASE_URL;
axios.defaults.headers.common['Content-Type'] = Config.API_ACCEPT;
axios.defaults.headers.common['Accept'] = Config.API_ACCEPT;
axios.defaults.headers.common['secret'] = Config.API_SECRET;

export default class Setup extends Component {
  render() {
    return (
      <Root>
        <AppNavigator />
      </Root>
    );
  }
}
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import { createLogger } from 'redux-logger';

import reducers from '../reducers';

const logger = createLogger();

export default createStore(reducers, compose(applyMiddleware(thunk, logger)));
import { APP_LOADING, APP_LOADED } from '../actionTypes';

export function appLoading() {
  return (dispatch) => {
    dispatch({type: APP_LOADING});
  }
}

export function appLoaded() {
  return (dispatch) => {
    dispatch({type: APP_LOADED});
  }
}
import { USER_LOADING, USER_LOADED, USER_FAILED, APP_LOADING, APP_LOADED } from "../actionTypes";
import axios from 'axios';
import Config from '../config';

export function userLogin(username, password) {
  return (dispatch) => {
    dispatch({type: USER_LOADING});
    axios
      .post("oauth/token", {
        username: username,
        password: password,
        client_id: Config.API_CLIENT_ID,
        client_secret: Config.API_CLIENT_SECRET,
        grant_type: 'password',
      }, {
        headers: {}
      })
      .then(response => {
        dispatch({
          type: USER_LOADED,
          data: response.data
        });
      })
      .catch(err => {
        dispatch({ type: USER_FAILED, error: err.response.data.message });
        alert(err.response.data.message);
      });
  };
}
import appReducer from './appReducer';
import userReducer from './userReducer';
import { combineReducers } from "redux";

const rootReducer = combineReducers({
  appReducer,
  userReducer
});

export default rootReducer;
import { USER_LOADING, USER_LOADED, USER_FAILED } from '../actionTypes';
const initialState = {
  username: "",
  password: "",
  user: {}
};

export default userReducer = (state = initialState, action) => {
  switch (action.type) {
    case USER_LOADING:
      return Object.assign({}, state, {
        loading: true,
        user: {},
      });
    case USER_LOADED:
      return Object.assign({}, state, {
        loading: false,
        user: action.data
      });
    case USER_FAILED:
      return Object.assign({}, state, {
        loading: false,
      });
    default:
      return state
  }
}
import { APP_LOADING, APP_LOADED } from "../actionTypes";

const initialState = {
  loading: true,
};

export default appReducer = (state = initialState, action) => {
  switch (action.type) {
    case APP_LOADING:
      return Object.assign({}, state, {
        loading: true
      });
    case APP_LOADED:
      return Object.assign({}, state, {
        loading: false
      });
    default:
      return state;
  }
};
'use strict';

import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { SkypeIndicator } from 'react-native-indicators';

import * as Actions from '../actions/index';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text, View } from 'native-base';

class HomeScreen extends Component {
  componentDidMount() {
    /** HERE, the apps should show a loading page forever but it didn't **/
    // setTimeout( _ => {
      // this.props.appLoaded();
    // }, 2000);
  }

  render() {
    if (this.props.loading) {
      return (
        <SkypeIndicator />
      );
    } else {
      return (
        <Container>
          <Header>

          </Header>
          <Body>
            <Button
              onPress={() =>
                this.props.navigation.navigate('LoginScreen')
              }><Text>Login now</Text></Button>
            <Text>Hello</Text>
          </Body>
        </Container>

      );
    }
  }
}

// The function takes data from the app current state,
// and insert/links it into the props of our component.
// This function makes Redux know that this component needs to be passed a piece of the state
function mapStateToProps(state, props) {
  return {
    loading: state.loading,
    user: state.user,
  }
}

// Doing this merges our actions into the component’s props,
// while wrapping them in dispatch() so that they immediately dispatch an Action.
// Just by doing this, we will have access to the actions defined in out actions file (action/homeScreen.js)
function mapDispatchToProps(dispatch) {
  return bindActionCreators(Actions, dispatch);
}

//Connect everything
export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen);
/app/actions/index.js

import React from 'react';
import {
  AppRegistry
} from 'react-native'
import App from './App';

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);

AppRegistry.registerComponent('mhagora', () => App);
import React, { Component } from 'react';
import { Provider } from "react-redux";

import store from './app/store';
import { StyleProvider, getTheme } from "native-base";
import Setup from "./app/setup";
import variables from "./app/theme/variables/commonColor";

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <StyleProvider style={getTheme(variables)}>
          <Setup />
        </StyleProvider>
      </Provider>
    );
  }
}
import React, { Component } from "react";
import axios from "axios/index";
import Config from "./config";
import { Root } from "native-base";

import AppNavigator from "./routes";

axios.defaults.baseURL = Config.API_BASE_URL;
axios.defaults.headers.common['Content-Type'] = Config.API_ACCEPT;
axios.defaults.headers.common['Accept'] = Config.API_ACCEPT;
axios.defaults.headers.common['secret'] = Config.API_SECRET;

export default class Setup extends Component {
  render() {
    return (
      <Root>
        <AppNavigator />
      </Root>
    );
  }
}
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import { createLogger } from 'redux-logger';

import reducers from '../reducers';

const logger = createLogger();

export default createStore(reducers, compose(applyMiddleware(thunk, logger)));
import { APP_LOADING, APP_LOADED } from '../actionTypes';

export function appLoading() {
  return (dispatch) => {
    dispatch({type: APP_LOADING});
  }
}

export function appLoaded() {
  return (dispatch) => {
    dispatch({type: APP_LOADED});
  }
}
import { USER_LOADING, USER_LOADED, USER_FAILED, APP_LOADING, APP_LOADED } from "../actionTypes";
import axios from 'axios';
import Config from '../config';

export function userLogin(username, password) {
  return (dispatch) => {
    dispatch({type: USER_LOADING});
    axios
      .post("oauth/token", {
        username: username,
        password: password,
        client_id: Config.API_CLIENT_ID,
        client_secret: Config.API_CLIENT_SECRET,
        grant_type: 'password',
      }, {
        headers: {}
      })
      .then(response => {
        dispatch({
          type: USER_LOADED,
          data: response.data
        });
      })
      .catch(err => {
        dispatch({ type: USER_FAILED, error: err.response.data.message });
        alert(err.response.data.message);
      });
  };
}
import appReducer from './appReducer';
import userReducer from './userReducer';
import { combineReducers } from "redux";

const rootReducer = combineReducers({
  appReducer,
  userReducer
});

export default rootReducer;
import { USER_LOADING, USER_LOADED, USER_FAILED } from '../actionTypes';
const initialState = {
  username: "",
  password: "",
  user: {}
};

export default userReducer = (state = initialState, action) => {
  switch (action.type) {
    case USER_LOADING:
      return Object.assign({}, state, {
        loading: true,
        user: {},
      });
    case USER_LOADED:
      return Object.assign({}, state, {
        loading: false,
        user: action.data
      });
    case USER_FAILED:
      return Object.assign({}, state, {
        loading: false,
      });
    default:
      return state
  }
}
import { APP_LOADING, APP_LOADED } from "../actionTypes";

const initialState = {
  loading: true,
};

export default appReducer = (state = initialState, action) => {
  switch (action.type) {
    case APP_LOADING:
      return Object.assign({}, state, {
        loading: true
      });
    case APP_LOADED:
      return Object.assign({}, state, {
        loading: false
      });
    default:
      return state;
  }
};
'use strict';

import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { SkypeIndicator } from 'react-native-indicators';

import * as Actions from '../actions/index';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text, View } from 'native-base';

class HomeScreen extends Component {
  componentDidMount() {
    /** HERE, the apps should show a loading page forever but it didn't **/
    // setTimeout( _ => {
      // this.props.appLoaded();
    // }, 2000);
  }

  render() {
    if (this.props.loading) {
      return (
        <SkypeIndicator />
      );
    } else {
      return (
        <Container>
          <Header>

          </Header>
          <Body>
            <Button
              onPress={() =>
                this.props.navigation.navigate('LoginScreen')
              }><Text>Login now</Text></Button>
            <Text>Hello</Text>
          </Body>
        </Container>

      );
    }
  }
}

// The function takes data from the app current state,
// and insert/links it into the props of our component.
// This function makes Redux know that this component needs to be passed a piece of the state
function mapStateToProps(state, props) {
  return {
    loading: state.loading,
    user: state.user,
  }
}

// Doing this merges our actions into the component’s props,
// while wrapping them in dispatch() so that they immediately dispatch an Action.
// Just by doing this, we will have access to the actions defined in out actions file (action/homeScreen.js)
function mapDispatchToProps(dispatch) {
  return bindActionCreators(Actions, dispatch);
}

//Connect everything
export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen);
/app/actions/user.js

import React from 'react';
import {
  AppRegistry
} from 'react-native'
import App from './App';

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);

AppRegistry.registerComponent('mhagora', () => App);
import React, { Component } from 'react';
import { Provider } from "react-redux";

import store from './app/store';
import { StyleProvider, getTheme } from "native-base";
import Setup from "./app/setup";
import variables from "./app/theme/variables/commonColor";

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <StyleProvider style={getTheme(variables)}>
          <Setup />
        </StyleProvider>
      </Provider>
    );
  }
}
import React, { Component } from "react";
import axios from "axios/index";
import Config from "./config";
import { Root } from "native-base";

import AppNavigator from "./routes";

axios.defaults.baseURL = Config.API_BASE_URL;
axios.defaults.headers.common['Content-Type'] = Config.API_ACCEPT;
axios.defaults.headers.common['Accept'] = Config.API_ACCEPT;
axios.defaults.headers.common['secret'] = Config.API_SECRET;

export default class Setup extends Component {
  render() {
    return (
      <Root>
        <AppNavigator />
      </Root>
    );
  }
}
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import { createLogger } from 'redux-logger';

import reducers from '../reducers';

const logger = createLogger();

export default createStore(reducers, compose(applyMiddleware(thunk, logger)));
import { APP_LOADING, APP_LOADED } from '../actionTypes';

export function appLoading() {
  return (dispatch) => {
    dispatch({type: APP_LOADING});
  }
}

export function appLoaded() {
  return (dispatch) => {
    dispatch({type: APP_LOADED});
  }
}
import { USER_LOADING, USER_LOADED, USER_FAILED, APP_LOADING, APP_LOADED } from "../actionTypes";
import axios from 'axios';
import Config from '../config';

export function userLogin(username, password) {
  return (dispatch) => {
    dispatch({type: USER_LOADING});
    axios
      .post("oauth/token", {
        username: username,
        password: password,
        client_id: Config.API_CLIENT_ID,
        client_secret: Config.API_CLIENT_SECRET,
        grant_type: 'password',
      }, {
        headers: {}
      })
      .then(response => {
        dispatch({
          type: USER_LOADED,
          data: response.data
        });
      })
      .catch(err => {
        dispatch({ type: USER_FAILED, error: err.response.data.message });
        alert(err.response.data.message);
      });
  };
}
import appReducer from './appReducer';
import userReducer from './userReducer';
import { combineReducers } from "redux";

const rootReducer = combineReducers({
  appReducer,
  userReducer
});

export default rootReducer;
import { USER_LOADING, USER_LOADED, USER_FAILED } from '../actionTypes';
const initialState = {
  username: "",
  password: "",
  user: {}
};

export default userReducer = (state = initialState, action) => {
  switch (action.type) {
    case USER_LOADING:
      return Object.assign({}, state, {
        loading: true,
        user: {},
      });
    case USER_LOADED:
      return Object.assign({}, state, {
        loading: false,
        user: action.data
      });
    case USER_FAILED:
      return Object.assign({}, state, {
        loading: false,
      });
    default:
      return state
  }
}
import { APP_LOADING, APP_LOADED } from "../actionTypes";

const initialState = {
  loading: true,
};

export default appReducer = (state = initialState, action) => {
  switch (action.type) {
    case APP_LOADING:
      return Object.assign({}, state, {
        loading: true
      });
    case APP_LOADED:
      return Object.assign({}, state, {
        loading: false
      });
    default:
      return state;
  }
};
'use strict';

import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { SkypeIndicator } from 'react-native-indicators';

import * as Actions from '../actions/index';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text, View } from 'native-base';

class HomeScreen extends Component {
  componentDidMount() {
    /** HERE, the apps should show a loading page forever but it didn't **/
    // setTimeout( _ => {
      // this.props.appLoaded();
    // }, 2000);
  }

  render() {
    if (this.props.loading) {
      return (
        <SkypeIndicator />
      );
    } else {
      return (
        <Container>
          <Header>

          </Header>
          <Body>
            <Button
              onPress={() =>
                this.props.navigation.navigate('LoginScreen')
              }><Text>Login now</Text></Button>
            <Text>Hello</Text>
          </Body>
        </Container>

      );
    }
  }
}

// The function takes data from the app current state,
// and insert/links it into the props of our component.
// This function makes Redux know that this component needs to be passed a piece of the state
function mapStateToProps(state, props) {
  return {
    loading: state.loading,
    user: state.user,
  }
}

// Doing this merges our actions into the component’s props,
// while wrapping them in dispatch() so that they immediately dispatch an Action.
// Just by doing this, we will have access to the actions defined in out actions file (action/homeScreen.js)
function mapDispatchToProps(dispatch) {
  return bindActionCreators(Actions, dispatch);
}

//Connect everything
export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen);
/app/reducers/index.js

import React from 'react';
import {
  AppRegistry
} from 'react-native'
import App from './App';

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);

AppRegistry.registerComponent('mhagora', () => App);
import React, { Component } from 'react';
import { Provider } from "react-redux";

import store from './app/store';
import { StyleProvider, getTheme } from "native-base";
import Setup from "./app/setup";
import variables from "./app/theme/variables/commonColor";

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <StyleProvider style={getTheme(variables)}>
          <Setup />
        </StyleProvider>
      </Provider>
    );
  }
}
import React, { Component } from "react";
import axios from "axios/index";
import Config from "./config";
import { Root } from "native-base";

import AppNavigator from "./routes";

axios.defaults.baseURL = Config.API_BASE_URL;
axios.defaults.headers.common['Content-Type'] = Config.API_ACCEPT;
axios.defaults.headers.common['Accept'] = Config.API_ACCEPT;
axios.defaults.headers.common['secret'] = Config.API_SECRET;

export default class Setup extends Component {
  render() {
    return (
      <Root>
        <AppNavigator />
      </Root>
    );
  }
}
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import { createLogger } from 'redux-logger';

import reducers from '../reducers';

const logger = createLogger();

export default createStore(reducers, compose(applyMiddleware(thunk, logger)));
import { APP_LOADING, APP_LOADED } from '../actionTypes';

export function appLoading() {
  return (dispatch) => {
    dispatch({type: APP_LOADING});
  }
}

export function appLoaded() {
  return (dispatch) => {
    dispatch({type: APP_LOADED});
  }
}
import { USER_LOADING, USER_LOADED, USER_FAILED, APP_LOADING, APP_LOADED } from "../actionTypes";
import axios from 'axios';
import Config from '../config';

export function userLogin(username, password) {
  return (dispatch) => {
    dispatch({type: USER_LOADING});
    axios
      .post("oauth/token", {
        username: username,
        password: password,
        client_id: Config.API_CLIENT_ID,
        client_secret: Config.API_CLIENT_SECRET,
        grant_type: 'password',
      }, {
        headers: {}
      })
      .then(response => {
        dispatch({
          type: USER_LOADED,
          data: response.data
        });
      })
      .catch(err => {
        dispatch({ type: USER_FAILED, error: err.response.data.message });
        alert(err.response.data.message);
      });
  };
}
import appReducer from './appReducer';
import userReducer from './userReducer';
import { combineReducers } from "redux";

const rootReducer = combineReducers({
  appReducer,
  userReducer
});

export default rootReducer;
import { USER_LOADING, USER_LOADED, USER_FAILED } from '../actionTypes';
const initialState = {
  username: "",
  password: "",
  user: {}
};

export default userReducer = (state = initialState, action) => {
  switch (action.type) {
    case USER_LOADING:
      return Object.assign({}, state, {
        loading: true,
        user: {},
      });
    case USER_LOADED:
      return Object.assign({}, state, {
        loading: false,
        user: action.data
      });
    case USER_FAILED:
      return Object.assign({}, state, {
        loading: false,
      });
    default:
      return state
  }
}
import { APP_LOADING, APP_LOADED } from "../actionTypes";

const initialState = {
  loading: true,
};

export default appReducer = (state = initialState, action) => {
  switch (action.type) {
    case APP_LOADING:
      return Object.assign({}, state, {
        loading: true
      });
    case APP_LOADED:
      return Object.assign({}, state, {
        loading: false
      });
    default:
      return state;
  }
};
'use strict';

import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { SkypeIndicator } from 'react-native-indicators';

import * as Actions from '../actions/index';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text, View } from 'native-base';

class HomeScreen extends Component {
  componentDidMount() {
    /** HERE, the apps should show a loading page forever but it didn't **/
    // setTimeout( _ => {
      // this.props.appLoaded();
    // }, 2000);
  }

  render() {
    if (this.props.loading) {
      return (
        <SkypeIndicator />
      );
    } else {
      return (
        <Container>
          <Header>

          </Header>
          <Body>
            <Button
              onPress={() =>
                this.props.navigation.navigate('LoginScreen')
              }><Text>Login now</Text></Button>
            <Text>Hello</Text>
          </Body>
        </Container>

      );
    }
  }
}

// The function takes data from the app current state,
// and insert/links it into the props of our component.
// This function makes Redux know that this component needs to be passed a piece of the state
function mapStateToProps(state, props) {
  return {
    loading: state.loading,
    user: state.user,
  }
}

// Doing this merges our actions into the component’s props,
// while wrapping them in dispatch() so that they immediately dispatch an Action.
// Just by doing this, we will have access to the actions defined in out actions file (action/homeScreen.js)
function mapDispatchToProps(dispatch) {
  return bindActionCreators(Actions, dispatch);
}

//Connect everything
export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen);
/app/reducers/userReducer.js

import React from 'react';
import {
  AppRegistry
} from 'react-native'
import App from './App';

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);

AppRegistry.registerComponent('mhagora', () => App);
import React, { Component } from 'react';
import { Provider } from "react-redux";

import store from './app/store';
import { StyleProvider, getTheme } from "native-base";
import Setup from "./app/setup";
import variables from "./app/theme/variables/commonColor";

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <StyleProvider style={getTheme(variables)}>
          <Setup />
        </StyleProvider>
      </Provider>
    );
  }
}
import React, { Component } from "react";
import axios from "axios/index";
import Config from "./config";
import { Root } from "native-base";

import AppNavigator from "./routes";

axios.defaults.baseURL = Config.API_BASE_URL;
axios.defaults.headers.common['Content-Type'] = Config.API_ACCEPT;
axios.defaults.headers.common['Accept'] = Config.API_ACCEPT;
axios.defaults.headers.common['secret'] = Config.API_SECRET;

export default class Setup extends Component {
  render() {
    return (
      <Root>
        <AppNavigator />
      </Root>
    );
  }
}
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import { createLogger } from 'redux-logger';

import reducers from '../reducers';

const logger = createLogger();

export default createStore(reducers, compose(applyMiddleware(thunk, logger)));
import { APP_LOADING, APP_LOADED } from '../actionTypes';

export function appLoading() {
  return (dispatch) => {
    dispatch({type: APP_LOADING});
  }
}

export function appLoaded() {
  return (dispatch) => {
    dispatch({type: APP_LOADED});
  }
}
import { USER_LOADING, USER_LOADED, USER_FAILED, APP_LOADING, APP_LOADED } from "../actionTypes";
import axios from 'axios';
import Config from '../config';

export function userLogin(username, password) {
  return (dispatch) => {
    dispatch({type: USER_LOADING});
    axios
      .post("oauth/token", {
        username: username,
        password: password,
        client_id: Config.API_CLIENT_ID,
        client_secret: Config.API_CLIENT_SECRET,
        grant_type: 'password',
      }, {
        headers: {}
      })
      .then(response => {
        dispatch({
          type: USER_LOADED,
          data: response.data
        });
      })
      .catch(err => {
        dispatch({ type: USER_FAILED, error: err.response.data.message });
        alert(err.response.data.message);
      });
  };
}
import appReducer from './appReducer';
import userReducer from './userReducer';
import { combineReducers } from "redux";

const rootReducer = combineReducers({
  appReducer,
  userReducer
});

export default rootReducer;
import { USER_LOADING, USER_LOADED, USER_FAILED } from '../actionTypes';
const initialState = {
  username: "",
  password: "",
  user: {}
};

export default userReducer = (state = initialState, action) => {
  switch (action.type) {
    case USER_LOADING:
      return Object.assign({}, state, {
        loading: true,
        user: {},
      });
    case USER_LOADED:
      return Object.assign({}, state, {
        loading: false,
        user: action.data
      });
    case USER_FAILED:
      return Object.assign({}, state, {
        loading: false,
      });
    default:
      return state
  }
}
import { APP_LOADING, APP_LOADED } from "../actionTypes";

const initialState = {
  loading: true,
};

export default appReducer = (state = initialState, action) => {
  switch (action.type) {
    case APP_LOADING:
      return Object.assign({}, state, {
        loading: true
      });
    case APP_LOADED:
      return Object.assign({}, state, {
        loading: false
      });
    default:
      return state;
  }
};
'use strict';

import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { SkypeIndicator } from 'react-native-indicators';

import * as Actions from '../actions/index';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text, View } from 'native-base';

class HomeScreen extends Component {
  componentDidMount() {
    /** HERE, the apps should show a loading page forever but it didn't **/
    // setTimeout( _ => {
      // this.props.appLoaded();
    // }, 2000);
  }

  render() {
    if (this.props.loading) {
      return (
        <SkypeIndicator />
      );
    } else {
      return (
        <Container>
          <Header>

          </Header>
          <Body>
            <Button
              onPress={() =>
                this.props.navigation.navigate('LoginScreen')
              }><Text>Login now</Text></Button>
            <Text>Hello</Text>
          </Body>
        </Container>

      );
    }
  }
}

// The function takes data from the app current state,
// and insert/links it into the props of our component.
// This function makes Redux know that this component needs to be passed a piece of the state
function mapStateToProps(state, props) {
  return {
    loading: state.loading,
    user: state.user,
  }
}

// Doing this merges our actions into the component’s props,
// while wrapping them in dispatch() so that they immediately dispatch an Action.
// Just by doing this, we will have access to the actions defined in out actions file (action/homeScreen.js)
function mapDispatchToProps(dispatch) {
  return bindActionCreators(Actions, dispatch);
}

//Connect everything
export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen);
/app/reducers/appReducer.js

import React from 'react';
import {
  AppRegistry
} from 'react-native'
import App from './App';

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);

AppRegistry.registerComponent('mhagora', () => App);
import React, { Component } from 'react';
import { Provider } from "react-redux";

import store from './app/store';
import { StyleProvider, getTheme } from "native-base";
import Setup from "./app/setup";
import variables from "./app/theme/variables/commonColor";

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <StyleProvider style={getTheme(variables)}>
          <Setup />
        </StyleProvider>
      </Provider>
    );
  }
}
import React, { Component } from "react";
import axios from "axios/index";
import Config from "./config";
import { Root } from "native-base";

import AppNavigator from "./routes";

axios.defaults.baseURL = Config.API_BASE_URL;
axios.defaults.headers.common['Content-Type'] = Config.API_ACCEPT;
axios.defaults.headers.common['Accept'] = Config.API_ACCEPT;
axios.defaults.headers.common['secret'] = Config.API_SECRET;

export default class Setup extends Component {
  render() {
    return (
      <Root>
        <AppNavigator />
      </Root>
    );
  }
}
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import { createLogger } from 'redux-logger';

import reducers from '../reducers';

const logger = createLogger();

export default createStore(reducers, compose(applyMiddleware(thunk, logger)));
import { APP_LOADING, APP_LOADED } from '../actionTypes';

export function appLoading() {
  return (dispatch) => {
    dispatch({type: APP_LOADING});
  }
}

export function appLoaded() {
  return (dispatch) => {
    dispatch({type: APP_LOADED});
  }
}
import { USER_LOADING, USER_LOADED, USER_FAILED, APP_LOADING, APP_LOADED } from "../actionTypes";
import axios from 'axios';
import Config from '../config';

export function userLogin(username, password) {
  return (dispatch) => {
    dispatch({type: USER_LOADING});
    axios
      .post("oauth/token", {
        username: username,
        password: password,
        client_id: Config.API_CLIENT_ID,
        client_secret: Config.API_CLIENT_SECRET,
        grant_type: 'password',
      }, {
        headers: {}
      })
      .then(response => {
        dispatch({
          type: USER_LOADED,
          data: response.data
        });
      })
      .catch(err => {
        dispatch({ type: USER_FAILED, error: err.response.data.message });
        alert(err.response.data.message);
      });
  };
}
import appReducer from './appReducer';
import userReducer from './userReducer';
import { combineReducers } from "redux";

const rootReducer = combineReducers({
  appReducer,
  userReducer
});

export default rootReducer;
import { USER_LOADING, USER_LOADED, USER_FAILED } from '../actionTypes';
const initialState = {
  username: "",
  password: "",
  user: {}
};

export default userReducer = (state = initialState, action) => {
  switch (action.type) {
    case USER_LOADING:
      return Object.assign({}, state, {
        loading: true,
        user: {},
      });
    case USER_LOADED:
      return Object.assign({}, state, {
        loading: false,
        user: action.data
      });
    case USER_FAILED:
      return Object.assign({}, state, {
        loading: false,
      });
    default:
      return state
  }
}
import { APP_LOADING, APP_LOADED } from "../actionTypes";

const initialState = {
  loading: true,
};

export default appReducer = (state = initialState, action) => {
  switch (action.type) {
    case APP_LOADING:
      return Object.assign({}, state, {
        loading: true
      });
    case APP_LOADED:
      return Object.assign({}, state, {
        loading: false
      });
    default:
      return state;
  }
};
'use strict';

import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { SkypeIndicator } from 'react-native-indicators';

import * as Actions from '../actions/index';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text, View } from 'native-base';

class HomeScreen extends Component {
  componentDidMount() {
    /** HERE, the apps should show a loading page forever but it didn't **/
    // setTimeout( _ => {
      // this.props.appLoaded();
    // }, 2000);
  }

  render() {
    if (this.props.loading) {
      return (
        <SkypeIndicator />
      );
    } else {
      return (
        <Container>
          <Header>

          </Header>
          <Body>
            <Button
              onPress={() =>
                this.props.navigation.navigate('LoginScreen')
              }><Text>Login now</Text></Button>
            <Text>Hello</Text>
          </Body>
        </Container>

      );
    }
  }
}

// The function takes data from the app current state,
// and insert/links it into the props of our component.
// This function makes Redux know that this component needs to be passed a piece of the state
function mapStateToProps(state, props) {
  return {
    loading: state.loading,
    user: state.user,
  }
}

// Doing this merges our actions into the component’s props,
// while wrapping them in dispatch() so that they immediately dispatch an Action.
// Just by doing this, we will have access to the actions defined in out actions file (action/homeScreen.js)
function mapDispatchToProps(dispatch) {
  return bindActionCreators(Actions, dispatch);
}

//Connect everything
export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen);
/app/screens/home.js

import React from 'react';
import {
  AppRegistry
} from 'react-native'
import App from './App';

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);

AppRegistry.registerComponent('mhagora', () => App);
import React, { Component } from 'react';
import { Provider } from "react-redux";

import store from './app/store';
import { StyleProvider, getTheme } from "native-base";
import Setup from "./app/setup";
import variables from "./app/theme/variables/commonColor";

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <StyleProvider style={getTheme(variables)}>
          <Setup />
        </StyleProvider>
      </Provider>
    );
  }
}
import React, { Component } from "react";
import axios from "axios/index";
import Config from "./config";
import { Root } from "native-base";

import AppNavigator from "./routes";

axios.defaults.baseURL = Config.API_BASE_URL;
axios.defaults.headers.common['Content-Type'] = Config.API_ACCEPT;
axios.defaults.headers.common['Accept'] = Config.API_ACCEPT;
axios.defaults.headers.common['secret'] = Config.API_SECRET;

export default class Setup extends Component {
  render() {
    return (
      <Root>
        <AppNavigator />
      </Root>
    );
  }
}
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import { createLogger } from 'redux-logger';

import reducers from '../reducers';

const logger = createLogger();

export default createStore(reducers, compose(applyMiddleware(thunk, logger)));
import { APP_LOADING, APP_LOADED } from '../actionTypes';

export function appLoading() {
  return (dispatch) => {
    dispatch({type: APP_LOADING});
  }
}

export function appLoaded() {
  return (dispatch) => {
    dispatch({type: APP_LOADED});
  }
}
import { USER_LOADING, USER_LOADED, USER_FAILED, APP_LOADING, APP_LOADED } from "../actionTypes";
import axios from 'axios';
import Config from '../config';

export function userLogin(username, password) {
  return (dispatch) => {
    dispatch({type: USER_LOADING});
    axios
      .post("oauth/token", {
        username: username,
        password: password,
        client_id: Config.API_CLIENT_ID,
        client_secret: Config.API_CLIENT_SECRET,
        grant_type: 'password',
      }, {
        headers: {}
      })
      .then(response => {
        dispatch({
          type: USER_LOADED,
          data: response.data
        });
      })
      .catch(err => {
        dispatch({ type: USER_FAILED, error: err.response.data.message });
        alert(err.response.data.message);
      });
  };
}
import appReducer from './appReducer';
import userReducer from './userReducer';
import { combineReducers } from "redux";

const rootReducer = combineReducers({
  appReducer,
  userReducer
});

export default rootReducer;
import { USER_LOADING, USER_LOADED, USER_FAILED } from '../actionTypes';
const initialState = {
  username: "",
  password: "",
  user: {}
};

export default userReducer = (state = initialState, action) => {
  switch (action.type) {
    case USER_LOADING:
      return Object.assign({}, state, {
        loading: true,
        user: {},
      });
    case USER_LOADED:
      return Object.assign({}, state, {
        loading: false,
        user: action.data
      });
    case USER_FAILED:
      return Object.assign({}, state, {
        loading: false,
      });
    default:
      return state
  }
}
import { APP_LOADING, APP_LOADED } from "../actionTypes";

const initialState = {
  loading: true,
};

export default appReducer = (state = initialState, action) => {
  switch (action.type) {
    case APP_LOADING:
      return Object.assign({}, state, {
        loading: true
      });
    case APP_LOADED:
      return Object.assign({}, state, {
        loading: false
      });
    default:
      return state;
  }
};
'use strict';

import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { SkypeIndicator } from 'react-native-indicators';

import * as Actions from '../actions/index';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text, View } from 'native-base';

class HomeScreen extends Component {
  componentDidMount() {
    /** HERE, the apps should show a loading page forever but it didn't **/
    // setTimeout( _ => {
      // this.props.appLoaded();
    // }, 2000);
  }

  render() {
    if (this.props.loading) {
      return (
        <SkypeIndicator />
      );
    } else {
      return (
        <Container>
          <Header>

          </Header>
          <Body>
            <Button
              onPress={() =>
                this.props.navigation.navigate('LoginScreen')
              }><Text>Login now</Text></Button>
            <Text>Hello</Text>
          </Body>
        </Container>

      );
    }
  }
}

// The function takes data from the app current state,
// and insert/links it into the props of our component.
// This function makes Redux know that this component needs to be passed a piece of the state
function mapStateToProps(state, props) {
  return {
    loading: state.loading,
    user: state.user,
  }
}

// Doing this merges our actions into the component’s props,
// while wrapping them in dispatch() so that they immediately dispatch an Action.
// Just by doing this, we will have access to the actions defined in out actions file (action/homeScreen.js)
function mapDispatchToProps(dispatch) {
  return bindActionCreators(Actions, dispatch);
}

//Connect everything
export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen);
“严格使用”;
从“React”导入React,{Component};
从“redux”导入{bindActionCreators};
从'react redux'导入{connect};
从“react native indicators”导入{SkypeIndicator};
从“../Actions/index”导入*作为操作;
从“本机基础”导入{容器、页眉、标题、内容、页脚、页脚选项卡、按钮、左、右、正文、图标、文本、视图};
类主屏幕扩展组件{
componentDidMount(){
/**在这里,应用程序应该永远显示加载页面,但它没有**/
//setTimeout(U8;=>{
//this.props.apploated();
// }, 2000);
}
render(){
如果(本道具装载){
返回(
);
}否则{
返回(
this.props.navigation.navigate('LoginScreen'))
}>立即登录
你好
);
}
}
}
//该函数从应用程序当前状态获取数据,
//并将其插入/链接到我们组件的道具中。
//此函数使Redux知道需要向该组件传递一段状态
函数mapStateToProps(状态、道具){
返回{
加载:state.loading,
用户:state.user,
}
}
//这样做会将我们的行动合并到组件的道具中,
//将它们包装在dispatch()中,以便它们立即分派操作。
//只需这样做,我们就可以访问OutActions文件(action/homeScreen.js)中定义的操作
功能图DispatchToprops(调度){
返回bindActionCreators(操作、分派);
}
//连接一切
导出默认连接(mapStateToProps、mapDispatchToProps)(主屏幕);
/app/screens/loginScreen

'use strict';

import React, { Component } from 'react';
import { StyleSheet } from 'react-native';
import { SkypeIndicator } from 'react-native-indicators';
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import { Body, Button, Container, Content, Header, Icon, Left, Text, Title, View } from "native-base";
import t from 'tcomb-form-native';
import { LoginUserModel, LoginUserModelOption } from "../models/UserModel";
import styles from '../styles';
import LoadingButton from 'react-native-loading-button';
import * as UserActions from '../actions/user';

const Form = t.form.Form;

const ps = StyleSheet.create({
  ...styles,
  container: {
    justifyContent: 'center',
    marginTop: 50,
    padding: 20
  },
});

class LoginScreen extends Component {
  constructor(props) {
    super(props);
  }
  onSubmitHandler = () => {
    const value = this._form.getValue();

    if(value) {
      this.props.userLogin(value.username, value.password);
    }
  };

  render() {
    return (
      <Container>
        <Header>
          <Left>
            <Button transparent onPress={() => this.props.navigation.goBack()}>
              <Icon name="arrow-back"/>
            </Button>
          </Left>
          <Body>
          <Title>Headers</Title>
          </Body>
        </Header>
        <Content padder>
          <View style={ps.container}>
            <Form ref={c => this._form = c} type={LoginUserModel} options={LoginUserModelOption} />
            <LoadingButton
              block
              onPress={this.onSubmitHandler.bind(this)}
              isLoading={this.props.loading}
              style={{ justifyContent: 'center' }}
            ><Icon name="checkmark"/><Text>Login Now</Text></LoadingButton>
          </View>
        </Content>
      </Container>
    );
  }
}

// The function takes data from the app current state,
// and insert/links it into the props of our component.
// This function makes Redux know that this component needs to be passed a piece of the state
function mapStateToProps(state, props) {
  return {
    loading: state.loading,
    user: state.user,
  }
}

// Doing this merges our actions into the component’s props,
// while wrapping them in dispatch() so that they immediately dispatch an Action.
// Just by doing this, we will have access to the actions defined in out actions file (action/homeScreen.js)
function mapDispatchToProps(dispatch) {
  return bindActionCreators(UserActions, dispatch);
}

//Connect everything
export default connect(mapStateToProps, mapDispatchToProps)(LoginScreen);
“严格使用”;
从“React”导入React,{Component};
从“react native”导入{StyleSheet};
从“react native indicators”导入{SkypeIndicator};
从“redux”导入{bindActionCreators};
从“react redux”导入{connect};
从“本机基础”导入{Body、Button、Container、Content、Header、Icon、Left、Text、Title、View};
从“tcomb form native”导入t;
从“./models/UserModel”导入{LoginUserModel,LoginUserModelOption};
从“../styles”导入样式;
从“反应本机加载按钮”导入加载按钮;
从“../actions/user”导入*作为用户操作;
const Form=t.Form.Form;
const ps=StyleSheet.create({
…风格,
容器:{
为内容辩护:“中心”,
玛金托普:50,
填充:20
},
});
类LoginScreen扩展组件{
建造师(道具){
超级(道具);
}
onSubmitHandler=()=>{
常量值=此值。_form.getValue();
如果(值){
this.props.userLogin(value.username、value.password);
}
};
render(){
返回(
this.props.navigation.goBack()}>
标题
此._form=c}type={LoginUserModel}options={LoginUserModelOption}/>
立即登录
);
}
}
//该函数从应用程序当前状态获取数据,
//并将其插入/链接到我们组件的道具中。
//此函数使Redux知道需要向该组件传递一段状态
函数mapStateToProps(状态、道具){
返回{
加载:state.loading,
用户:state.user,
}
}
//这样做会将我们的行动合并到组件的道具中,
//将它们包装在dispatch()中,以便它们立即分派操作。
//只需这样做,我们就可以访问OutActions文件(action/homeScreen.js)中定义的操作
功能图DispatchToprops(调度){
返回bindActionCreators(UserActions,dispatch);
}
//连接一切
导出默认连接(MapStateTrops、mapDispatchToProps)(LoginScreen);
主屏幕应该会产生一个永久加载页面,但事实并非如此

按loginScreen按钮时应自动加载,但它没有

对于react native,我尝试设置/使用状态/道具,但似乎没有更改/连接,我还有另一个页面尝试检查状态是否已同步,但结果就像总是获得新状态一样,据我所知,状态类似于可在任何连接到redux的组件中访问的全局变量

我的问题是 1.react native/redux/redux thunk设置是否正确?如果没有,错误在哪里 2.状态/道具是否在与redux连接的任何组件中都是全局可访问的 3.如果语句2正确,状态/道具之间有什么不同?this.state和this.props 4.我真的不明白承诺的工作,我们如何处理/等待,直到api调用完成(成功/错误),然后再进入下一步/流程,我使用php很多,我的逻辑卡在每个函数应该返回一些东西,然后取决于下一个函数的处理结果…然后

感谢您的回答/花费宝贵时间阅读此问题,谢谢

创建了一个易于复制/测试的github


如果您不介意的话,可以在以下位置设置项目:?这样我们就可以自己运行,更容易帮助您在我看来,这里的代码太多了,请阅读以下内容:这不是世博会项目,我们将检查并了解如何转换为世博会项目,同时,如果您有时间/渴望尝试,我已经添加了github链接@Isaac@ivan我不确定问题是从哪里开始的,动作,减速器,或者商店,甚至是开始脚本已经做错了什么…@user259752:不必这样