首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NavigationService减缓反应-本地生产

NavigationService减缓反应-本地生产
EN

Stack Overflow用户
提问于 2019-05-16 11:56:03
回答 1查看 44关注 0票数 0

我已经实现了反应导航提供的NavigationService,这使得生产应用程序加载x10的速度慢了一倍。

我用它做了一次,而没有它。

它的启动以15+秒为单位,另一个以1-2秒开始。

还有其他人遇到过这种问题吗?

下面是我在导航器和导航服务中使用的代码:

RootNavigator.js:

代码语言:javascript
复制
import React, { Component } from "react";
import {
  createStackNavigator,
  HeaderBackButton,
  createAppContainer
} from "react-navigation";

import { colors } from "assets/styles/colors";

import RegistrationInputScreen from "components/Registration/Input";
import RegistrationVerificationScreen from "components/Registration/Verification";
import MainScreen from "screens/MainScreen";
import Conversation from "components/Messages/Conversation";
import Private from "components/FirstTime/Private";
import Description from "components/FirstTime/Description";
import CategoriesScreen from "components/FirstTime/CategoriesScreen";
import Professional from "components/FirstTime/Professional";
import Home from "components/Home";
import SecretScreen from "screens/SecretScreen";
import Map from "components/Map/Map";
import ProfileScreen from "components/Profile/Profile";
import EditProfile from "components/Profile/EditProfile";
import PublicProfile from "components/Profile/PublicProfile";
import Settings from "components/Profile/Settings";
import RegisteredScreen from "components/Partials/Registered";
import NavigationService from "navigation/NavigationService";

export default class RootNavigator extends Component {
  constructor(props) {
    super(props);
  }

  componentWillMount() {
    console.log("PROPS", this.props);
  }

  render() {
    let sp = this.props.screenProps;
    return (
      <Navigator
        // ref={navigatorRef => {
        //   NavigationService.setTopLevelNavigator(navigatorRef);
        // }}
        screenProps={{
          getDeviceToken: sp.getDeviceToken
        }}
      />
    );
  }
}

export const RootNav = createStackNavigator({
  RegistrationOptions: {
    screen: Home,
    navigationOptions: {
      header: null
    }
  },
  RegistrationInput: {
    screen: RegistrationInputScreen,
    navigationOptions: config => setHeader(null, config)
  },
  RegistrationVerification: {
    screen: RegistrationVerificationScreen,
    navigationOptions: config => setHeader("Registration Verification", config)
  },
  Map: {
    screen: Map,
    navigationOptions: {
      header: null
    }
  },
  MainScreen: MainScreen,
  Registered: {
    screen: RegisteredScreen,
    navigationOptions: {
      header: null
    }
  },
  Private: {
    screen: Private,
    navigationOptions: config => setHeader("Introduce yourself", config)
  },
  Interests: {
    screen: CategoriesScreen,
    navigationOptions: config => setHeader("Back", config)
  },
  Description: {
    screen: Description,
    navigationOptions: config => setHeader("Describe yourself", config)
  },
  Professional: {
    screen: Professional,
    navigationOptions: config => setHeader("Professional", config)
  },
  Conversation: {
    screen: Conversation,
    navigationOptions: config => setHeader(null, config)
  },
  Secret: {
    screen: SecretScreen,
    navigationOptions: config => setHeader("Configure app", config)
  },
  Profile: {
    screen: ProfileScreen,
    navigationOptions: config => setHeader("Profile", config)
  },
  Public: {
    screen: PublicProfile,
    navigationOptions: config => setHeader("Profile", config)
  },
  EditProfile: {
    screen: EditProfile,
    navigationOptions: config => setHeader("Edit profile", config)
  },
  Settings: {
    screen: Settings,
    navigationOptions: config => setHeader("Settings", config)
  }
});

export const Navigator = createAppContainer(RootNav);

const setHeader = (title = null, config) => {
  let options = {
    title: title,
    headerStyle: {
      backgroundColor: colors.bgRed,
      shadowOpacity: 0,
      shadowOffset: {
        height: 0
      },
      shadowRadius: 0,
      elevation: 0
    },
    headerTitleStyle: { color: colors.white },
    headerTransitionPreset: { headerMode: "screen" },
    cardShadowEnabled: false,
    headerLeft: (
      <HeaderBackButton
        tintColor={colors.white}
        onPress={() => config.navigation.dispatch({ type: "Navigation/BACK" })}
      />
    ),
    ...config.navigationOptions
  };

  if (title === null) delete options.title;

  return options;
};

NavigationService.js:

代码语言:javascript
复制
import { NavigationActions } from 'react-navigation';

let _navigator;

const setTopLevelNavigator = (navigatorRef) => {
    console.log("WILL SET TOP LEVEL NAVIGATOR WITH", navigatorRef);
    _navigator = navigatorRef;
}

const navigate = (routeName, params) => {
    _navigator.dispatch(
        NavigationActions.navigate({
            routeName,
            params
        })
    )
}

export default{
    navigate,
    setTopLevelNavigator
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-16 12:45:14

为了防止其他人为此而挣扎,我通过删除setTopLevelNavigator中的setTopLevelNavigator来解决这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56167993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档