简体   繁体   English

React-Navigation 性能:多少屏幕太多了?

[英]React-Navigation performance: How many screens are too many?

I am new to both Recact Native and React-Navigation. The app I am planning is super content heavy.我是 React Native 和 React-Navigation 的新手。我正在计划的应用程序内容非常丰富。 It will have several hundred unqique screens.它将有数百个独特的屏幕。 I want to connect them via React-Navigation so my stack is going to be quiet large.我想通过 React-Navigation 连接它们,这样我的堆栈就会非常大。 Is there an issue with that performance wise or anything I should keep in mind?该性能是否有问题或我应该记住什么? My guess is that a screen is only loaded when the user is accessing it for the first time, so the initial loading time of the app should not be affected?我的猜测是只有当用户第一次访问时才会加载屏幕,所以应用程序的初始加载时间应该不会受到影响?

Thanks!谢谢!

Actually it doesn't matter how may js files are you creating but it matters when you are:实际上,创建 js 文件的数量并不重要,但在以下情况下很重要:

  1. Not Reusing your code.不重用您的代码。 For example you create a 3 Screens which uses a Card so it didn't create a card component js file separately then the complexity is increasing but if you create a JS file for Card and reuse it in 3 screens it optimised this.例如,您创建了一个使用 Card 的 3 Screens,因此它没有单独创建一个 card 组件 js 文件,那么复杂性会增加,但是如果您为 Card 创建一个 JS 文件并在 3 个屏幕中重复使用它,它会对此进行优化。 So if you this this component will be reusable then create separate file for it.所以如果你这个组件将是可重用的,那么为它创建单独的文件。
  2. Using Dimension too much.过度使用维度。 I know when using dimensions the Screen design is responsive but at abstract level it calculate height, width every time for every screen so it is not an optimized way.我知道在使用尺寸时,屏幕设计是响应式的,但在抽象级别上,它每次都会为每个屏幕计算高度和宽度,因此这不是一种优化方式。 So try to use flex and also try to reduce usage of Dimension.所以尽量使用flex ,也尽量减少Dimension的使用。 But if you use Dimension wisely it is very powerful tool.但如果您明智地使用 Dimension,它是非常强大的工具。

3)Try to use FastImage instead of image when you want to show images using FlatList, Map etc. In short if images in a single screen is render more than twice. 3)FlatList、Map等图片展示时,尽量使用FastImage代替image

  1. You can get more info here: Optimization in React-Native您可以在此处获得更多信息: React-Native 中的优化

Note: At Last i want to say that you can create as much as JS files but it must be reusable, not unnecessary and no repeated code there.注意:最后我想说的是,你可以创建尽可能多的 JS 文件,但它必须是可重用的,不是不必要的,也没有重复的代码。

You can also consider this as a performance improvement.您也可以将此视为性能改进。

You have a screen.你有一个屏幕。 When you push or navigate a new screen on it.当您在其上按下或导航新屏幕时。 You can stop the animations in the background screen.您可以停止背景屏幕中的动画。 Because the screen in the back continues to work.因为后面的屏幕继续工作。 So you can stop animating the background screen.所以你可以停止动画背景屏幕。

For example, you have a slider component in the home screen and.例如,您在主屏幕和中有一个 slider 组件。 This slider autoplay feature is active.此 slider 自动播放功能处于活动状态。 When you change the home screen you can stop the autoplay feature.当您更改主屏幕时,您可以停止自动播放功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM