### Image onLoadStart Example Source: https://github.com/react/react-native-website/blob/main/docs/image.md Invoked on load start. This example demonstrates setting a loading state when the image begins to load. ```javascript onLoadStart={() => this.setState({loading: true})} ``` -------------------------------- ### Install and Create a New React Native Project Source: https://github.com/react/react-native-website/blob/main/website/blog/2017-03-13-introducing-create-react-native-app.md Install the create-react-native-app package globally, create a new project, navigate into the project directory, and start the development server. ```sh $ npm i -g create-react-native-app $ create-react-native-app my-project $ cd my-project $ npm start ``` -------------------------------- ### Install Specific NetInfo Version Source: https://github.com/react/react-native-website/blob/main/docs/libraries.md Example of installing a specific version of the @react-native-community/netinfo library. ```bash npm install @react-native-community/netinfo@^2.0.0 ``` -------------------------------- ### Full Example with All Properties Source: https://github.com/react/react-native-website/blob/main/docs/usewindowdimensions.md This example demonstrates how to use useWindowDimensions to display height, width, font scale, and pixel ratio. It automatically updates when these values change. ```tsx import {StyleSheet, Text, useWindowDimensions} from 'react-native'; import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context'; const App = () => { const {height, width, scale, fontScale} = useWindowDimensions(); return ( Window Dimension Data Height: {height} Width: {width} Font scale: {fontScale} Pixel ratio: {scale} ); }; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, header: { fontSize: 20, marginBottom: 12, }, }); export default App; ``` -------------------------------- ### diffClamp() Source: https://github.com/react/react-native-website/blob/main/docs/animated.md Creates a new Animated value that is limited between 2 values. It uses the difference between the last value so even if the value is far from the bounds it will start changing when the value starts getting closer again. (`value = clamp(value + diff, min, max)`). This is useful with scroll events, for example, to show the navbar when scrolling up and to hide it when scrolling down. ```APIDOC ## `diffClamp()` ### Description Create a new Animated value that is limited between 2 values. It uses the difference between the last value so even if the value is far from the bounds it will start changing when the value starts getting closer again. (`value = clamp(value + diff, min, max)`). This is useful with scroll events, for example, to show the navbar when scrolling up and to hide it when scrolling down. ### Method Signature `static diffClamp(a: Animated, min: number, max: number): AnimatedDiffClamp;` ``` -------------------------------- ### Width and Height Example (JavaScript) Source: https://github.com/react/react-native-website/blob/main/website/versioned_docs/version-0.77/flexbox.md Demonstrates how to dynamically set width and height using 'auto', pixels, and percentages. This example allows users to interactively change the dimensions. ```javascript import React, {useState} from 'react'; import {View, TouchableOpacity, Text, StyleSheet} from 'react-native'; import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context'; const WidthHeightBasics = () => { const [widthType, setWidthType] = useState('auto'); const [heightType, setHeightType] = useState('auto'); return ( ); }; const PreviewLayout = ({ children, widthType, heightType, widthValues, heightValues, setWidthType, setHeightType, }) => ( width {widthValues.map(value => ( setWidthType(value)} style={[styles.button, widthType === value && styles.selected]}> {value} ))} height {heightValues.map(value => ( setHeightType(value)} style={[styles.button, heightType === value && styles.selected]}> {value} ))} {children} ); const styles = StyleSheet.create({ box: { width: 50, height: 50, }, row: { flexDirection: 'row', flexWrap: 'wrap', }, button: { padding: 8, borderRadius: 4, backgroundColor: 'oldlace', alignSelf: 'flex-start', marginRight: 10, marginBottom: 10, }, selected: { backgroundColor: 'coral', shadowOpacity: 0, borderWidth: 0, }, buttonLabel: { fontSize: 12, fontWeight: '500', color: 'coral', }, selectedLabel: { color: 'white', }, label: { textAlign: 'center', marginBottom: 10, fontSize: 24, }, }); export default WidthHeightBasics; ``` -------------------------------- ### Get Dimensions Example Usage Source: https://github.com/react/react-native-website/blob/main/docs/dimensions.md A concise example showing how to destructure width and height from the result of `Dimensions.get('window')`. ```tsx const {height, width} = Dimensions.get('window'); ``` -------------------------------- ### Installing a Specific Library Version Source: https://github.com/react/react-native-website/blob/main/website/versioned_docs/version-0.78/libraries.md Install a particular version of a library to ensure compatibility with your React Native version. For example, installing version 2.0.0 of the netinfo library. ```bash npm install @ ``` ```bash npm install @react-native-community/netinfo@^2.0.0 ``` -------------------------------- ### Hello World Example Source: https://github.com/react/react-native-website/blob/main/docs/introduction.md An interactive example demonstrating a basic React Native component that displays text. This can be run directly in the browser using Snack Player. ```javascript import {Text, View} from 'react-native'; const YourApp = () => { return ( Try editing me! 🎉 ); }; export default YourApp; ``` -------------------------------- ### Get Zulu OpenJDK 17 Installation Info Source: https://github.com/react/react-native-website/blob/main/docs/_getting-started-macos-android.md Retrieves information about the Zulu OpenJDK 17 installation, including its path. This is useful for verifying the installation or locating the JDK. ```shell brew info --cask zulu@17 ``` -------------------------------- ### Start Development Server Source: https://github.com/react/react-native-website/blob/main/README.md Starts the Docusaurus development server for local testing. ```bash yarn start ``` -------------------------------- ### Install a Specific Library Version Source: https://github.com/react/react-native-website/blob/main/docs/libraries.md Install a particular version of a library, for example, to ensure compatibility with an older React Native version. ```bash npm install @ ``` -------------------------------- ### Initialize React Native Project Source: https://github.com/react/react-native-website/blob/main/docs/fabric-native-components.md Initialize a new React Native project. Use `--install-pods false` to skip pod installation for now. ```bash npx @react-native-community/cli@latest init Demo --install-pods false ``` -------------------------------- ### Align Self Example Source: https://github.com/react/react-native-website/blob/main/website/versioned_docs/version-0.78/flexbox.md This example demonstrates the usage of the alignSelf property to align a flex item to the start of the cross-axis. Ensure you have the necessary styles defined. ```javascript const styles = StyleSheet.create({ container: { flex: 1, marginTop: 8, backgroundColor: 'white', }, box: { height: 55, // The alignSelf property is applied here alignSelf: 'flex-start', }, // ... other styles }); ``` -------------------------------- ### Initialize a New React Native Project Source: https://github.com/react/react-native-website/blob/main/docs/get-started-without-a-framework.md Use the React Native Community CLI to generate a new project. This is the standard way to start a project from scratch. ```shell npx @react-native-community/cli@latest init AwesomeProject ``` -------------------------------- ### Clipboard API Example Source: https://github.com/react/react-native-website/blob/main/website/versioned_docs/version-0.77/clipboard.md Demonstrates how to copy text to the clipboard and fetch it back using the Clipboard API. This example requires React Native setup. ```javascript import React, {useState} from 'react'; import { View, Text, TouchableOpacity, Clipboard, StyleSheet, } from 'react-native'; const App = () => { const [copiedText, setCopiedText] = useState(''); const copyToClipboard = () => { Clipboard.setString('hello world'); }; const fetchCopiedText = async () => { const text = await Clipboard.getString(); setCopiedText(text); }; return ( copyToClipboard()}> Click here to copy to Clipboard fetchCopiedText()}> View copied text {copiedText} ); }; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, copiedText: { marginTop: 10, color: 'red', }, }); export default App; ``` -------------------------------- ### Start the Expo development server Source: https://github.com/react/react-native-website/blob/main/website/blog/2026-02-24-react-native-comes-to-meta-quest.mdx Run this command in your Expo project directory to start the development server. This is necessary for connecting with Expo Go on the Meta Quest headset. ```bash npx expo start ``` -------------------------------- ### VirtualizedList Example (JavaScript) Source: https://github.com/react/react-native-website/blob/main/website/versioned_docs/version-0.77/virtualizedlist.md Demonstrates a basic implementation of VirtualizedList in JavaScript, showing how to render a list of items with specified data retrieval and item rendering functions. ```javascript import React from 'react'; import {View, VirtualizedList, StyleSheet, Text, StatusBar} from 'react-native'; import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context'; const getItem = (_data, index) => ({ id: Math.random().toString(12).substring(0), title: `Item ${index + 1}`, }); const getItemCount = _data => 50; const Item = ({title}) => ( {title} ); const App = () => ( } keyExtractor={item => item.id} getItemCount={getItemCount} getItem={getItem} /> ); const styles = StyleSheet.create({ container: { flex: 1, marginTop: StatusBar.currentHeight, }, item: { backgroundColor: '#f9c2ff', height: 150, justifyContent: 'center', marginVertical: 8, marginHorizontal: 16, padding: 20, }, title: { fontSize: 32, }, }); export default App; ``` -------------------------------- ### Start Metro Bundler with npm Source: https://github.com/react/react-native-website/blob/main/docs/_integration-with-existing-apps-kotlin.md Run the npm start command in your project's root directory to launch the Metro bundler. This server provides the JavaScript bundle to your Android simulator or device. ```shell npm start ``` -------------------------------- ### Basic Layout Animation Example Source: https://github.com/react/react-native-website/blob/main/website/versioned_docs/version-0.84/layoutanimation.md This example demonstrates how to use LayoutAnimation to animate changes in layout properties like opacity and size. It includes platform-specific setup for Android. ```tsx import { useState, useEffect, } from 'react'; import { View, Platform, UIManager, LayoutAnimation, StyleSheet, Button, } from 'react-native'; if ( Platform.OS === 'android' && UIManager.setLayoutAnimationEnabledExperimental ) { UIManager.setLayoutAnimationEnabledExperimental(true); } const App = () => { const [boxPosition, setBoxPosition] = useState('left'); const toggleBox = () => { LayoutAnimation.configureNext({ duration: 500, create: {type: 'linear', property: 'opacity'}, update: {type: 'spring', springDamping: 0.4}, delete: {type: 'linear', property: 'opacity'}, }); setBoxPosition(boxPosition === 'left' ? 'right' : 'left'); }; return (