### Install react-native-windows for module development Source: https://github.com/discord/react-native-screens/blob/main/windows/README.md Install the react-native-windows package with a version matching your react-native version for module development. ```bash npm i react-native-windows@^0.62 --dev ``` -------------------------------- ### Install react-native-screens for Bare React Native Project Source: https://github.com/discord/react-native-screens/blob/main/README.md Use this command to add react-native-screens as a dependency in a bare React Native project. ```bash yarn add react-native-screens ``` -------------------------------- ### Install react-native-screens with npm Source: https://github.com/discord/react-native-screens/blob/main/windows/README.md Use this command to install the react-native-screens package. It is recommended for autolinking on React Native for Windows versions 0.63 and later. ```bash npm i react-native-screens --save ``` -------------------------------- ### Install Pods for iOS Fabric Source: https://github.com/discord/react-native-screens/blob/main/README-Fabric.md Install pods for your iOS Fabric application. Ensure the RCT_NEW_ARCH_ENABLED=1 environment variable is set. ```bash RCT_NEW_ARCH_ENABLED=1 rbenv exec bundle exec pod install ``` -------------------------------- ### Install Ruby Gems for iOS Fabric Source: https://github.com/discord/react-native-screens/blob/main/README-Fabric.md Run this command in your application's root directory to install required Ruby gems for iOS Fabric builds. ```bash rbenv exec bundle install ``` -------------------------------- ### Example Header Configuration with Multiple Items Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Demonstrates how to configure header items including text buttons, icon buttons, SF Symbols, menus, badges, and prominent buttons. ```typescript Alert.alert('Text pressed'), }, { type: 'button', image: require('../../assets/search_black.png'), onPress: () => Alert.alert('Icon pressed'), }, { type: 'button', sfSymbolName: "square.and.arrow.up", onPress: () => Alert.alert('SF symbol pressed'), }, { type: 'menu', label: 'Menu', menu: { items: [ { label: 'Option 1', type: "action", onPress: () => Alert.alert('Option 1 pressed'), }, { label: 'Option 2', type: "action", onPress: () => Alert.alert('Option 2 pressed'), }, ], }, }, { type: 'button', label: 'Badge', badge: { value: '3', color: 'white', backgroundColor: 'red', }, onPress: () => Alert.alert('Badge pressed'), }, { type: 'button', label: 'Prominent', variant: 'prominent', tintColor: 'green', onPress: () => Alert.alert('Prominent pressed'), }, ], }} /> ``` -------------------------------- ### Install react-native-screens for Expo Managed Workflow Source: https://github.com/discord/react-native-screens/blob/main/README.md Use this command to add react-native-screens as a dependency when using the Expo managed workflow. ```bash npx expo install react-native-screens ``` -------------------------------- ### Setup ReanimatedScreenProvider for Reanimated Transitions Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Wrap your application with `ReanimatedScreenProvider` to enable the use of `useReanimatedTransitionProgress` hook with react-native-reanimated v2.x. ```jsx import { ReanimatedScreenProvider } from 'react-native-screens/reanimated'; export default function App() { return ( ); } ``` -------------------------------- ### Enable Project Gamma Source: https://github.com/discord/react-native-screens/blob/main/guides/CONTRIBUTING.md Set the RNS_GAMMA_ENABLED environment variable to 1 before installing pods to include Project Gamma (version 5.0) implementation files. This is necessary because Gamma files are excluded from regular builds and will cause runtime crashes if not enabled. ```bash export RNS_GAMMA_ENABLED=1 ``` -------------------------------- ### ScreenContainer with multiple Screens Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Use ScreenContainer to manage the activity state of child Screen components. This example shows how to manage three tabs, with the second tab being active during a transition. ```javascript {tab1} {tab2} {tab3} ``` -------------------------------- ### Use Animated.Value for Transition Progress Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Use the `useTransitionProgress` hook to get animated values for screen transition progress. Interpolate these values to control animations like opacity. ```jsx import { Animated } from 'react-native'; import { useTransitionProgress } from 'react-native-screens'; function Home() { const { progress } = useTransitionProgress(); const opacity = progress.interpolate({ inputRange: [0, 0.5, 1], outputRange: [1.0, 0.0, 1.0], extrapolate: 'clamp', }); return ( ); } ``` -------------------------------- ### navigationBarColor Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Deprecated prop for setting the navigation bar color on Android. It is no longer effective due to edge-to-edge enforcement starting from Android SDK 35. ```APIDOC ## `navigationBarColor` (Android only) ### Description This prop has been **deprecated** due to [edge-to-edge enforcement starting from Android SDK 35](https://developer.android.com/about/versions/15/behavior-changes-15#ux). Setting it has no effect as native code related to this prop has been removed. Kept only for backward compatibility. Will be removed in next major release. Sets the navigation bar color. Defaults to initial status bar color. ``` -------------------------------- ### gestureResponseDistance Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Restricts the distance from the screen edges where the back swipe gesture is recognized on iOS. This is used in conjunction with `fullScreenSwipeEnabled` and can be configured for start, end, top, and bottom edges. ```APIDOC ## `gestureResponseDistance` (iOS only) ### Description Use it to restrict the distance from the edges of screen in which the gesture should be recognized. To be used alongside `fullScreenSwipeEnabled`. The responsive area is covered with 4 values: `start`, `end`, `top`, `bottom`. ### Parameters #### Query Parameters - **start** (number) - Required - The distance from the start edge. - **end** (number) - Required - The distance from the end edge. - **top** (number) - Required - The distance from the top edge. - **bottom** (number) - Required - The distance from the bottom edge. ### Request Example ```tsx gestureResponseDistance: { start: 200, end: 250, top: 100, bottom: 150, } ``` ``` -------------------------------- ### navigationBarTranslucent Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Deprecated prop for setting the navigation bar translucency on Android. It is no longer effective due to edge-to-edge enforcement starting from Android SDK 35. ```APIDOC ## `navigationBarTranslucent` (Android only) ### Description This prop has been **deprecated** due to [edge-to-edge enforcement starting from Android SDK 35](https://developer.android.com/about/versions/15/behavior-changes-15#ux). Setting it has no effect as native code related to this prop has been removed. Kept only for backward compatibility. Will be removed in next major release. Sets the translucency of the navigation bar. Defaults to `false`. ``` -------------------------------- ### Basic CMake Configuration Source: https://github.com/discord/react-native-screens/blob/main/android/src/main/jni/CMakeLists.txt Sets the minimum CMake version and enables verbose makefile output for debugging. ```cmake cmake_minimum_required(VERSION 3.13) set(CMAKE_VERBOSE_MAKEFILE ON) ``` -------------------------------- ### onAppear Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Callback function that is invoked when the current screen appears. ```APIDOC ## `onAppear` ### Description A callback that gets called when the current screen appears. ``` -------------------------------- ### onWillAppear Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Callback function invoked when the current screen is about to appear. This is called at the beginning of the transition. ```APIDOC ## `onWillAppear` ### Description A callback that gets called when the current screen will appear. This is called as soon as the transition begins. ``` -------------------------------- ### Include Directory Configuration Source: https://github.com/discord/react-native-screens/blob/main/android/src/main/jni/CMakeLists.txt Specifies public include directories for the library target, making headers accessible during compilation. ```cmake target_include_directories( ${LIB_TARGET_NAME} PUBLIC . ${LIB_COMMON_DIR} ${LIB_ANDROID_GENERATED_JNI_DIR} ${LIB_ANDROID_GENERATED_COMPONENTS_DIR} ) ``` -------------------------------- ### Include Directories Source: https://github.com/discord/react-native-screens/blob/main/android/CMakeLists.txt Specifies the include directories for the project, ensuring that header files from the '../cpp' directory are accessible during compilation. ```cmake include_directories( ../cpp ) ``` -------------------------------- ### onDisappear Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Callback function that is invoked when the current screen disappears. ```APIDOC ## `onDisappear` ### Description A callback that gets called when the current screen disappears. ``` -------------------------------- ### Add RNScreens.vcxproj to Visual Studio Solution Source: https://github.com/discord/react-native-screens/blob/main/windows/README.md Manually add the RNScreens project file to your Visual Studio solution when using older versions of React Native for Windows. ```bash node_modules\react-native-screens\windows\RNScreens\RNScreens.vcxproj ``` -------------------------------- ### Project Include Directory Source: https://github.com/discord/react-native-screens/blob/main/android/src/main/jni/CMakeLists.txt Adds the current source directory to the project's public include paths. ```cmake target_include_directories( ${CMAKE_PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) ``` -------------------------------- ### Register RNScreens Package Provider in App.cpp Source: https://github.com/discord/react-native-screens/blob/main/windows/README.md Register the RNScreens ReactPackageProvider in your App.cpp file before InitializeComponent() for manual linking. ```c++ PackageProviders().Append(winrt::RNScreens::ReactPackageProvider()); ``` -------------------------------- ### onWillDisappear Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Callback function invoked when the current screen is about to disappear. This is called at the beginning of the transition. ```APIDOC ## `onWillDisappear` ### Description A callback that gets called when the current screen will disappear. This is called as soon as the transition begins. ``` -------------------------------- ### Library and Directory Definitions Source: https://github.com/discord/react-native-screens/blob/main/android/src/main/jni/CMakeLists.txt Defines the library name and various source directory paths used throughout the CMake script. ```cmake set(LIB_LITERAL rnscreens) set(LIB_TARGET_NAME react_codegen_${LIB_LITERAL}) set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) set(LIB_COMMON_DIR ${LIB_ANDROID_DIR}/../common/cpp) set(LIB_COMMON_COMPONENTS_DIR ${LIB_COMMON_DIR}/react/renderer/components/${LIB_LITERAL}) set(LIB_ANDROID_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni) set(LIB_ANDROID_GENERATED_COMPONENTS_DIR ${LIB_ANDROID_GENERATED_JNI_DIR}/react/renderer/components/${LIB_LITERAL}) ``` -------------------------------- ### Source File Discovery Source: https://github.com/discord/react-native-screens/blob/main/android/src/main/jni/CMakeLists.txt Uses file GLOB to find C++ source files from custom and codegen directories. CONFIGURE_DEPENDS ensures files are re-globbed if they change. ```cmake file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS *.cpp ${LIB_COMMON_COMPONENTS_DIR}/*.cpp ${LIB_COMMON_COMPONENTS_DIR}/utils/*.cpp) file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}/*.cpp) ``` -------------------------------- ### Enable Experimental react-freeze Support Source: https://github.com/discord/react-native-screens/blob/main/README.md Enable experimental support for react-freeze by calling enableFreeze(true) in your application's entry file. Requires React Native 0.68+ and react-navigation 5.x or 6.x. ```javascript import { enableFreeze } from 'react-native-screens'; enableFreeze(true); ``` -------------------------------- ### Find ReactAndroid Package Source: https://github.com/discord/react-native-screens/blob/main/android/CMakeLists.txt Finds and includes the ReactAndroid package, which is required for the project's build. ```cmake find_package(ReactAndroid REQUIRED CONFIG) ``` -------------------------------- ### Link Libraries for rnscreens Source: https://github.com/discord/react-native-screens/blob/main/android/CMakeLists.txt Links the necessary libraries to the 'rnscreens' target. This includes ReactAndroid components and potentially fbjni, with conditional linking based on the new architecture. ```cmake if(${RNS_NEW_ARCH_ENABLED}) find_package(fbjni REQUIRED CONFIG) target_link_libraries(rnscreens ReactAndroid::reactnative ReactAndroid::jsi fbjni::fbjni android ) else() target_link_libraries(rnscreens ReactAndroid::jsi android ) endif() ``` -------------------------------- ### Set Target Properties for rnscreens Source: https://github.com/discord/react-native-screens/blob/main/android/CMakeLists.txt Configures build properties for the 'rnscreens' target, including C++ standard version, requiring the standard, disabling extensions, and enabling position-independent code. ```cmake set_target_properties(rnscreens PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF POSITION_INDEPENDENT_CODE ON ) ``` -------------------------------- ### Menu Item Configuration Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Defines the structure for menu items within a button, supporting actions, submenus, and various attributes like icons, states, and styling. ```typescript menu?: { type: 'menu'; label?: string; changesSelectionAsPrimaryAction?: boolean // Whether selection changes as a primary action (iOS 15+). Read more: https://developer.apple.com/documentation/uikit/uibarbuttonitem/changesselectionasprimaryaction items: Array< | { label?: string; type: 'action'; icon?: PlatformIconIOSSfSymbol; state?: 'on' | 'off' | 'mixed'; // State of the menu item. Read more: https://developer.apple.com/documentation/uikit/uimenuelement/state disabled?: boolean; // Attribute indicating disabled style. Read more: https://developer.apple.com/documentation/uikit/uimenuelement/attributes/disabled destructive?: boolean; // Attribute indicating destructive style. Read more: https://developer.apple.com/documentation/uikit/uimenuelement/attributes/destructive hidden?: boolean; // Attribute indicating hidden style. Read more: https://developer.apple.com/documentation/uikit/uimenuelement/attributes/hidden keepsMenuPresented?: boolean; // Attribute indicating that the menu remains presented after firing the element’s action instead of dismissing. Read more: https://developer.apple.com/documentation/uikit/uimenuelement/attributes/keepsmenupresented discoverabilityTitle?: string; // Discoverability title of the menu item. Read more: https://developer.apple.com/documentation/uikit/uiaction/discoverabilitytitle } | { label?: string; type: 'submenu'; icon?: PlatformIconIOSSfSymbol; displayInline?: boolean; // Whether to display submenu inline - https://developer.apple.com/documentation/uikit/uimenu/options-swift.struct/displayinline destructive?: boolean; // Attribute indicating destructive style. Read more: https://developer.apple.com/documentation/uikit/uimenu/options-swift.struct/destructive singleSelection?: boolean; // Whether submenu allows single selection - https://developer.apple.com/documentation/uikit/uimenu/options-swift.struct/singleselection displayAsPalette?: boolean; // Whether to display submenu as palette - https://developer.apple.com/documentation/uikit/uimenu/options-swift.struct/displayaspalette items: menu['items']; // References itself so you can create inifinte deep menus. So either actions or more submenus } > } ``` -------------------------------- ### Generate Codegen Artifacts (Android) Source: https://github.com/discord/react-native-screens/blob/main/guides/CONTRIBUTING.md Manually generate codegen artifacts for the Fabric architecture on Android by running the Gradle task. This ensures that the interfaces are in sync for the Paper architecture. ```bash ./gradlew generateCodegenArtifactsFromSchema ``` -------------------------------- ### Target Compile Definitions Source: https://github.com/discord/react-native-screens/blob/main/android/CMakeLists.txt Adds compile definitions to the 'rnscreens' target, specifically setting Folly configuration to disable it. ```cmake target_compile_definitions( rnscreens PRIVATE -DFOLLY_NO_CONFIG=1 ) ``` -------------------------------- ### Library Linking Source: https://github.com/discord/react-native-screens/blob/main/android/src/main/jni/CMakeLists.txt Links the library target against essential React Native and FBGJNI libraries. ```cmake target_link_libraries( ${LIB_TARGET_NAME} ReactAndroid::reactnative ReactAndroid::jsi fbjni::fbjni ) ``` -------------------------------- ### Compiler Options Source: https://github.com/discord/react-native-screens/blob/main/android/src/main/jni/CMakeLists.txt Specifies essential compiler flags for C++ development, including exception handling, RTTI, C++ standard, and warning levels. ```cmake add_compile_options( -fexceptions -frtti -std=c++20 -Wall -Wpedantic -Wno-gnu-zero-variadic-macro-arguments -Wno-dollar-in-identifier-extension ) ``` -------------------------------- ### Configure Custom Kotlin Version in Android Build Gradle Source: https://github.com/discord/react-native-screens/blob/main/README.md Set the kotlinVersion ext property in your project's android/build.gradle file to specify a custom Kotlin version for react-native-screens. The library requires Kotlin 1.3.50 or higher. ```gradle buildscript { ext { ... kotlinVersion = "1.4.10" } } ``` -------------------------------- ### Library Target Definition Source: https://github.com/discord/react-native-screens/blob/main/android/src/main/jni/CMakeLists.txt Defines the shared library target with its custom and codegen source files. ```cmake add_library( ${LIB_TARGET_NAME} SHARED ${LIB_CUSTOM_SRCS} ${LIB_CODEGEN_SRCS} ) ``` -------------------------------- ### Include RNScreens header in pch.h Source: https://github.com/discord/react-native-screens/blob/main/windows/README.md Include the RNScreens header file in your application's pch.h file for manual linking. ```c++ #include "winrt/RNScreens.h" ``` -------------------------------- ### Conditional Compiler Options for React Native Version Source: https://github.com/discord/react-native-screens/blob/main/android/src/main/jni/CMakeLists.txt Applies specific compile options based on the React Native version. Uses a helper macro for versions 0.80+ or defines custom options for older versions. ```cmake if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 80) target_compile_reactnative_options(${LIB_TARGET_NAME} PRIVATE) else() target_compile_options( ${LIB_TARGET_NAME} PRIVATE -DLOG_TAG="ReactNative" -fexceptions -frtti -std=c++20 -Wall ) endif() ``` -------------------------------- ### Configure Gesture Response Distance Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Use `gestureResponseDistance` to define the area from screen edges where the back swipe gesture is recognized. This is useful alongside `fullScreenSwipeEnabled` to control the gesture's responsiveness. ```tsx gestureResponseDistance: { start: 200, end: 250, top: 100, bottom: 150, } ``` -------------------------------- ### Spacing Item Configuration Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Defines a spacing item for use in navigation headers. The `spacing` property is a numeric value supported only on iOS 18+. ```plaintext type: 'spacing' spacing?: number // Fixed space between items. The numeric value is only supported on iOS 18- ``` -------------------------------- ### Define react-native-screens Shared Library Source: https://github.com/discord/react-native-screens/blob/main/android/CMakeLists.txt Defines the shared library for react-native-screens. Includes conditional source files based on the RNS_NEW_ARCH_ENABLED flag for supporting the new React Native architecture. ```cmake cmake_minimum_required(VERSION 3.9.0) project(rnscreens) if(${RNS_NEW_ARCH_ENABLED}) add_library(rnscreens SHARED ../cpp/RNScreensTurboModule.cpp ../cpp/RNSScreenRemovalListener.cpp ./src/main/cpp/jni-adapter.cpp ./src/main/cpp/NativeProxy.cpp ./src/main/cpp/OnLoad.cpp ) else() add_library(rnscreens SHARED ../cpp/RNScreensTurboModule.cpp ./src/main/cpp/jni-adapter.cpp ) endif() ``` -------------------------------- ### Configure Screen Stack Header with headerConfig Prop Source: https://github.com/discord/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md Use the `headerConfig` prop on `ScreenStackItem` to define header properties like title and large title, and to render custom React Native views within the header, such as a save button in the right view. ```jsx