React Native 0.74 is released
Hi React Native Developers, Version 0.74 has been released, stable and ready for use now, with more than 1600 commits. You can see the full changelog at React Native 0.74.1 Change Log.
The main updates in this release are:
Using Yarn 3 for new projects by default.
Bridgeless is enabled by default when using the New Architecture.
Rendering multiple updates in onLayout changes in the New Architecture.
Yoga updated to version 3.
Let's explain each main update in detail.
Yarn 3:
Yarn 3 replaces the classic Yarn (1.x) for new projects as it is deprecated. Yarn 3 provides better performance when installing and updating dependencies. It also optimizes the process of storing dependencies.
Bridgeless is enabled by default in New Architecture :
React Native is moving towards implementing a new architecture by default in future releases and is gradually taking steps to deprecate the old architecture to boost performance. In the old architecture, the bridge is the main component used to enable communication between JavaScript and native modules. Because native features like camera, Bluetooth, etc., are accessed using native code written in Kotlin, Java, Objective-C, Swift, or C++, but to enable applications to access these features in JavaScript, the bridge uses the process of serialization (Javascript object to JSON string) and deserialization (JSON string to javascript object), which causes performance issues in the app.
To counter this issue, React Native introduced the New Architecture, which relies on the JSI (JavaScript interface) written in C++. This enables all native code features to be accessible in JavaScript code without depending on serialization and deserialization, resulting in significantly improved app performance.
But right now, the old architecture is still in use and to enable new architecure (JSI) the dependencies of OLD architecture first needs to be removed and React Native Team has three steps to do that.
Turbo Modules: Introduced in React Native version 0.68 to remove the app's dependency on native calls from the bridge.
Fabric Renderer: Also introduced in V0.68 to render components without the old bridge architecture.
Bridgeless Mode: Introduced in V0.73 to remove the remaining dependencies on the old architecture, such as error handling, global event emitters, timers, and more.
As you can see, the Bridgeless Mode was introduced in V0.73, which required manual enabling. However, in V0.74, when you opt for the New Architecture in your app, the Bridgeless mode will be enabled by default.
Multiple onLayout updates in single render:
The React Native team not only depends on the new architecture but also enhances the rendering process in the old architecture. In React Native, the onLayout
prop serves to manage layout adjustments for a component. Whenever there's a change in layout because of size alterations, rotation, or mounting, the onLayout
callback activates for that component. Below is the code snippet to activate the onLayout
callback:
function CustomComponent(){
return (
<View
onLayout={() => {
console.log('Custom Component onLayout has been invoked')
}}
/>
)
}
Now let's see how onLayout with complete code example:
function CustomComponent() {
const [firstState, setFirstState] = useState(false)
const [secondState, setSecondState] = useState(false)
const [thirdState, setThirdState] = useState(false)
console.log('COMPONENT RE-RENDERED .....')
return (
<View>
<View
onLayout={() => {
console.log('FIRST View onLayout invoked')
setFirstState(true) // Update first state on view mount
}}>
</View>
<View
onLayout={() => {
console.log('SECOND View onLayout invoked')
setSecondState(true) // Update second state on view mount
}}>
</View>
<View
onLayout={() => {
console.log('THIRD View onLayout invoked')
setThirdState(true) // Update third state on view mount
}}>
</View>
</View>
)
}
In React Native V0.73, the component above will be rendered in the following sequence:
FIRST View onLayout invoked
COMPONENT RE-RENDERED .....
SECOND View onLayout invoked
COMPONENT RE-RENDERED .....
THIRD View onLayout invoked
COMPONENT RE-RENDERED .....
Notice that when the onLayout
is triggered for a view, we experience the re-rendering of the entire view. This approach can potentially impact performance, especially if you have logic that triggers numerous onLayout
callbacks.
Now, let's execute the same code in the latest V0.74, and here's the output:
FIRST View onLayout invoked
SECOND View onLayout invoked
THIRD View onLayout invoked
COMPONENT RE-RENDERED .....
You can observe that the component is now re-rendered only once, and multiple onLayout
callbacks are handled in a single render, improving performance.
What's new in Yoga 3.0:
Yoga 3 introduced some new properties such as:
'space-evenly'
property foralignContent
style'static'
property forposition
style
In previous versions of React Native, there were some UI and rendering issues, including incorrect behavior with the 'row-reverse' style. However, in version 0.74 of React Native, using flexDirection: 'row-reverse'
now functions as expected.
The other key updates in this version are:
The minimum Android SDK requirement has been increased to version 23 (Android 6.0) to enhance compatibility and performance.
Deprecated PropTypes have been removed, reducing app size and memory overhead.
There have been API changes to PushNotificationIOS, as it prepares for relocation to a community package.
Additionally, various other breaking changes and enhancements have been implemented across platforms.
That's it, Please feel free to like, comment and share if you found this post helpful :)
Subscribe to my newsletter
Read articles from Muhammad Hassaan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Muhammad Hassaan
Muhammad Hassaan
Results-driven and highly skilled software engineer with over 5 years of experience in mobile applications development, specializing in React Native, Android Native, Flutter, and iOS Native. Proficient in a variety of programming languages including Kotlin, TypeScript, JavaScript, React, Java, PHP, and Python. Holds an MSC in Applied Artificial Intelligence and Data Analytics from the University of Bradford, UK, demonstrating a strong foundation in data science. Currently contributing as a Mobile Applications Developer at Prevayl in Manchester, UK for the past 2 years, with a proven track record of delivering high-quality software solutions. Possesses a versatile skill set encompassing web development using React and NodeJs. Equipped with the expertise to transition into a role as a Data Scientist, leveraging the academic background and practical experience to analyze and derive insights from data. Known for adaptability, problem-solving prowess, and a commitment to staying abreast of emerging technologies. Adept at collaborating with cross-functional teams to drive successful project outcomes. Passionate about pushing the boundaries of technology to create innovative and impactful solutions. Can show around 300 Github Pull Requests to showcase practical work