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>
);
}
}
如果你想访问其他组件或页面中的数据,你应该使用redux存储。您可以将在当前页面中获取或生成的数据存储到 redux 存储中,任何需要它的组件或页面都可以访问该存储。
您可以尝试将参数传递给这样的路由
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>
);
}
}
- 它已经解决了,感谢您的帮助:))顺便说一句,我只是将此数组数据传递到导航器:)
结果 = [对象]
this.props.navigation.navigate('Profile', { result: result.user });
- 然后在其他页面中,让我们说个人资料,我为新状态制作了
this.state = { result: this.props.navigation.state.params.result, };
- 然后我在每个部分中都像这样称呼该状态
{ this.state.result.email }