-1
export default class Tela1 extends React.Component {
  constructor ( props){
    super  ( props);

    this.state = {
      username : '',
      passaword :  ' ',
    }
  } 

  ComponentDidMount  (){
    this._loadInitialState().done();
  }

  _loadInitialState =  async () =>  {
    var value = await AsyncStorage.getItem ('user');
    if(value !== null){
      const Nome =   this.username;
      this.props.navigation.navigate('Tela2' , Nome);
    }
  }

Tela login

TELA 2

render() {
  const params = this.props.navigation.state.params;
  return (
    <ImageBackground source={require('./foto/i1.jpg')} style = {{ width : '100%',height : '100%', flex : 1}} >
    <View style={styles.container}>
    <Header style = {{ backgroundColor : '#ffcc00'}}>
      <Left>
        <Button transparent>
        </Button>
      </Left>

      <Body>
        <Title style  = {{ color : 'black'}}>Top Fit </Title>
      </Body>
      <Right>

      </Right>
    </Header>

    <View style={{flex: 1, justifyContent: 'center',alignItems: 'center'}}>
      <TouchableHighlight onPress={() => this.props.navigation.navigate('Tela3',
        {
          texto: "Weverton é um bobão", uri: "https://media.giphy.com/media/mMC2BVxQWd6Ql3oOyI/giphy.gif"
          ,texto2: "LALALALLALAA"
        })}>
        <View style={styles.button}>
          <Text style={styles.buttonText}>Exercicios</Text>
        </View>
      </TouchableHighlight>
      <TouchableOpacity onPress={() => this.props.navigation.navigate('Exercicios')}>
        <View style={styles.button}>
          <Text style={styles.buttonText}>Treino</Text>
        </View>
      </TouchableOpacity>
      <TouchableNativeFeedback
        onPress={() => this.props.navigation.navigate('Meus_dados' ) }>
        <View style={styles.button}>
          <Text style={styles.buttonText} > {params}  </Text>
        </View>
      </TouchableNativeFeedback>
    </View>

1 Resposta 1

0

Boa! Pelo que entendi quer passar o conteúdo da variável Nome para o componente Tela2, correto? Para passar usando o react-navigation é só fazer :

 this.props.navigation.navigate('Tela2' , {Nome});

Em Tela2 você irá recuperar da seguinte forma :

const Nome = navigation.getParam('Nome');

Se você ler : https://reactnavigation.org/docs/en/params.html verá que eles aconselham a usar o getParam para pegar os parâmetros e não a forma direta this.props.navigation.state.params

Agora, se o problema for somente o valor que está sendo passado, pelo código que colocou, você está jogando o valor do AsyncStorage na variável value e se ela não for nula, pegando o valor de this.username ( o correto seria usar this.state.username) e no código não há indicação de onde você está setando o estado de username.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .