- Debug React Native project
- Safe area
- ComponentProps and StyleProps
- Open Xcode project
- shortcuts
- React native performance
- Running in development mode (dev=true)
- Using
console.logstatements ListViewinitial rendering is too slow or scroll performance is bad for large lists- Dropping JS thread FPS because of doing a lot of work on the JavaScript thread at the same time
- Moving a view on the screen (scrolling, translating, rotating) drops UI thread FPS
- Animating the size of an image drops UI thread FPS
- My TouchableX view isn't very responsive
- Slow navigator transitions
- Box Shadow and Filter style props
- type style props in React Native
childrenProps in default project with React 19- How to make Expo apps faster
https://www.youtube.com/watch?v=7wzqN2G8dfU
- enable
remote deubgon app simulator or device https://youtu.be/7wzqN2G8dfU?t=11. By default, an Chrome debug console will launch on19001port. - change React Native Tools port setting into
19001in VS Code setting. The default port, 8081, doesn't work. - create
launch.jsonwithattach packageroption - as start to debug, the debug console reports
there is another packager is running. Terminating the Chrome debug console to resolve this issue. - relaod app to make the debug work. If the packager disconnected, the app need to reload again.
import {SafeAreaView} from'react-native';
<SafeAreaView style={styles.container}></SafeAreaView>
const styles = StyleSheet.create({
container: {
paddingTop: Platform.OS === "android" ? StatusBar.currentHeight : 0,
},
});interface ObscuraButtonProps {
iconName?: ComponentProps<typeof Ionicons> ["name"];
containerStyle?: StyleProp<ViewStyle>;
}open obscuraclone.xcworkspaceiOS
fn + Dto toggle devtoolsfn + Rto reload
https://reactnative.dev/docs/performance
- JS frame - JavaScript thread
- UI frame - main thread
Common sources of performance problems
A lot more work needs to be done at runtime to provide you with good warnings and error messages, such as validating propTypes and various other assertions.
You can also use this babel plugin that removes all the console.* calls.
{
"env": {
"production": {
"plugins": ["transform-remove-console"]
}
}
}Use the new FlatList or SectionList component instead.
If your FlatList is rendering slow, be sure that you've implemented getItemLayout to optimize rendering speed by skipping measurement of the rendered items.
- set
useNativeDriver: true - use
LayoutAnimation
Enabling shouldRasterizeIOS or renderToHardwareTextureAndroid can help.
Be careful not to overuse this or your memory usage could go through the roof. Profile your performance and memory usage when using these props.
Use the transform: [{scale}] style property to animate the size.
Wrap any action inside of your onPress handler in requestAnimationFrame:
handleOnPress() {
requestAnimationFrame(() => {
this.doExpensiveAction();
});
}Use React Navigation library. The views in React Navigation use native components and the Animated library to deliver 60 FPS animations that are run on the native thread.
import {
StyleProp,
TextStyle,
ViewStyle,
} from 'react-native';
interface PrimaryButtonProps {
buttonStyle?: StyleProp<ViewStyle>;
labelStyle?: StyleProp<TextStyle>;
}This is the way how React Native default project define children props.
import type {PropsWithChildren} from 'react';
type SectionProps = PropsWithChildren<{
title: string;
}>;https://www.youtube.com/watch?v=vFbim_U1Lmc&t
- enable
React Compilerin Project - https://www.npmjs.com/package/react-compiler-healthcheck
- https://github.com/blazejkustra/react-compiler-marker
- worklet in React Native ✨ https://www.npmjs.com/package/react-native-worklets, and its Document