最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React navigation 5 really slow and dropping JS FPS on Expo - Stack Overflow

programmeradmin2浏览0评论

I am currently working on a React Native (Expo) App and I am facing some performance issues. I have not found any answer yet for my problem so I hope someone can help me.

My problem is that whenever I launch the app on my physical device (Galaxy S9+) and navigate to different screens, I notice JS frames dropping from 60 all the way to like 10-30. I have a main drawer navigator, a bottom tab navigator and some stack navigators. I have basic View, Text, ... ponent so I don't think it is due to heavy ponents.(I am using react-navigation v5)

I also have to mention that I don't really see any lack of performance or JS FPS drops on an iOS simulator.

I am currently working on a React Native (Expo) App and I am facing some performance issues. I have not found any answer yet for my problem so I hope someone can help me.

My problem is that whenever I launch the app on my physical device (Galaxy S9+) and navigate to different screens, I notice JS frames dropping from 60 all the way to like 10-30. I have a main drawer navigator, a bottom tab navigator and some stack navigators. I have basic View, Text, ... ponent so I don't think it is due to heavy ponents.(I am using react-navigation v5)

I also have to mention that I don't really see any lack of performance or JS FPS drops on an iOS simulator.

Share Improve this question edited Dec 20, 2020 at 21:09 blouuuu asked Dec 20, 2020 at 20:47 blouuuublouuuu 5441 gold badge7 silver badges18 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 15

Android devices are a lot more sensitive to unoptimized JavaScript code because they typically have far worse JS performance when pared to iOS devices, so you have less headroom to write inefficient code. The same code running on iOS can feel smooth and on Android it can end up frequently dropping frames.

It's remended to use React Devtools to understand the source of slow rendering performance in React apps, and I think this is a fine option here and something you certainly should do.

Another thing you can do is switch to createNativeStackNavigator wherever you are using createStackNavigator, and that will help push some of your performance concerns a little bit down the road. You can also learn more about this navigator in this YouTube video.

I'd personally do both of the above right now: 1) profile your React rendering performance and find where you're doing unnecessary / extra work, eliminate that. 2) switch to using createNativeStackNavigator.

Create your own animation

This animation will make your app more fast

 const App = () => {   
   const Stack = createStackNavigator();

   const TransitionScreen = {
    gestureDirection: 'horizontal',
    transitionSpec: {
      open: TransitionSpecs.TransitionIOSSpec,
      close: TransitionSpecs.TransitionIOSSpec,
    },
    cardStyleInterpolator: ({current, next, layouts}) => {
      return {
        cardStyle: {
          transform: [
            {
              translateX: current.progress.interpolate({
                inputRange: [0, 1],
                outputRange: [layouts.screen.width, 0],
              }),
            },
            {
              translateX: next
                ? next.progress.interpolate({
                    inputRange: [0, 1],
                    outputRange: [0, -layouts.screen.width],
                  })
                : 1,
            },
          ],
        },
        overlayStyle: {
          opacity: current.progress.interpolate({
            inputRange: [0, 1],
            outputRange: [0, 0.5],
          }),
        },
      };
    },
 

     };
    
      const CardOptions = {
        cardStyle: {backgroundColor: 'transparent'},
        ...TransitionScreen,
        headerShown: false,
        gestureEnabled: false,
      };

 return (
    <NavigationContainer theme={DarkTheme}>
      <Stack.Navigator>
        <Stack.Screen
          name="preloader"
          ponent={PreLoader}
          options={CardOptions}
        />
      </Stack.Navigator>
    </NavigationContainer>  
 );
 };
    
    export default App;
发布评论

评论列表(0)

  1. 暂无评论