Android 加载屏幕完成后移动到另一屏幕

Android 加载屏幕完成后移动到另一屏幕,android,react-native,react-native-cli,Android,React Native,React Native Cli,在我的react原生应用程序中,主屏幕上有一个按钮,用于打开指南针,显示特定位置的方向。为此,我需要将用户的坐标传递到compass屏幕以进行计算,m在navigator中传递值 我在主屏幕的componentDidMount()方法上加载坐标,我的问题是获取用户的坐标有时需要一些时间(取决于用户的gps信号强度和他/她的设备),因此我使用条件渲染来显示“加载”组件,如果用户在加载坐标前按下指南针按钮。但问题是,我不知道在装载机之后如何将他/她发送到指南针屏幕,因为装载机之后,他/她现在停留在主

在我的react原生应用程序中,主屏幕上有一个按钮,用于打开指南针,显示特定位置的方向。为此,我需要将用户的坐标传递到compass屏幕以进行计算,m在navigator中传递值

我在主屏幕的componentDidMount()方法上加载坐标,我的问题是获取用户的坐标有时需要一些时间(取决于用户的gps信号强度和他/她的设备),因此我使用条件渲染来显示“加载”组件,如果用户在加载坐标前按下指南针按钮。但问题是,我不知道在装载机之后如何将他/她发送到指南针屏幕,因为装载机之后,他/她现在停留在主屏幕上,必须再次按下按钮才能转到指南针

  state = {
    currentLongitude: "unknown",
    currentLatitude: "unknown",
    locationLoading: false,
  };

getCards = () => [...
{id: "3",
      card: this.languageCard("Compass"),
      onPress: () => {
        this.state.currentLatitude != "unknown"
          ? this.props.navigation.navigate("Compass", {
              latitude: this.state.currentLatitude,
              longitude: this.state.currentLongitude,
            })
          : this.setState({ locationLoading: true });
                      },
  }...]

  componentDidMount() {
        this.requestLocation();
  }

requestLocation() {
    var that = this;
    if (Platform.OS === "ios") {
      this.callLocation(that);
    } else {
      async function requestLocationPermission() {
        try {
          const granted = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
            {
              title: "Location Access Required",
              message: "This App needs to Access your location",
            }
          );
          if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            that.callLocation(that);
          } else {
            alert("Permission Denied");
          }
        } catch (err) {
          alert("err", err);
          console.warn(err);
        }
      }
      requestLocationPermission();
    }
  }

  callLocation(that) {
    Geolocation.getCurrentPosition(
      (position) => {
        const currentLongitude = JSON.stringify(position.coords.longitude);
        const currentLatitude = JSON.stringify(position.coords.latitude);
        that.setState({ currentLongitude: currentLongitude });
        that.setState({ currentLatitude: currentLatitude });
        this.setState({ locationLoading: false });
      },
      (error) => alert(error.message),
      { enableHighAccuracy: false, timeout: 20000, maximumAge: 1000 }
    );
  }

render() {
    return this.state.locationLoading ? (
      <Loader />
    ) : (
      <SafeAreaView>
....
</SafeAreaView>
状态={
当前经度:“未知”,
当前纬度:“未知”,
位置加载:错误,
};
getCards=()=>[。。。
{id:“3”,
卡片:这张语言卡片(“指南针”),
onPress:()=>{
this.state.currentLatitude!=“未知”
?这个.道具.导航.导航(“指南针”{
纬度:this.state.currentLatitude,
经度:this.state.currentLength,
})
:this.setState({locationLoading:true});
},
}...]
componentDidMount(){
this.requestLocation();
}
请求位置(){
var=这个;
如果(Platform.OS==“ios”){
这个.呼叫位置(那个);
}否则{
异步函数requestLocationPermission(){
试一试{
授予的常数=等待许可和ROID.request(
PERMISSIONS和roid.PERMISSIONS.ACCESS\u FINE\u位置,
{
标题:“需要位置访问”,
消息:“此应用需要访问您的位置”,
}
);
如果(已授予===权限sandroid.RESULTS.已授予){
那.那(那),;
}否则{
警报(“权限被拒绝”);
}
}捕捉(错误){
警惕(“错误”,错误);
控制台。警告(错误);
}
}
requestLocationPermission();
}
}
呼叫位置(即){
Geolocation.getCurrentPosition(
(职位)=>{
const currentLength=JSON.stringify(position.coords.longitude);
const currentLatitude=JSON.stringify(position.coords.latitude);
setState({currentLength:currentLength});
setState({currentLatitude:currentLatitude});
this.setState({locationLoading:false});
},
(错误)=>警报(错误消息),
{enableHighAccurance:false,超时:20000,最大值:1000}
);
}
render(){
是否返回此.state.locationLoading(
) : (
....

请张贴相关代码块。这是所有用于此功能的代码。当按指南针按钮时,您可以显示调用的代码吗?此代码是getCards功能中的On Press