Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action.[SCENE_KEY] not working #2444

Closed
jbrod22 opened this issue Sep 28, 2017 · 2 comments
Closed

Action.[SCENE_KEY] not working #2444

jbrod22 opened this issue Sep 28, 2017 · 2 comments

Comments

@jbrod22
Copy link

jbrod22 commented Sep 28, 2017

Version

Tell us which versions you are using:

  • react-native-router-flux v4
  • react-native v0.47

Expected behaviour

All I'm trying to do is navigate from one container to another. I'm using Redux-Thunk.

Actual behaviour

NavigationRouter recognizes my other scenes as functions they return undefined, scene does not change.

Code

EDIT: Glad to see mds code snippet is working

Router
import React, { Component } from 'react'
import { Scene, Router } from 'react-native-router-flux'
import Styles from './Styles/NavigationContainerStyles'
import NavigationDrawer from './NavigationDrawer'

import LaunchScreen from '../Containers/LaunchScreen'
import Login from '../Containers/LoginScreen'
import SettingsScreen from '../Containers/SettingsScreen'

class NavigationRouter extends Component {
render () {
return (







)
}
}

export default NavigationRouter
LoginScreenimport React, { PropTypes } from 'react'
import {
View,
ScrollView,
Text,
TextInput,
TouchableOpacity,
Image,
Keyboard,
LayoutAnimation
} from 'react-native'
import { connect } from 'react-redux'
import Styles from './Styles/LoginScreenStyles'
import {Images, Metrics} from '../Themes'
import { Actions as NavigationActions } from 'react-native-router-flux'
import { Button, Text as NBText, Contant, Form, Item, Input, Label } from 'native-base'
import { loginUser } from '../Reducers/LoginActions'
import settingsScreen from './SettingsScreen'

class LoginScreen extends React.Component {

  static propTypes = {
    dispatch: PropTypes.func,
    fetching: PropTypes.bool,
    attemptLogin: PropTypes.func
  }

  isAttempting = false
  keyboardDidShowListener = {}
  keyboardDidHideListener = {}

  constructor (props) {
    super(props)
    this.state = {
      username: 'admin',
      password: 'admin',
      visibleHeight: Metrics.screenHeight,
      topLogo: { width: Metrics.screenWidth-40 }
    }
    this.isAttempting = false      
  }
  componentWillReceiveProps (newProps) {
    console.log('this')
    // console.log(NavigationActions.state)
    console.log(NavigationActions.settingsScreen(PARAMS))
    this.forceUpdate()
    // Did the login attempt complete?
    if (this.isAttempting && newProps.user.id) {
      if(!newProps.user.accountSetup){
        NavigationActions.settingsScreen()
      }else{
        NavigationActions.launchScreen();
      }
    }
  }

  componentWillMount () {
    // Using keyboardWillShow/Hide looks 1,000 times better, but doesn't work on Android
    // TODO: Revisit this if Android begins to support - https://github.com/facebook/react-native/issues/3468
    this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this.keyboardDidShow)
    this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this.keyboardDidHide)
  }

  componentWillUnmount () {
    this.keyboardDidShowListener.remove()
    this.keyboardDidHideListener.remove()
  }

  keyboardDidShow = (e) => {
    // Animation types easeInEaseOut/linear/spring
    LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
    let newSize = Metrics.screenHeight - e.endCoordinates.height
    this.setState({
      visibleHeight: newSize,
      topLogo: {width: 100, height: 70}
    })
  }
  keyboardDidHide = (e) => {
    // Animation types easeInEaseOut/linear/spring
    LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
    this.setState({
      visibleHeight: Metrics.screenHeight,
      topLogo: {width: Metrics.screenWidth-40}
    })
  }

  handlePressLogin = () => {
    this.isAttempting = true;
    const {username, password} = this.state;
    this.props.attemptLogin(username, password)
  }

  handlePressSignup = () => {
    
  }

  handleChangeUsername = (text) => {
    this.setState({ username: text })
  }

  handleChangePassword = (text) => {
    this.setState({ password: text })
  }

  render () {
    const { username, password } = this.state
    const { fetching } = this.props
    const editable = !fetching
    const textInputStyle = editable ? Styles.textInput : Styles.textInputReadonly

    return (
      <ScrollView contentContainerStyle={{justifyContent: 'center'}} style={[Styles.container, {height: this.state.visibleHeight}]} keyboardShouldPersistTaps='always'>
        <Image source={Images.logo} style={[Styles.topLogo, this.state.topLogo]} />
        <View style={Styles.form}>
        <Form>
          <Item stackedLabel>
            <Label>VTCARES ID</Label>
            <Input
               ref='username'
               value={username}
               editable={editable}
               keyboardType='default'
               returnKeyType='next'
               autoCapitalize='none'
               autoCorrect={false}
               onChangeText={this.handleChangeUsername}
               underlineColorAndroid='transparent'
               onSubmitEditing={()=> this.password._root.focus()}
               />
          </Item>
           <Item stackedLabel>
            <Label>Password</Label>
            <Input
               ref='password'
               value={password}
               editable={editable}
               keyboardType='default'
               returnKeyType='next'
               autoCapitalize='none'
               autoCorrect={false}
               onChangeText={this.handleChangePassword}
               underlineColorAndroid='transparent'
               onSubmitEditing={()=> this.password._root.focus()}
               />
          </Item>
        </Form>
          <View style={[Styles.loginRow]}>
            <Button style={{flex: 1, justifyContent: 'center'}} full onPress={this.handlePressLogin}>
              <NBText>
                Log In
              </NBText>
            </Button>
            <Button style={{flex: 1, justifyContent: 'center'}} full onPress={this.handlePressSignup}>
              <NBText>
                Sign Up
              </NBText>
            </Button>
          </View>
        </View> 
      </ScrollView>
    )
  }

}

const mapStateToProps = (state) => {
  return {
    user: state.login
  }
}

const mapDispatchToProps = (dispatch) => {
  return {
    attemptLogin: (username, password) => dispatch(loginUser(username, password))
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(LoginScreen)
`
@mcabs3
Copy link
Collaborator

mcabs3 commented Sep 29, 2017

I don't see anything in your Navigation Router. what is your application router setup?

@jbrod22
Copy link
Author

jbrod22 commented Sep 30, 2017 via email

@jbrod22 jbrod22 closed this as completed Sep 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants