import React from 'react';
import { View, Text, Button, Alert } from 'react-native';
import Expo from 'expo';
export default class LoginScreen extends React.Component{
async signInWithGoogleAsync() {
try {
const result = await Expo.Google.logInAsync({
androidClientId: '768673945897-ftrhehlg3io4v2fohdbpacio1vghos8v.apps.googleusercontent.com',
//iosClientId: YOUR_CLIENT_ID_HERE,
scopes: ['profile', 'email'],
});
if (result.type === 'success') {
console.log(result);
//this.props.navigation.navigate('Profile');
return result.accessToken;
return result.user.name;
return result.user.photoUrl;
} else {
return {cancelled: true};
}
} catch(e) {
return {error: true};
}
}
render() {
return(
<View>
<Button
onPress={this.signInWithGoogleAsync.bind(this)}
title='Google Sign in'
/>
</View>
);
}
}
答案 0 :(得分:0)
好吧,如果您想访问某些其他组件或页面中的数据,则应使用redux存储。您可以将在当前页面中获得或生成的数据存储到redux存储中,任何需要它的组件或页面都可以访问它。
答案 1 :(得分:0)
您可以尝试像这样传递parameters to routes
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
<Button
title="Go to Details"
onPress={() => {
/* 1. Navigate to the Details route with params */
this.props.navigation.navigate('Details', {
itemId: 86,
otherParam: 'anything you want here',
});
}}
/>
</View>
);
}
}
并像这样检索数据...
class DetailsScreen extends React.Component {
render() {
/* 2. Get the param, provide a fallback value if not available */
const { navigation } = this.props;
const itemId = navigation.getParam('itemId', 'NO-ID');
const otherParam = navigation.getParam('otherParam', 'some default value');
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
<Text>itemId: {JSON.stringify(itemId)}</Text>
<Text>otherParam: {JSON.stringify(otherParam)}</Text>
<Button
title="Go to Details... again"
onPress={() =>
this.props.navigation.push('Details', {
itemId: Math.floor(Math.random() * 100),
})}
/>
<Button
title="Go to Home"
onPress={() => this.props.navigation.navigate('Home')}
/>
<Button
title="Go back"
onPress={() => this.props.navigation.goBack()}
/>
</View>
);
}
}
答案 2 :(得分:0)
结果= [对象]
this.props.navigation.navigate('Profile',{result:result.user});
this.state = { 结果:this.props.navigation.state.params.result,};
{this.state.result.email}