Guest User

Untitled

a guest
May 5th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. //@flow
  2. import * as React from "react";
  3. import { BackHandler } from "react-native";
  4. import { connect } from "react-redux";
  5. import Login from "../components/Login";
  6. import LoginActions from "../store/actions/LoginActions";
  7. type Props = {
  8. login: Function
  9. };
  10.  
  11. export class LoginScreen extends React.Component<Props> {
  12. props: Props;
  13. handleLogin: Function;
  14. backButtonSubscription: { remove: Function };
  15.  
  16. constructor(props: Props) {
  17. super(props);
  18. this.handleLogin = this.handleLogin.bind(this);
  19. }
  20.  
  21. componentDidMount() {
  22. this.backButtonSubscription = BackHandler.addEventListener(
  23. "hardwareBackPress",
  24. () => { return true; }
  25. );
  26. }
  27.  
  28. componentWillUnmount() {
  29. this.backButtonSubscription.remove();
  30. }
  31.  
  32. handleLogin(userName: string, password: string) {
  33. this.props.login(userName, password);
  34. }
  35.  
  36. render() {
  37. return <Login handleLogin={this.handlelogin} />;
  38. }
  39. }
  40. const mapStateToProps = (state) => {
  41. return {
  42. errorMessage: state.login.errorMessage
  43. };
  44. };
  45. const mapDispatchToProps = dispatch => {
  46. return {
  47. login: (userName, password) => {
  48. dispatch(LoginActions.login(userName, password));
  49. }
  50. };
  51. };
  52.  
  53. export default connect(mapStateToProps, mapDispatchToProps)(LoginScreen);
Add Comment
Please, Sign In to add comment