From 7341879f90df4dcdee3463a3446e29ff464f47dd Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Wed, 6 Dec 2023 17:27:42 +0000 Subject: [PATCH] [docs] Cut version 0.73.0 --- .../_getting-started-linux-android.md | 196 ++ .../_getting-started-macos-android.md | 211 ++ .../_getting-started-macos-ios.md | 182 ++ .../_getting-started-windows-android.md | 229 ++ .../_integration-with-existing-apps-java.md | 443 +++ .../_integration-with-existing-apps-kotlin.md | 419 +++ .../_integration-with-existing-apps-objc.md | 403 +++ .../_integration-with-existing-apps-swift.md | 381 +++ .../_markdown-new-architecture-warning.mdx | 7 + .../version-0.73.0/_remove-global-cli.md | 5 + .../version-0.73.0/accessibility.md | 487 +++ .../version-0.73.0/accessibilityinfo.md | 242 ++ .../version-0.73.0/actionsheetios.md | 139 + .../version-0.73.0/activityindicator.md | 84 + .../versioned_docs/version-0.73.0/alert.md | 248 ++ .../versioned_docs/version-0.73.0/alertios.md | 190 ++ .../versioned_docs/version-0.73.0/animated.md | 536 +++ .../version-0.73.0/animatedvalue.md | 184 ++ .../version-0.73.0/animatedvaluexy.md | 224 ++ .../version-0.73.0/animations.md | 675 ++++ .../version-0.73.0/app-extensions.md | 26 + .../version-0.73.0/appearance.md | 100 + .../version-0.73.0/appregistry.md | 383 +++ .../versioned_docs/version-0.73.0/appstate.md | 114 + .../version-0.73.0/asyncstorage.md | 365 +++ .../version-0.73.0/backhandler.md | 136 + .../version-0.73.0/build-speed.md | 197 ++ .../version-0.73.0/building-for-tv.md | 191 ++ .../versioned_docs/version-0.73.0/button.md | 295 ++ .../versioned_docs/version-0.73.0/checkbox.md | 113 + .../version-0.73.0/clipboard.md | 110 + .../versioned_docs/version-0.73.0/colors.md | 223 ++ .../version-0.73.0/communication-android.md | 149 + .../version-0.73.0/communication-ios.md | 204 ++ .../version-0.73.0/components-and-apis.md | 207 ++ .../version-0.73.0/custom-webview-android.md | 403 +++ .../version-0.73.0/custom-webview-ios.md | 236 ++ .../version-0.73.0/datepickerandroid.md | 75 + .../version-0.73.0/datepickerios.md | 162 + .../debugging-release-builds.md | 97 + .../version-0.73.0/debugging.md | 148 + .../version-0.73.0/devsettings.md | 51 + .../version-0.73.0/dimensions.md | 147 + .../version-0.73.0/direct-manipulation.md | 444 +++ .../version-0.73.0/drawerlayoutandroid.md | 328 ++ .../version-0.73.0/dynamiccolorios.md | 55 + .../versioned_docs/version-0.73.0/easing.md | 558 ++++ .../version-0.73.0/fast-refresh.md | 47 + .../versioned_docs/version-0.73.0/flatlist.md | 863 +++++ .../versioned_docs/version-0.73.0/flexbox.md | 2868 +++++++++++++++++ .../gesture-responder-system.md | 66 + .../version-0.73.0/getting-started.md | 168 + .../version-0.73.0/handling-text-input.md | 41 + .../version-0.73.0/handling-touches.md | 185 ++ .../version-0.73.0/headless-js-android.md | 396 +++ .../version-0.73.0/height-and-width.md | 121 + .../versioned_docs/version-0.73.0/hermes.md | 249 ++ .../version-0.73.0/image-style-props.md | 387 +++ .../versioned_docs/version-0.73.0/image.md | 629 ++++ .../version-0.73.0/imagebackground.md | 83 + .../version-0.73.0/imagepickerios.md | 79 + .../versioned_docs/version-0.73.0/images.md | 248 ++ .../version-0.73.0/improvingux.md | 596 ++++ .../version-0.73.0/inputaccessoryview.md | 78 + .../integration-with-android-fragment.md | 309 ++ .../integration-with-existing-apps.md | 38 + .../version-0.73.0/interactionmanager.md | 410 +++ .../intro-react-native-components.md | 84 + .../version-0.73.0/intro-react.md | 467 +++ .../version-0.73.0/introduction.md | 83 + .../version-0.73.0/javascript-environment.md | 109 + .../versioned_docs/version-0.73.0/keyboard.md | 141 + .../version-0.73.0/keyboardavoidingview.md | 120 + .../version-0.73.0/layout-props.md | 996 ++++++ .../version-0.73.0/layoutanimation.md | 354 ++ .../version-0.73.0/layoutevent.md | 72 + .../version-0.73.0/libraries.md | 118 + .../version-0.73.0/linking-libraries-ios.md | 57 + .../versioned_docs/version-0.73.0/linking.md | 657 ++++ .../versioned_docs/version-0.73.0/metro.md | 104 + .../versioned_docs/version-0.73.0/modal.md | 233 ++ .../version-0.73.0/more-resources.md | 43 + .../native-components-android.md | 867 +++++ .../version-0.73.0/native-components-ios.md | 496 +++ .../version-0.73.0/native-debugging.md | 44 + .../version-0.73.0/native-modules-android.md | 1179 +++++++ .../version-0.73.0/native-modules-intro.md | 29 + .../version-0.73.0/native-modules-ios.md | 618 ++++ .../version-0.73.0/native-modules-setup.md | 35 + .../version-0.73.0/navigation.md | 122 + .../versioned_docs/version-0.73.0/network.md | 274 ++ .../new-architecture-app-intro.md | 125 + .../new-architecture-appendix.md | 301 ++ .../version-0.73.0/new-architecture-intro.md | 27 + .../new-architecture-library-android.md | 118 + .../new-architecture-library-intro.md | 420 +++ .../new-architecture-library-ios.md | 73 + .../new-architecture-troubleshooting.md | 40 + .../optimizing-flatlist-configuration.md | 155 + .../version-0.73.0/other-debugging-methods.md | 95 + .../version-0.73.0/out-of-tree-platforms.md | 46 + .../version-0.73.0/panresponder.md | 174 + .../version-0.73.0/performance.md | 108 + .../version-0.73.0/permissionsandroid.md | 205 ++ .../version-0.73.0/pixelratio.md | 168 + .../version-0.73.0/platform-specific-code.md | 138 + .../versioned_docs/version-0.73.0/platform.md | 224 ++ .../version-0.73.0/platformcolor.md | 83 + .../version-0.73.0/pressable.md | 253 ++ .../version-0.73.0/pressevent.md | 118 + .../version-0.73.0/profile-hermes.md | 137 + .../version-0.73.0/profiling.md | 146 + .../version-0.73.0/progressbarandroid.md | 129 + .../version-0.73.0/progressviewios.md | 124 + .../versioned_docs/version-0.73.0/props.md | 99 + .../version-0.73.0/publishing-to-app-store.md | 88 + .../version-0.73.0/pushnotificationios.md | 511 +++ .../ram-bundles-inline-requires.md | 184 ++ .../react-18-and-react-native.md | 122 + .../version-0.73.0/react-devtools.md | 87 + .../react-native-gradle-plugin.md | 187 ++ .../version-0.73.0/react-node.md | 13 + website/versioned_docs/version-0.73.0/rect.md | 50 + .../version-0.73.0/refreshcontrol.md | 168 + .../versioned_docs/version-0.73.0/roottag.md | 74 + .../version-0.73.0/running-on-device.md | 437 +++ .../running-on-simulator-ios.md | 94 + .../version-0.73.0/safeareaview.md | 49 + .../version-0.73.0/scrollview.md | 776 +++++ .../version-0.73.0/sectionlist.md | 368 +++ .../versioned_docs/version-0.73.0/security.md | 129 + .../version-0.73.0/segmentedcontrolios.md | 126 + .../versioned_docs/version-0.73.0/settings.md | 98 + .../version-0.73.0/shadow-props.md | 253 ++ .../versioned_docs/version-0.73.0/share.md | 130 + .../version-0.73.0/signed-apk-android.md | 196 ++ .../versioned_docs/version-0.73.0/slider.md | 176 + .../version-0.73.0/speeding-ci-builds.md | 54 + .../versioned_docs/version-0.73.0/state.md | 103 + .../version-0.73.0/statusbar.md | 477 +++ .../version-0.73.0/statusbarios.md | 8 + .../versioned_docs/version-0.73.0/style.md | 52 + .../version-0.73.0/stylesheet.md | 338 ++ .../versioned_docs/version-0.73.0/switch.md | 124 + .../versioned_docs/version-0.73.0/systrace.md | 146 + .../version-0.73.0/testing-overview.md | 273 ++ .../version-0.73.0/text-style-props.md | 941 ++++++ website/versioned_docs/version-0.73.0/text.md | 758 +++++ .../version-0.73.0/textinput.md | 1039 ++++++ .../_markdown_beta_ts_support.mdx | 3 + .../_markdown_native_deprecation.mdx | 4 + ...ackward-compatibility-fabric-components.md | 522 +++ .../backward-compatibility-turbomodules.md | 463 +++ .../backward-compatibility.md | 25 + .../the-new-architecture/cxx-custom-types.md | 285 ++ .../cxx-cxxturbomodules.md | 520 +++ .../the-new-architecture/landing-page.md | 32 + .../the-new-architecture/pillars-codegen.md | 232 ++ .../pillars-fabric-components.md | 1042 ++++++ .../pillars-turbomodule.md | 896 +++++ .../the-new-architecture/pillars.md | 41 + .../the-new-architecture/use-app-template.md | 122 + .../the-new-architecture/why.md | 44 + .../version-0.73.0/timepickerandroid.md | 71 + .../versioned_docs/version-0.73.0/timers.md | 54 + .../version-0.73.0/toastandroid.md | 152 + .../version-0.73.0/touchablehighlight.md | 204 ++ .../version-0.73.0/touchablenativefeedback.md | 213 ++ .../version-0.73.0/touchableopacity.md | 159 + .../touchablewithoutfeedback.md | 520 +++ .../version-0.73.0/transforms.md | 326 ++ .../version-0.73.0/troubleshooting.md | 152 + .../versioned_docs/version-0.73.0/tutorial.md | 270 ++ .../version-0.73.0/typescript.md | 219 ++ .../version-0.73.0/upgrading.md | 75 + .../version-0.73.0/usecolorscheme.md | 48 + .../version-0.73.0/usewindowdimensions.md | 93 + .../version-0.73.0/using-a-listview.md | 114 + .../version-0.73.0/using-a-scrollview.md | 63 + .../version-0.73.0/vibration.md | 146 + .../version-0.73.0/view-style-props.md | 289 ++ website/versioned_docs/version-0.73.0/view.md | 771 +++++ .../version-0.73.0/viewtoken.md | 65 + .../version-0.73.0/virtualizedlist.md | 718 +++++ .../version-0.73.0-sidebars.json | 301 ++ website/versions.json | 1 + 186 files changed, 47555 insertions(+) create mode 100644 website/versioned_docs/version-0.73.0/_getting-started-linux-android.md create mode 100644 website/versioned_docs/version-0.73.0/_getting-started-macos-android.md create mode 100644 website/versioned_docs/version-0.73.0/_getting-started-macos-ios.md create mode 100644 website/versioned_docs/version-0.73.0/_getting-started-windows-android.md create mode 100644 website/versioned_docs/version-0.73.0/_integration-with-existing-apps-java.md create mode 100644 website/versioned_docs/version-0.73.0/_integration-with-existing-apps-kotlin.md create mode 100644 website/versioned_docs/version-0.73.0/_integration-with-existing-apps-objc.md create mode 100644 website/versioned_docs/version-0.73.0/_integration-with-existing-apps-swift.md create mode 100644 website/versioned_docs/version-0.73.0/_markdown-new-architecture-warning.mdx create mode 100644 website/versioned_docs/version-0.73.0/_remove-global-cli.md create mode 100644 website/versioned_docs/version-0.73.0/accessibility.md create mode 100644 website/versioned_docs/version-0.73.0/accessibilityinfo.md create mode 100644 website/versioned_docs/version-0.73.0/actionsheetios.md create mode 100644 website/versioned_docs/version-0.73.0/activityindicator.md create mode 100644 website/versioned_docs/version-0.73.0/alert.md create mode 100644 website/versioned_docs/version-0.73.0/alertios.md create mode 100644 website/versioned_docs/version-0.73.0/animated.md create mode 100644 website/versioned_docs/version-0.73.0/animatedvalue.md create mode 100644 website/versioned_docs/version-0.73.0/animatedvaluexy.md create mode 100644 website/versioned_docs/version-0.73.0/animations.md create mode 100644 website/versioned_docs/version-0.73.0/app-extensions.md create mode 100644 website/versioned_docs/version-0.73.0/appearance.md create mode 100644 website/versioned_docs/version-0.73.0/appregistry.md create mode 100644 website/versioned_docs/version-0.73.0/appstate.md create mode 100644 website/versioned_docs/version-0.73.0/asyncstorage.md create mode 100644 website/versioned_docs/version-0.73.0/backhandler.md create mode 100644 website/versioned_docs/version-0.73.0/build-speed.md create mode 100644 website/versioned_docs/version-0.73.0/building-for-tv.md create mode 100644 website/versioned_docs/version-0.73.0/button.md create mode 100644 website/versioned_docs/version-0.73.0/checkbox.md create mode 100644 website/versioned_docs/version-0.73.0/clipboard.md create mode 100644 website/versioned_docs/version-0.73.0/colors.md create mode 100644 website/versioned_docs/version-0.73.0/communication-android.md create mode 100644 website/versioned_docs/version-0.73.0/communication-ios.md create mode 100644 website/versioned_docs/version-0.73.0/components-and-apis.md create mode 100644 website/versioned_docs/version-0.73.0/custom-webview-android.md create mode 100644 website/versioned_docs/version-0.73.0/custom-webview-ios.md create mode 100644 website/versioned_docs/version-0.73.0/datepickerandroid.md create mode 100644 website/versioned_docs/version-0.73.0/datepickerios.md create mode 100644 website/versioned_docs/version-0.73.0/debugging-release-builds.md create mode 100644 website/versioned_docs/version-0.73.0/debugging.md create mode 100644 website/versioned_docs/version-0.73.0/devsettings.md create mode 100644 website/versioned_docs/version-0.73.0/dimensions.md create mode 100644 website/versioned_docs/version-0.73.0/direct-manipulation.md create mode 100644 website/versioned_docs/version-0.73.0/drawerlayoutandroid.md create mode 100644 website/versioned_docs/version-0.73.0/dynamiccolorios.md create mode 100644 website/versioned_docs/version-0.73.0/easing.md create mode 100644 website/versioned_docs/version-0.73.0/fast-refresh.md create mode 100644 website/versioned_docs/version-0.73.0/flatlist.md create mode 100644 website/versioned_docs/version-0.73.0/flexbox.md create mode 100644 website/versioned_docs/version-0.73.0/gesture-responder-system.md create mode 100644 website/versioned_docs/version-0.73.0/getting-started.md create mode 100644 website/versioned_docs/version-0.73.0/handling-text-input.md create mode 100644 website/versioned_docs/version-0.73.0/handling-touches.md create mode 100644 website/versioned_docs/version-0.73.0/headless-js-android.md create mode 100644 website/versioned_docs/version-0.73.0/height-and-width.md create mode 100644 website/versioned_docs/version-0.73.0/hermes.md create mode 100644 website/versioned_docs/version-0.73.0/image-style-props.md create mode 100644 website/versioned_docs/version-0.73.0/image.md create mode 100644 website/versioned_docs/version-0.73.0/imagebackground.md create mode 100644 website/versioned_docs/version-0.73.0/imagepickerios.md create mode 100644 website/versioned_docs/version-0.73.0/images.md create mode 100644 website/versioned_docs/version-0.73.0/improvingux.md create mode 100644 website/versioned_docs/version-0.73.0/inputaccessoryview.md create mode 100644 website/versioned_docs/version-0.73.0/integration-with-android-fragment.md create mode 100644 website/versioned_docs/version-0.73.0/integration-with-existing-apps.md create mode 100644 website/versioned_docs/version-0.73.0/interactionmanager.md create mode 100644 website/versioned_docs/version-0.73.0/intro-react-native-components.md create mode 100644 website/versioned_docs/version-0.73.0/intro-react.md create mode 100644 website/versioned_docs/version-0.73.0/introduction.md create mode 100644 website/versioned_docs/version-0.73.0/javascript-environment.md create mode 100644 website/versioned_docs/version-0.73.0/keyboard.md create mode 100644 website/versioned_docs/version-0.73.0/keyboardavoidingview.md create mode 100644 website/versioned_docs/version-0.73.0/layout-props.md create mode 100644 website/versioned_docs/version-0.73.0/layoutanimation.md create mode 100644 website/versioned_docs/version-0.73.0/layoutevent.md create mode 100644 website/versioned_docs/version-0.73.0/libraries.md create mode 100644 website/versioned_docs/version-0.73.0/linking-libraries-ios.md create mode 100644 website/versioned_docs/version-0.73.0/linking.md create mode 100644 website/versioned_docs/version-0.73.0/metro.md create mode 100644 website/versioned_docs/version-0.73.0/modal.md create mode 100644 website/versioned_docs/version-0.73.0/more-resources.md create mode 100644 website/versioned_docs/version-0.73.0/native-components-android.md create mode 100644 website/versioned_docs/version-0.73.0/native-components-ios.md create mode 100644 website/versioned_docs/version-0.73.0/native-debugging.md create mode 100644 website/versioned_docs/version-0.73.0/native-modules-android.md create mode 100644 website/versioned_docs/version-0.73.0/native-modules-intro.md create mode 100644 website/versioned_docs/version-0.73.0/native-modules-ios.md create mode 100644 website/versioned_docs/version-0.73.0/native-modules-setup.md create mode 100644 website/versioned_docs/version-0.73.0/navigation.md create mode 100644 website/versioned_docs/version-0.73.0/network.md create mode 100644 website/versioned_docs/version-0.73.0/new-architecture-app-intro.md create mode 100644 website/versioned_docs/version-0.73.0/new-architecture-appendix.md create mode 100644 website/versioned_docs/version-0.73.0/new-architecture-intro.md create mode 100644 website/versioned_docs/version-0.73.0/new-architecture-library-android.md create mode 100644 website/versioned_docs/version-0.73.0/new-architecture-library-intro.md create mode 100644 website/versioned_docs/version-0.73.0/new-architecture-library-ios.md create mode 100644 website/versioned_docs/version-0.73.0/new-architecture-troubleshooting.md create mode 100644 website/versioned_docs/version-0.73.0/optimizing-flatlist-configuration.md create mode 100644 website/versioned_docs/version-0.73.0/other-debugging-methods.md create mode 100644 website/versioned_docs/version-0.73.0/out-of-tree-platforms.md create mode 100644 website/versioned_docs/version-0.73.0/panresponder.md create mode 100644 website/versioned_docs/version-0.73.0/performance.md create mode 100644 website/versioned_docs/version-0.73.0/permissionsandroid.md create mode 100644 website/versioned_docs/version-0.73.0/pixelratio.md create mode 100644 website/versioned_docs/version-0.73.0/platform-specific-code.md create mode 100644 website/versioned_docs/version-0.73.0/platform.md create mode 100644 website/versioned_docs/version-0.73.0/platformcolor.md create mode 100644 website/versioned_docs/version-0.73.0/pressable.md create mode 100644 website/versioned_docs/version-0.73.0/pressevent.md create mode 100644 website/versioned_docs/version-0.73.0/profile-hermes.md create mode 100644 website/versioned_docs/version-0.73.0/profiling.md create mode 100644 website/versioned_docs/version-0.73.0/progressbarandroid.md create mode 100644 website/versioned_docs/version-0.73.0/progressviewios.md create mode 100644 website/versioned_docs/version-0.73.0/props.md create mode 100644 website/versioned_docs/version-0.73.0/publishing-to-app-store.md create mode 100644 website/versioned_docs/version-0.73.0/pushnotificationios.md create mode 100644 website/versioned_docs/version-0.73.0/ram-bundles-inline-requires.md create mode 100644 website/versioned_docs/version-0.73.0/react-18-and-react-native.md create mode 100644 website/versioned_docs/version-0.73.0/react-devtools.md create mode 100644 website/versioned_docs/version-0.73.0/react-native-gradle-plugin.md create mode 100644 website/versioned_docs/version-0.73.0/react-node.md create mode 100644 website/versioned_docs/version-0.73.0/rect.md create mode 100644 website/versioned_docs/version-0.73.0/refreshcontrol.md create mode 100644 website/versioned_docs/version-0.73.0/roottag.md create mode 100644 website/versioned_docs/version-0.73.0/running-on-device.md create mode 100644 website/versioned_docs/version-0.73.0/running-on-simulator-ios.md create mode 100644 website/versioned_docs/version-0.73.0/safeareaview.md create mode 100644 website/versioned_docs/version-0.73.0/scrollview.md create mode 100644 website/versioned_docs/version-0.73.0/sectionlist.md create mode 100644 website/versioned_docs/version-0.73.0/security.md create mode 100644 website/versioned_docs/version-0.73.0/segmentedcontrolios.md create mode 100644 website/versioned_docs/version-0.73.0/settings.md create mode 100644 website/versioned_docs/version-0.73.0/shadow-props.md create mode 100644 website/versioned_docs/version-0.73.0/share.md create mode 100644 website/versioned_docs/version-0.73.0/signed-apk-android.md create mode 100644 website/versioned_docs/version-0.73.0/slider.md create mode 100644 website/versioned_docs/version-0.73.0/speeding-ci-builds.md create mode 100644 website/versioned_docs/version-0.73.0/state.md create mode 100644 website/versioned_docs/version-0.73.0/statusbar.md create mode 100644 website/versioned_docs/version-0.73.0/statusbarios.md create mode 100644 website/versioned_docs/version-0.73.0/style.md create mode 100644 website/versioned_docs/version-0.73.0/stylesheet.md create mode 100644 website/versioned_docs/version-0.73.0/switch.md create mode 100644 website/versioned_docs/version-0.73.0/systrace.md create mode 100644 website/versioned_docs/version-0.73.0/testing-overview.md create mode 100644 website/versioned_docs/version-0.73.0/text-style-props.md create mode 100644 website/versioned_docs/version-0.73.0/text.md create mode 100644 website/versioned_docs/version-0.73.0/textinput.md create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/_markdown_beta_ts_support.mdx create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/_markdown_native_deprecation.mdx create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/backward-compatibility-fabric-components.md create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/backward-compatibility-turbomodules.md create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/backward-compatibility.md create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/cxx-custom-types.md create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/cxx-cxxturbomodules.md create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/landing-page.md create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/pillars-codegen.md create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/pillars-fabric-components.md create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/pillars-turbomodule.md create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/pillars.md create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/use-app-template.md create mode 100644 website/versioned_docs/version-0.73.0/the-new-architecture/why.md create mode 100644 website/versioned_docs/version-0.73.0/timepickerandroid.md create mode 100644 website/versioned_docs/version-0.73.0/timers.md create mode 100644 website/versioned_docs/version-0.73.0/toastandroid.md create mode 100644 website/versioned_docs/version-0.73.0/touchablehighlight.md create mode 100644 website/versioned_docs/version-0.73.0/touchablenativefeedback.md create mode 100644 website/versioned_docs/version-0.73.0/touchableopacity.md create mode 100644 website/versioned_docs/version-0.73.0/touchablewithoutfeedback.md create mode 100644 website/versioned_docs/version-0.73.0/transforms.md create mode 100644 website/versioned_docs/version-0.73.0/troubleshooting.md create mode 100644 website/versioned_docs/version-0.73.0/tutorial.md create mode 100644 website/versioned_docs/version-0.73.0/typescript.md create mode 100644 website/versioned_docs/version-0.73.0/upgrading.md create mode 100644 website/versioned_docs/version-0.73.0/usecolorscheme.md create mode 100644 website/versioned_docs/version-0.73.0/usewindowdimensions.md create mode 100644 website/versioned_docs/version-0.73.0/using-a-listview.md create mode 100644 website/versioned_docs/version-0.73.0/using-a-scrollview.md create mode 100644 website/versioned_docs/version-0.73.0/vibration.md create mode 100644 website/versioned_docs/version-0.73.0/view-style-props.md create mode 100644 website/versioned_docs/version-0.73.0/view.md create mode 100644 website/versioned_docs/version-0.73.0/viewtoken.md create mode 100644 website/versioned_docs/version-0.73.0/virtualizedlist.md create mode 100644 website/versioned_sidebars/version-0.73.0-sidebars.json diff --git a/website/versioned_docs/version-0.73.0/_getting-started-linux-android.md b/website/versioned_docs/version-0.73.0/_getting-started-linux-android.md new file mode 100644 index 00000000000..ec095bc07d3 --- /dev/null +++ b/website/versioned_docs/version-0.73.0/_getting-started-linux-android.md @@ -0,0 +1,196 @@ +import RemoveGlobalCLI from './\_remove-global-cli.md'; +import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants'; + +## Installing dependencies + +You will need Node, the React Native command line interface, a JDK, and Android Studio. + +While you can use any editor of your choice to develop your app, you will need to install Android Studio in order to set up the necessary tooling to build your React Native app for Android. + +

Node

+ +Follow the [installation instructions for your Linux distribution](https://nodejs.org/en/download/package-manager/) to install Node 18 or newer. + +

Java Development Kit

+ +React Native currently recommends version 17 of the Java SE Development Kit (JDK). You may encounter problems using higher JDK versions. You may download and install [OpenJDK](https://openjdk.java.net) from [AdoptOpenJDK](https://adoptopenjdk.net/) or your system packager. + +

Android development environment

+ +Setting up your development environment can be somewhat tedious if you're new to Android development. If you're already familiar with Android development, there are a few things you may need to configure. In either case, please make sure to carefully follow the next few steps. + +

1. Install Android Studio

+ +[Download and install Android Studio](https://developer.android.com/studio/index.html). While on Android Studio installation wizard, make sure the boxes next to all of the following items are checked: + +- `Android SDK` +- `Android SDK Platform` +- `Android Virtual Device` + +Then, click "Next" to install all of these components. + +> If the checkboxes are grayed out, you will have a chance to install these components later on. + +Once setup has finalized and you're presented with the Welcome screen, proceed to the next step. + +

2. Install the Android SDK

+ +Android Studio installs the latest Android SDK by default. Building a React Native app with native code, however, requires the `Android 13 (Tiramisu)` SDK in particular. Additional Android SDKs can be installed through the SDK Manager in Android Studio. + +To do that, open Android Studio, click on "Configure" button and select "SDK Manager". + +> The SDK Manager can also be found within the Android Studio "Settings" dialog, under **Languages & Frameworks** → **Android SDK**. + +Select the "SDK Platforms" tab from within the SDK Manager, then check the box next to "Show Package Details" in the bottom right corner. Look for and expand the `Android 13 (Tiramisu)` entry, then make sure the following items are checked: + +- `Android SDK Platform 33` +- `Intel x86 Atom_64 System Image` or `Google APIs Intel x86 Atom System Image` + +Next, select the "SDK Tools" tab and check the box next to "Show Package Details" here as well. Look for and expand the "Android SDK Build-Tools" entry, then make sure that `33.0.0` is selected. + +Finally, click "Apply" to download and install the Android SDK and related build tools. + +

3. Configure the ANDROID_HOME environment variable

+ +The React Native tools require some environment variables to be set up in order to build apps with native code. + +Add the following lines to your `$HOME/.bash_profile` or `$HOME/.bashrc` (if you are using `zsh` then `~/.zprofile` or `~/.zshrc`) config file: + +```shell +export ANDROID_HOME=$HOME/Android/Sdk +export PATH=$PATH:$ANDROID_HOME/emulator +export PATH=$PATH:$ANDROID_HOME/platform-tools +``` + +> `.bash_profile` is specific to `bash`. If you're using another shell, you will need to edit the appropriate shell-specific config file. + +Type `source $HOME/.bash_profile` for `bash` or `source $HOME/.zprofile` to load the config into your current shell. Verify that ANDROID_HOME has been set by running `echo $ANDROID_HOME` and the appropriate directories have been added to your path by running `echo $PATH`. + +> Please make sure you use the correct Android SDK path. You can find the actual location of the SDK in the Android Studio "Settings" dialog, under **Languages & Frameworks** → **Android SDK**. + +

Watchman

+ +Follow the [Watchman installation guide](https://facebook.github.io/watchman/docs/install#buildinstall) to compile and install Watchman from source. + +> [Watchman](https://facebook.github.io/watchman/docs/install) is a tool by Facebook for watching changes in the filesystem. It is highly recommended you install it for better performance and increased compatibility in certain edge cases (translation: you may be able to get by without installing this, but your mileage may vary; installing this now may save you from a headache later). + +

React Native Command Line Interface

+ +React Native has a built-in command line interface. Rather than install and manage a specific version of the CLI globally, we recommend you access the current version at runtime using `npx`, which ships with Node.js. With `npx react-native `, the current stable version of the CLI will be downloaded and executed at the time the command is run. + +

Creating a new application

+ + + +React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using `npx`, which ships with Node.js. Let's create a new React Native project called "AwesomeProject": + +```shell +npx react-native@latest init AwesomeProject +``` + +This is not necessary if you are integrating React Native into an existing application, if you "ejected" from Expo, or if you're adding Android support to an existing React Native project (see [Integration with Existing Apps](integration-with-existing-apps.md)). You can also use a third-party CLI to init your React Native app, such as [Ignite CLI](/~https://github.com/infinitered/ignite). + +

[Optional] Using a specific version or template

+ +If you want to start a new project with a specific React Native version, you can use the `--version` argument: + +```shell +npx react-native@X.XX.X init AwesomeProject --version X.XX.X +``` + +You can also start a project with a custom React Native template with the `--template` argument. + +

Preparing the Android device

+ +You will need an Android device to run your React Native Android app. This can be either a physical Android device, or more commonly, you can use an Android Virtual Device which allows you to emulate an Android device on your computer. + +Either way, you will need to prepare the device to run Android apps for development. + +

Using a physical device

+ +If you have a physical Android device, you can use it for development in place of an AVD by plugging it in to your computer using a USB cable and following the instructions [here](running-on-device.md). + +

Using a virtual device

+ +If you use Android Studio to open `./AwesomeProject/android`, you can see the list of available Android Virtual Devices (AVDs) by opening the "AVD Manager" from within Android Studio. Look for an icon that looks like this: + +![Android Studio AVD Manager](/docs/assets/GettingStartedAndroidStudioAVD.png) + +If you have recently installed Android Studio, you will likely need to [create a new AVD](https://developer.android.com/studio/run/managing-avds.html). Select "Create Virtual Device...", then pick any Phone from the list and click "Next", then select the **Tiramisu** API Level 33 image. + +> We recommend configuring [VM acceleration](https://developer.android.com/studio/run/emulator-acceleration.html#vm-linux) on your system to improve performance. Once you've followed those instructions, go back to the AVD Manager. + +Click "Next" then "Finish" to create your AVD. At this point you should be able to click on the green triangle button next to your AVD to launch it, then proceed to the next step. + +

Running your React Native application

+ +

Step 1: Start Metro

+ +[**Metro**](https://facebook.github.io/metro/) is the JavaScript build tool for React Native. To start the Metro development server, run the following from your project folder: + + + + +```shell +npm start +``` + + + + +```shell +yarn start +``` + + + + +:::note +If you're familiar with web development, Metro is similar to bundlers such as Vite and webpack, but is designed end-to-end for React Native. For instance, Metro uses [Babel](https://babel.dev/) to transform syntax such as JSX into executable JavaScript. +::: + +

Step 2: Start your application

+ +Let Metro Bundler run in its own terminal. Open a new terminal inside your React Native project folder. Run the following: + + + + +```shell +npm run android +``` + + + + +```shell +yarn android +``` + + + + +If everything is set up correctly, you should see your new app running in your Android emulator shortly. + +This is one way to run your app - you can also run it directly from within Android Studio. + +> If you can't get this to work, see the [Troubleshooting](troubleshooting.md) page. + +

Modifying your app

+ +Now that you have successfully run the app, let's modify it. + +- Open `App.tsx` in your text editor of choice and edit some lines. +- Press the R key twice or select `Reload` from the Dev Menu (Ctrl + M) to see your changes! + +

That's it!

+ +Congratulations! You've successfully run and modified your first React Native app. + +
+ +

Now what?

+ +- If you want to add this new React Native code to an existing application, check out the [Integration guide](integration-with-existing-apps.md). + +If you're curious to learn more about React Native, check out the [Introduction to React Native](getting-started). diff --git a/website/versioned_docs/version-0.73.0/_getting-started-macos-android.md b/website/versioned_docs/version-0.73.0/_getting-started-macos-android.md new file mode 100644 index 00000000000..fa5f79e1a62 --- /dev/null +++ b/website/versioned_docs/version-0.73.0/_getting-started-macos-android.md @@ -0,0 +1,211 @@ +import RemoveGlobalCLI from './\_remove-global-cli.md'; +import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants'; + +## Installing dependencies + +You will need Node, Watchman, the React Native command line interface, a JDK, and Android Studio. + +While you can use any editor of your choice to develop your app, you will need to install Android Studio in order to set up the necessary tooling to build your React Native app for Android. + +

Node & Watchman

+ +We recommend installing Node and Watchman using [Homebrew](https://brew.sh/). Run the following commands in a Terminal after installing Homebrew: + +```shell +brew install node +brew install watchman +``` + +If you have already installed Node on your system, make sure it is Node 18 or newer. + +[Watchman](https://facebook.github.io/watchman) is a tool by Facebook for watching changes in the filesystem. It is highly recommended you install it for better performance. + +

Java Development Kit

+ +We recommend installing the OpenJDK distribution called Azul **Zulu** using [Homebrew](https://brew.sh/). Run the following commands in a Terminal after installing Homebrew: + +```shell +brew tap homebrew/cask-versions +brew install --cask zulu17 + +# Get path to where cask was installed to double-click installer +brew info --cask zulu17 +``` + +After you install the JDK, update your `JAVA_HOME` environment variable. If you used above steps, JDK will likely be at `/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home` + +The Zulu OpenJDK distribution offers JDKs for **both Intel and M1 Macs**. This will make sure your builds are faster on M1 Macs compared to using an Intel-based JDK. + +If you have already installed JDK on your system, we recommend JDK 17. You may encounter problems using higher JDK versions. + +

Android development environment

+ +Setting up your development environment can be somewhat tedious if you're new to Android development. If you're already familiar with Android development, there are a few things you may need to configure. In either case, please make sure to carefully follow the next few steps. + +

1. Install Android Studio

+ +[Download and install Android Studio](https://developer.android.com/studio/index.html). While on Android Studio installation wizard, make sure the boxes next to all of the following items are checked: + +- `Android SDK` +- `Android SDK Platform` +- `Android Virtual Device` + +Then, click "Next" to install all of these components. + +> If the checkboxes are grayed out, you will have a chance to install these components later on. + +Once setup has finalized and you're presented with the Welcome screen, proceed to the next step. + +

2. Install the Android SDK

+ +Android Studio installs the latest Android SDK by default. Building a React Native app with native code, however, requires the `Android 13 (Tiramisu)` SDK in particular. Additional Android SDKs can be installed through the SDK Manager in Android Studio. + +To do that, open Android Studio, click on "More Actions" button and select "SDK Manager". + +![Android Studio Welcome](/docs/assets/GettingStartedAndroidStudioWelcomeMacOS.png) + +> The SDK Manager can also be found within the Android Studio "Settings" dialog, under **Languages & Frameworks** → **Android SDK**. + +Select the "SDK Platforms" tab from within the SDK Manager, then check the box next to "Show Package Details" in the bottom right corner. Look for and expand the `Android 13 (Tiramisu)` entry, then make sure the following items are checked: + +- `Android SDK Platform 33` +- `Intel x86 Atom_64 System Image` or `Google APIs Intel x86 Atom System Image` or (for Apple M1 Silicon) `Google APIs ARM 64 v8a System Image` + +Next, select the "SDK Tools" tab and check the box next to "Show Package Details" here as well. Look for and expand the "Android SDK Build-Tools" entry, then make sure that `33.0.0` is selected. + +Finally, click "Apply" to download and install the Android SDK and related build tools. + +

3. Configure the ANDROID_HOME environment variable

+ +The React Native tools require some environment variables to be set up in order to build apps with native code. + +Add the following lines to your `~/.zprofile` or `~/.zshrc` (if you are using `bash`, then `~/.bash_profile` or `~/.bashrc`) config file: + +```shell +export ANDROID_HOME=$HOME/Library/Android/sdk +export PATH=$PATH:$ANDROID_HOME/emulator +export PATH=$PATH:$ANDROID_HOME/platform-tools +``` + +Run `source ~/.zprofile` (or `source ~/.bash_profile` for `bash`) to load the config into your current shell. Verify that ANDROID_HOME has been set by running `echo $ANDROID_HOME` and the appropriate directories have been added to your path by running `echo $PATH`. + +> Please make sure you use the correct Android SDK path. You can find the actual location of the SDK in the Android Studio "Settings" dialog, under **Languages & Frameworks** → **Android SDK**. + +

React Native Command Line Interface

+ +React Native has a built-in command line interface. Rather than install and manage a specific version of the CLI globally, we recommend you access the current version at runtime using `npx`, which ships with Node.js. With `npx react-native `, the current stable version of the CLI will be downloaded and executed at the time the command is run. + +

Creating a new application

+ + + +React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using `npx`, which ships with Node.js. Let's create a new React Native project called "AwesomeProject": + +```shell +npx react-native@latest init AwesomeProject +``` + +This is not necessary if you are integrating React Native into an existing application, if you "ejected" from Expo, or if you're adding Android support to an existing React Native project (see [Integration with Existing Apps](integration-with-existing-apps.md)). You can also use a third-party CLI to init your React Native app, such as [Ignite CLI](/~https://github.com/infinitered/ignite). + +

[Optional] Using a specific version or template

+ +If you want to start a new project with a specific React Native version, you can use the `--version` argument: + +```shell +npx react-native@X.XX.X init AwesomeProject --version X.XX.X +``` + +You can also start a project with a custom React Native template with the `--template` argument. + +

Preparing the Android device

+ +You will need an Android device to run your React Native Android app. This can be either a physical Android device, or more commonly, you can use an Android Virtual Device which allows you to emulate an Android device on your computer. + +Either way, you will need to prepare the device to run Android apps for development. + +

Using a physical device

+ +If you have a physical Android device, you can use it for development in place of an AVD by plugging it in to your computer using a USB cable and following the instructions [here](running-on-device.md). + +

Using a virtual device

+ +If you use Android Studio to open `./AwesomeProject/android`, you can see the list of available Android Virtual Devices (AVDs) by opening the "AVD Manager" from within Android Studio. Look for an icon that looks like this: + +![Android Studio AVD Manager](/docs/assets/GettingStartedAndroidStudioAVD.png) + +If you have recently installed Android Studio, you will likely need to [create a new AVD](https://developer.android.com/studio/run/managing-avds.html). Select "Create Virtual Device...", then pick any Phone from the list and click "Next", then select the **Tiramisu** API Level 33 image. + +Click "Next" then "Finish" to create your AVD. At this point you should be able to click on the green triangle button next to your AVD to launch it, then proceed to the next step. + +

Running your React Native application

+ +

Step 1: Start Metro

+ +[**Metro**](https://facebook.github.io/metro/) is the JavaScript build tool for React Native. To start the Metro development server, run the following from your project folder: + + + + +```shell +npm start +``` + + + + +```shell +yarn start +``` + + + + +:::note +If you're familiar with web development, Metro is similar to bundlers such as Vite and webpack, but is designed end-to-end for React Native. For instance, Metro uses [Babel](https://babel.dev/) to transform syntax such as JSX into executable JavaScript. +::: + +

Step 2: Start your application

+ + + + +```shell +npm run android +``` + + + + +```shell +yarn android +``` + + + + +If everything is set up correctly, you should see your new app running in your Android emulator shortly. + +![AwesomeProject on Android](/docs/assets/GettingStartedAndroidSuccessMacOS.png) + +This is one way to run your app - you can also run it directly from within Android Studio. + +> If you can't get this to work, see the [Troubleshooting](troubleshooting.md) page. + +

Modifying your app

+ +Now that you have successfully run the app, let's modify it. + +- Open `App.tsx` in your text editor of choice and edit some lines. +- Press the R key twice or select `Reload` from the Dev Menu (Cmd ⌘ + M) to see your changes! + +

That's it!

+ +Congratulations! You've successfully run and modified your first React Native app. + +
+ +

Now what?

+ +- If you want to add this new React Native code to an existing application, check out the [Integration guide](integration-with-existing-apps.md). + +If you're curious to learn more about React Native, check out the [Introduction to React Native](getting-started). diff --git a/website/versioned_docs/version-0.73.0/_getting-started-macos-ios.md b/website/versioned_docs/version-0.73.0/_getting-started-macos-ios.md new file mode 100644 index 00000000000..60db1ec7acc --- /dev/null +++ b/website/versioned_docs/version-0.73.0/_getting-started-macos-ios.md @@ -0,0 +1,182 @@ +import RemoveGlobalCLI from './\_remove-global-cli.md'; +import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants'; + +## Installing dependencies + +You will need Node, Watchman, the React Native command line interface, Xcode and CocoaPods. + +While you can use any editor of your choice to develop your app, you will need to install Xcode in order to set up the necessary tooling to build your React Native app for iOS. + +### Node & Watchman + +We recommend installing Node and Watchman using [Homebrew](https://brew.sh/). Run the following commands in a Terminal after installing Homebrew: + +```shell +brew install node +brew install watchman +``` + +If you have already installed Node on your system, make sure it is Node 18 or newer. + +[Watchman](https://facebook.github.io/watchman) is a tool by Facebook for watching changes in the filesystem. It is highly recommended you install it for better performance. + +### Xcode + +The easiest way to install Xcode is via the [Mac App Store](https://itunes.apple.com/us/app/xcode/id497799835?mt=12). Installing Xcode will also install the iOS Simulator and all the necessary tools to build your iOS app. + +If you have already installed Xcode on your system, make sure it is version 10 or newer. + +#### Command Line Tools + +You will also need to install the Xcode Command Line Tools. Open Xcode, then choose **Settings... (or Preferences...)** from the Xcode menu. Go to the Locations panel and install the tools by selecting the most recent version in the Command Line Tools dropdown. + +![Xcode Command Line Tools](/docs/assets/GettingStartedXcodeCommandLineTools.png) + +#### Installing an iOS Simulator in Xcode + +To install a simulator, open **Xcode > Settings... (or Preferences...)** and select the **Platforms (or Components)** tab. Select a simulator with the corresponding version of iOS you wish to use. + +If you are using Xcode version 14.0 or greater than to install a simulator, open **Xcode > Settings > Platforms** tab, then click "+" icon and select **iOS…** option. + +#### CocoaPods + +[CocoaPods](https://cocoapods.org/) is one of the dependency management system available for iOS. CocoaPods is a Ruby [gem](https://en.wikipedia.org/wiki/RubyGems). You can install CocoaPods using the version of Ruby that ships with the latest version of macOS. + +For more information, please visit [CocoaPods Getting Started guide](https://guides.cocoapods.org/using/getting-started.html). + +### React Native Command Line Interface + +React Native has a built-in command line interface. Rather than install and manage a specific version of the CLI globally, we recommend you access the current version at runtime using `npx`, which ships with Node.js. With `npx react-native `, the current stable version of the CLI will be downloaded and executed at the time the command is run. + +## Creating a new application + + + +You can use React Native's built-in command line interface to generate a new project. Let's create a new React Native project called "AwesomeProject": + +```shell +npx react-native@latest init AwesomeProject +``` + +This is not necessary if you are integrating React Native into an existing application, if you "ejected" from Expo, or if you're adding iOS support to an existing React Native project (see [Integration with Existing Apps](integration-with-existing-apps.md)). You can also use a third-party CLI to init your React Native app, such as [Ignite CLI](/~https://github.com/infinitered/ignite). + +:::info + +If you are having trouble with iOS, try to reinstall the dependencies by running: + +1. `cd ios` to navigate to the `ios` folder. +2. `bundle install` to install [Bundler](https://bundler.io/) +3. `bundle exec pod install` to install the iOS dependencies managed by CocoaPods. + +::: + +### [Optional] Using a specific version or template + +If you want to start a new project with a specific React Native version, you can use the `--version` argument: + +```shell +npx react-native@X.XX.X init AwesomeProject --version X.XX.X +``` + +You can also start a project with a custom React Native template with the `--template` argument. + +> **Note** If the above command is failing, you may have old version of `react-native` or `react-native-cli` installed globally on your pc. Try uninstalling the cli and run the cli using `npx`. + +### [Optional] Configuring your environment + +Starting from React Native version 0.69, it is possible to configure the Xcode environment using the `.xcode.env` file provided by the template. + +The `.xcode.env` file contains an environment variable to export the path to the `node` executable in the `NODE_BINARY` variable. +This is the **suggested approach** to decouple the build infrastructure from the system version of `node`. You should customize this variable with your own path or your own `node` version manager, if it differs from the default. + +On top of this, it's possible to add any other environment variable and to source the `.xcode.env` file in your build script phases. If you need to run script that requires some specific environment, this is the **suggested approach**: it allows to decouple the build phases from a specific environment. + +:::info +If you are already using [NVM](https://nvm.sh/) (a command which helps you install and switch between versions of Node.js) and [zsh](https://ohmyz.sh/), you might want to move the code that initialize NVM from your `~/.zshrc` into a `~/.zshenv` file to help Xcode find your Node executable: + +```zsh +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm +``` + +You might also want to ensure that all "shell script build phase" of your Xcode project, is using `/bin/zsh` as its shell. +::: + +## Running your React Native application + +### Step 1: Start Metro + +[**Metro**](https://facebook.github.io/metro/) is the JavaScript build tool for React Native. To start the Metro development server, run the following from your project folder: + + + + +```shell +npm start +``` + + + + +```shell +yarn start +``` + + + + +:::note +If you're familiar with web development, Metro is similar to bundlers such as Vite and webpack, but is designed end-to-end for React Native. For instance, Metro uses [Babel](https://babel.dev/) to transform syntax such as JSX into executable JavaScript. +::: + +### Step 2: Start your application + +Let Metro Bundler run in its own terminal. Open a new terminal inside your React Native project folder. Run the following: + + + + +```shell +npm run ios +``` + + + + +```shell +yarn ios +``` + + + + +You should see your new app running in the iOS Simulator shortly. + +![AwesomeProject on iOS](/docs/assets/GettingStartediOSSuccess.png) + +This is one way to run your app. You can also run it directly from within Xcode. + +> If you can't get this to work, see the [Troubleshooting](troubleshooting.md) page. + +### Running on a device + +The above command will automatically run your app on the iOS Simulator by default. If you want to run the app on an actual physical iOS device, please follow the instructions [here](running-on-device.md). + +### Modifying your app + +Now that you have successfully run the app, let's modify it. + +- Open `App.tsx` in your text editor of choice and edit some lines. +- Hit Cmd ⌘ + R in your iOS Simulator to reload the app and see your changes! + +### That's it! + +Congratulations! You've successfully run and modified your first React Native app. + +
+ +## Now what? + +- If you want to add this new React Native code to an existing application, check out the [Integration guide](integration-with-existing-apps.md). + +If you're curious to learn more about React Native, check out the [Introduction to React Native](getting-started). diff --git a/website/versioned_docs/version-0.73.0/_getting-started-windows-android.md b/website/versioned_docs/version-0.73.0/_getting-started-windows-android.md new file mode 100644 index 00000000000..a9c01a46846 --- /dev/null +++ b/website/versioned_docs/version-0.73.0/_getting-started-windows-android.md @@ -0,0 +1,229 @@ +import RemoveGlobalCLI from './\_remove-global-cli.md'; +import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants'; + +

Installing dependencies

+ +You will need Node, the React Native command line interface, a JDK, and Android Studio. + +While you can use any editor of your choice to develop your app, you will need to install Android Studio in order to set up the necessary tooling to build your React Native app for Android. + +

Node, JDK

+ +We recommend installing Node via [Chocolatey](https://chocolatey.org/install), a popular package manager for Windows. + +It is recommended to use an LTS version of Node. If you want to be able to switch between different versions, you might want to install Node via [nvm-windows](/~https://github.com/coreybutler/nvm-windows), a Node version manager for Windows. + +React Native also requires [Java SE Development Kit (JDK)](https://openjdk.java.net/projects/jdk/17/), which can be installed using Chocolatey as well. + +Open an Administrator Command Prompt (right click Command Prompt and select "Run as Administrator"), then run the following command: + +```powershell +choco install -y nodejs-lts microsoft-openjdk17 +``` + +If you have already installed Node on your system, make sure it is Node 18 or newer. If you already have a JDK on your system, we recommend JDK17. You may encounter problems using higher JDK versions. + +> You can find additional installation options on [Node's Downloads page](https://nodejs.org/en/download/). + +> If you're using the latest version of Java Development Kit, you'll need to change the Gradle version of your project so it can recognize the JDK. You can do that by going to `{project root folder}\android\gradle\wrapper\gradle-wrapper.properties` and changing the `distributionUrl` value to upgrade the Gradle version. You can check out [here the latest releases of Gradle](https://gradle.org/releases/). + +

Android development environment

+ +Setting up your development environment can be somewhat tedious if you're new to Android development. If you're already familiar with Android development, there are a few things you may need to configure. In either case, please make sure to carefully follow the next few steps. + +

1. Install Android Studio

+ +[Download and install Android Studio](https://developer.android.com/studio/index.html). While on Android Studio installation wizard, make sure the boxes next to all of the following items are checked: + +- `Android SDK` +- `Android SDK Platform` +- `Android Virtual Device` +- If you are not already using Hyper-V: `Performance (Intel ® HAXM)` ([See here for AMD or Hyper-V](https://android-developers.googleblog.com/2018/07/android-emulator-amd-processor-hyper-v.html)) + +Then, click "Next" to install all of these components. + +> If the checkboxes are grayed out, you will have a chance to install these components later on. + +Once setup has finalized and you're presented with the Welcome screen, proceed to the next step. + +

2. Install the Android SDK

+ +Android Studio installs the latest Android SDK by default. Building a React Native app with native code, however, requires the `Android 13 (Tiramisu)` SDK in particular. Additional Android SDKs can be installed through the SDK Manager in Android Studio. + +To do that, open Android Studio, click on "More Actions" button and select "SDK Manager". + +![Android Studio Welcome](/docs/assets/GettingStartedAndroidStudioWelcomeWindows.png) + +> The SDK Manager can also be found within the Android Studio "Settings" dialog, under **Languages & Frameworks** → **Android SDK**. + +Select the "SDK Platforms" tab from within the SDK Manager, then check the box next to "Show Package Details" in the bottom right corner. Look for and expand the `Android 13 (Tiramisu)` entry, then make sure the following items are checked: + +- `Android SDK Platform 33` +- `Intel x86 Atom_64 System Image` or `Google APIs Intel x86 Atom System Image` + +Next, select the "SDK Tools" tab and check the box next to "Show Package Details" here as well. Look for and expand the `Android SDK Build-Tools` entry, then make sure that `33.0.0` is selected. + +Finally, click "Apply" to download and install the Android SDK and related build tools. + +

3. Configure the ANDROID_HOME environment variable

+ +The React Native tools require some environment variables to be set up in order to build apps with native code. + +1. Open the **Windows Control Panel.** +2. Click on **User Accounts,** then click **User Accounts** again +3. Click on **Change my environment variables** +4. Click on **New...** to create a new `ANDROID_HOME` user variable that points to the path to your Android SDK: + +![ANDROID_HOME Environment Variable](/docs/assets/GettingStartedAndroidEnvironmentVariableANDROID_HOME.png) + +The SDK is installed, by default, at the following location: + +```powershell +%LOCALAPPDATA%\Android\Sdk +``` + +You can find the actual location of the SDK in the Android Studio "Settings" dialog, under **Languages & Frameworks** → **Android SDK**. + +Open a new Command Prompt window to ensure the new environment variable is loaded before proceeding to the next step. + +1. Open powershell +2. Copy and paste **Get-ChildItem -Path Env:\\** into powershell +3. Verify `ANDROID_HOME` has been added + +

4. Add platform-tools to Path

+ +1. Open the **Windows Control Panel.** +2. Click on **User Accounts,** then click **User Accounts** again +3. Click on **Change my environment variables** +4. Select the **Path** variable. +5. Click **Edit.** +6. Click **New** and add the path to platform-tools to the list. + +The default location for this folder is: + +```powershell +%LOCALAPPDATA%\Android\Sdk\platform-tools +``` + +

React Native Command Line Interface

+ +React Native has a built-in command line interface. Rather than install and manage a specific version of the CLI globally, we recommend you access the current version at runtime using `npx`, which ships with Node.js. With `npx react-native `, the current stable version of the CLI will be downloaded and executed at the time the command is run. + +

Creating a new application

+ + + +React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using `npx`, which ships with Node.js. Let's create a new React Native project called "AwesomeProject": + +```shell +npx react-native@latest init AwesomeProject +``` + +This is not necessary if you are integrating React Native into an existing application, if you "ejected" from Expo, or if you're adding Android support to an existing React Native project (see [Integration with Existing Apps](integration-with-existing-apps.md)). You can also use a third-party CLI to init your React Native app, such as [Ignite CLI](/~https://github.com/infinitered/ignite). + +

[Optional] Using a specific version or template

+ +If you want to start a new project with a specific React Native version, you can use the `--version` argument: + +```shell +npx react-native@X.XX.X init AwesomeProject --version X.XX.X +``` + +You can also start a project with a custom React Native template with the `--template` argument. + +

Preparing the Android device

+ +You will need an Android device to run your React Native Android app. This can be either a physical Android device, or more commonly, you can use an Android Virtual Device which allows you to emulate an Android device on your computer. + +Either way, you will need to prepare the device to run Android apps for development. + +

Using a physical device

+ +If you have a physical Android device, you can use it for development in place of an AVD by plugging it in to your computer using a USB cable and following the instructions [here](running-on-device.md). + +

Using a virtual device

+ +If you use Android Studio to open `./AwesomeProject/android`, you can see the list of available Android Virtual Devices (AVDs) by opening the "AVD Manager" from within Android Studio. Look for an icon that looks like this: + +![Android Studio AVD Manager](/docs/assets/GettingStartedAndroidStudioAVD.png) + +If you have recently installed Android Studio, you will likely need to [create a new AVD](https://developer.android.com/studio/run/managing-avds.html). Select "Create Virtual Device...", then pick any Phone from the list and click "Next", then select the **Tiramisu** API Level 33 image. + +> If you don't have HAXM installed, click on "Install HAXM" or follow [these instructions](/~https://github.com/intel/haxm/wiki/Installation-Instructions-on-Windows) to set it up, then go back to the AVD Manager. + +Click "Next" then "Finish" to create your AVD. At this point you should be able to click on the green triangle button next to your AVD to launch it, then proceed to the next step. + +

Running your React Native application

+ +

Step 1: Start Metro

+ +[**Metro**](https://facebook.github.io/metro/) is the JavaScript build tool for React Native. To start the Metro development server, run the following from your project folder: + + + + +```shell +npm start +``` + + + + +```shell +yarn start +``` + + + + +:::note +If you're familiar with web development, Metro is similar to bundlers such as Vite and webpack, but is designed end-to-end for React Native. For instance, Metro uses [Babel](https://babel.dev/) to transform syntax such as JSX into executable JavaScript. +::: + +

Step 2: Start your application

+ +Let Metro Bundler run in its own terminal. Open a new terminal inside your React Native project folder. Run the following: + + + + +```shell +npm run android +``` + + + + +```shell +yarn android +``` + + + + +If everything is set up correctly, you should see your new app running in your Android emulator shortly. + +![AwesomeProject on Android](/docs/assets/GettingStartedAndroidSuccessWindows.png) + +This is one way to run your app - you can also run it directly from within Android Studio. + +> If you can't get this to work, see the [Troubleshooting](troubleshooting.md) page. + +

Modifying your app

+ +Now that you have successfully run the app, let's modify it. + +- Open `App.tsx` in your text editor of choice and edit some lines. +- Press the R key twice or select `Reload` from the Dev Menu (Ctrl + M) to see your changes! + +

That's it!

+ +Congratulations! You've successfully run and modified your first React Native app. + +
+ +

Now what?

+ +- If you want to add this new React Native code to an existing application, check out the [Integration guide](integration-with-existing-apps.md). + +If you're curious to learn more about React Native, check out the [Introduction to React Native](getting-started). diff --git a/website/versioned_docs/version-0.73.0/_integration-with-existing-apps-java.md b/website/versioned_docs/version-0.73.0/_integration-with-existing-apps-java.md new file mode 100644 index 00000000000..af77483cebe --- /dev/null +++ b/website/versioned_docs/version-0.73.0/_integration-with-existing-apps-java.md @@ -0,0 +1,443 @@ +import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants'; + +## Key Concepts + +The keys to integrating React Native components into your Android application are to: + +1. Set up React Native dependencies and directory structure. +2. Develop your React Native components in JavaScript. +3. Add a `ReactRootView` to your Android app. This view will serve as the container for your React Native component. +4. Start the React Native server and run your native application. +5. Verify that the React Native aspect of your application works as expected. + +## Prerequisites + +Follow the React Native CLI Quickstart in the [environment setup guide](environment-setup) to configure your development environment for building React Native apps for Android. + +### 1. Set up directory structure + +To ensure a smooth experience, create a new folder for your integrated React Native project, then copy your existing Android project to an `/android` subfolder. + +### 2. Install JavaScript dependencies + +Go to the root directory for your project and create a new `package.json` file with the following contents: + +``` +{ + "name": "MyReactNativeApp", + "version": "0.0.1", + "private": true, + "scripts": { + "start": "react-native start" + } +} +``` + +Next, install the `react` and `react-native` packages. Open a terminal or command prompt, then navigate to the directory with your `package.json` file and run: + + + + +```shell +npm install react-native +``` + + + + +```shell +yarn add react-native +``` + + + + +This will print a message similar to the following (scroll up in the yarn output to see it): + +> warning "`react-native@0.70.5`" has unmet peer dependency "`react@18.1.0`" + +This is OK, it means we also need to install React: + + + + +```shell +npm install react@version_printed_above +``` + + + + +```shell +yarn add react@version_printed_above +``` + + + + +Yarn has created a new `/node_modules` folder. This folder stores all the JavaScript dependencies required to build your project. + +Add `node_modules/` to your `.gitignore` file. + +## Adding React Native to your app + +### Configuring Gradle + +React Native uses the React Native Gradle Plugin to configure your dependencies and project setup. + +First, let's edit your `settings.gradle` file by adding this line: + +```groovy +includeBuild('../node_modules/@react-native/gradle-plugin') +``` + +Then you need to open your top level `build.gradle` and include this line: + +```diff +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath("com.android.tools.build:gradle:7.3.1") ++ classpath("com.facebook.react:react-native-gradle-plugin") + } +} +``` + +This makes sure the React Native Gradle Plugin is available inside your project. +Finally, add those lines inside your app's `build.gradle` file (it's a different `build.gradle` file inside your app folder): + +```diff +apply plugin: "com.android.application" ++apply plugin: "com.facebook.react" + +repositories { + mavenCentral() +} + +dependencies { + // Other dependencies here ++ implementation "com.facebook.react:react-android" ++ implementation "com.facebook.react:hermes-android" +} +``` + +Those depedencies are available on `mavenCentral()` so make sure you have it defined in your `repositories{}` block. + +:::info +We intentionally don't specify the version for those `implementation` dependencies as the React Native Gradle Plugin will take care of it. If you don't use the React Native Gradle Plugin, you'll have to specify version manually. +::: + +### Enable native modules autolinking + +To use the power of [autolinking](/~https://github.com/react-native-community/cli/blob/master/docs/autolinking.md), we have to apply it a few places. First add the following entry to `settings.gradle`: + +```gradle +apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) +``` + +Next add the following entry at the very bottom of the `app/build.gradle`: + +```gradle +apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) +``` + +### Configuring permissions + +Next, make sure you have the Internet permission in your `AndroidManifest.xml`: + +```xml + +``` + +If you need to access to the `DevSettingsActivity` add to your `AndroidManifest.xml`: + +```xml + +``` + +This is only used in dev mode when reloading JavaScript from the development server, so you can strip this in release builds if you need to. + +### Cleartext Traffic (API level 28+) + +> Starting with Android 9 (API level 28), cleartext traffic is disabled by default; this prevents your application from connecting to the [Metro bundler][metro]. The changes below allow cleartext traffic in debug builds. + +#### 1. Apply the `usesCleartextTraffic` option to your Debug `AndroidManifest.xml` + +```xml + + + + + +``` + +This is not required for Release builds. + +To learn more about Network Security Config and the cleartext traffic policy [see this link](https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted). + +### Code integration + +Now we will actually modify the native Android application to integrate React Native. + +#### The React Native component + +The first bit of code we will write is the actual React Native code for the new "High Score" screen that will be integrated into our application. + +##### 1. Create a `index.js` file + +First, create an empty `index.js` file in the root of your React Native project. + +`index.js` is the starting point for React Native applications, and it is always required. It can be a small file that `require`s other file that are part of your React Native component or application, or it can contain all the code that is needed for it. In our case, we will put everything in `index.js`. + +##### 2. Add your React Native code + +In your `index.js`, create your component. In our sample here, we will add a `` component within a styled ``: + +```jsx +import React from 'react'; +import {AppRegistry, StyleSheet, Text, View} from 'react-native'; + +const HelloWorld = () => { + return ( + + Hello, World + + ); +}; +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + }, + hello: { + fontSize: 20, + textAlign: 'center', + margin: 10, + }, +}); + +AppRegistry.registerComponent( + 'MyReactNativeApp', + () => HelloWorld, +); +``` + +##### 3. Configure permissions for development error overlay + +If your app is targeting the Android `API level 23` or greater, make sure you have the permission `android.permission.SYSTEM_ALERT_WINDOW` enabled for the development build. You can check this with `Settings.canDrawOverlays(this);`. This is required in dev builds because React Native development errors must be displayed above all the other windows. Due to the new permissions system introduced in the API level 23 (Android M), the user needs to approve it. This can be achieved by adding the following code to your Activity's in `onCreate()` method. + +```java +private final int OVERLAY_PERMISSION_REQ_CODE = 1; // Choose any value + +... + +if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!Settings.canDrawOverlays(this)) { + Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, + Uri.parse("package:" + getPackageName())); + startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); + } +} +``` + +Finally, the `onActivityResult()` method (as shown in the code below) has to be overridden to handle the permission Accepted or Denied cases for consistent UX. Also, for integrating Native Modules which use `startActivityForResult`, we need to pass the result to the `onActivityResult` method of our `ReactInstanceManager` instance. + +```java +@Override +protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!Settings.canDrawOverlays(this)) { + // SYSTEM_ALERT_WINDOW permission not granted + } + } + } + mReactInstanceManager.onActivityResult( this, requestCode, resultCode, data ); +} +``` + +#### The Magic: `ReactRootView` + +Let's add some native code in order to start the React Native runtime and tell it to render our JS component. To do this, we're going to create an `Activity` that creates a `ReactRootView`, starts a React application inside it and sets it as the main content view. + +> If you are targeting Android version <5, use the `AppCompatActivity` class from the `com.android.support:appcompat` package instead of `Activity`. + +```java +public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler { + private ReactRootView mReactRootView; + private ReactInstanceManager mReactInstanceManager; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + SoLoader.init(this, false); + + mReactRootView = new ReactRootView(this); + List packages = new PackageList(getApplication()).getPackages(); + // Packages that cannot be autolinked yet can be added manually here, for example: + // packages.add(new MyReactNativePackage()); + // Remember to include them in `settings.gradle` and `app/build.gradle` too. + + mReactInstanceManager = ReactInstanceManager.builder() + .setApplication(getApplication()) + .setCurrentActivity(this) + .setBundleAssetName("index.android.bundle") + .setJSMainModulePath("index") + .addPackages(packages) + .setUseDeveloperSupport(BuildConfig.DEBUG) + .setInitialLifecycleState(LifecycleState.RESUMED) + .build(); + // The string here (e.g. "MyReactNativeApp") has to match + // the string in AppRegistry.registerComponent() in index.js + mReactRootView.startReactApplication(mReactInstanceManager, "MyReactNativeApp", null); + + setContentView(mReactRootView); + } + + @Override + public void invokeDefaultOnBackPressed() { + super.onBackPressed(); + } +} +``` + +> If you are using a starter kit for React Native, replace the "HelloWorld" string with the one in your index.js file (it’s the first argument to the `AppRegistry.registerComponent()` method). + +Perform a “Sync Project files with Gradle” operation. + +If you are using Android Studio, use `Alt + Enter` to add all missing imports in your MyReactActivity class. Be careful to use your package’s `BuildConfig` and not the one from the `facebook` package. + +We need set the theme of `MyReactActivity` to `Theme.AppCompat.Light.NoActionBar` because some React Native UI components rely on this theme. + +```xml + + +``` + +> A `ReactInstanceManager` can be shared by multiple activities and/or fragments. You will want to make your own `ReactFragment` or `ReactActivity` and have a singleton _holder_ that holds a `ReactInstanceManager`. When you need the `ReactInstanceManager` (e.g., to hook up the `ReactInstanceManager` to the lifecycle of those Activities or Fragments) use the one provided by the singleton. + +Next, we need to pass some activity lifecycle callbacks to the `ReactInstanceManager` and `ReactRootView`: + +```java +@Override +protected void onPause() { + super.onPause(); + + if (mReactInstanceManager != null) { + mReactInstanceManager.onHostPause(this); + } +} + +@Override +protected void onResume() { + super.onResume(); + + if (mReactInstanceManager != null) { + mReactInstanceManager.onHostResume(this, this); + } +} + +@Override +protected void onDestroy() { + super.onDestroy(); + + if (mReactInstanceManager != null) { + mReactInstanceManager.onHostDestroy(this); + } + if (mReactRootView != null) { + mReactRootView.unmountReactApplication(); + } +} +``` + +We also need to pass back button events to React Native: + +```java +@Override + public void onBackPressed() { + if (mReactInstanceManager != null) { + mReactInstanceManager.onBackPressed(); + } else { + super.onBackPressed(); + } +} +``` + +This allows JavaScript to control what happens when the user presses the hardware back button (e.g. to implement navigation). When JavaScript doesn't handle the back button press, your `invokeDefaultOnBackPressed` method will be called. By default this finishes your `Activity`. + +Finally, we need to hook up the dev menu. By default, this is activated by (rage) shaking the device, but this is not very useful in emulators. So we make it show when you press the hardware menu button (use Ctrl + M if you're using Android Studio emulator): + +```java +@Override +public boolean onKeyUp(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) { + mReactInstanceManager.showDevOptionsDialog(); + return true; + } + return super.onKeyUp(keyCode, event); +} +``` + +Now your activity is ready to run some JavaScript code. + +### Test your integration + +You have now done all the basic steps to integrate React Native with your current application. Now we will start the [Metro bundler][metro] to build the `index.bundle` package and the server running on localhost to serve it. + +##### 1. Run the packager + +To run your app, you need to first start the development server. To do this, run the following command in the root directory of your React Native project: + + + + +```shell +npm start +``` + + + + +```shell +yarn start +``` + + + + +##### 2. Run the app + +Now build and run your Android app as normal. + +Once you reach your React-powered activity inside the app, it should load the JavaScript code from the development server and display: + +![Screenshot](/docs/assets/EmbeddedAppAndroid.png) + +### Creating a release build in Android Studio + +You can use Android Studio to create your release builds too! It’s as quick as creating release builds of your previously-existing native Android app. + +If you use the React Native Gradle Plugin as described above, everything should work when running app from Android Studio. + +If you're not using the React Native Gradle Plugin, there’s one additional step which you’ll have to do before every release build. You need to execute the following to create a React Native bundle, which will be included with your native Android app: + +```shell +$ npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/com/your-company-name/app-package-name/src/main/assets/index.android.bundle --assets-dest android/com/your-company-name/app-package-name/src/main/res/ +``` + +> Don’t forget to replace the paths with correct ones and create the assets folder if it doesn’t exist. + +Now, create a release build of your native app from within Android Studio as usual and you should be good to go! + +### Now what? + +At this point you can continue developing your app as usual. Refer to our [debugging](debugging) and [deployment](running-on-device) docs to learn more about working with React Native. + +[metro]: https://facebook.github.io/metro/ diff --git a/website/versioned_docs/version-0.73.0/_integration-with-existing-apps-kotlin.md b/website/versioned_docs/version-0.73.0/_integration-with-existing-apps-kotlin.md new file mode 100644 index 00000000000..a43d9e261e4 --- /dev/null +++ b/website/versioned_docs/version-0.73.0/_integration-with-existing-apps-kotlin.md @@ -0,0 +1,419 @@ +import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants'; + +## Key Concepts + +The keys to integrating React Native components into your Android application are to: + +1. Set up React Native dependencies and directory structure. +2. Develop your React Native components in JavaScript. +3. Add a `ReactRootView` to your Android app. This view will serve as the container for your React Native component. +4. Start the React Native server and run your native application. +5. Verify that the React Native aspect of your application works as expected. + +## Prerequisites + +Follow the React Native CLI Quickstart in the [environment setup guide](environment-setup) to configure your development environment for building React Native apps for Android. + +### 1. Set up directory structure + +To ensure a smooth experience, create a new folder for your integrated React Native project, then copy your existing Android project to an `/android` subfolder. + +### 2. Install JavaScript dependencies + +Go to the root directory for your project and create a new `package.json` file with the following contents: + +``` +{ + "name": "MyReactNativeApp", + "version": "0.0.1", + "private": true, + "scripts": { + "start": "yarn react-native start" + } +} +``` + +Next, install the `react` and `react-native` packages. Open a terminal or command prompt, then navigate to the directory with your `package.json` file and run: + + + + +```shell +npm install react-native +``` + + + + +```shell +yarn add react-native +``` + + + + +This will print a message similar to the following (scroll up in the yarn output to see it): + +> warning "`react-native@0.70.5`" has unmet peer dependency "`react@18.1.0`" + +This is OK, it means we also need to install React: + + + + +```shell +npm install react@version_printed_above +``` + + + + +```shell +yarn add react@version_printed_above +``` + + + + +Yarn has created a new `/node_modules` folder. This folder stores all the JavaScript dependencies required to build your project. + +Add `node_modules/` to your `.gitignore` file. + +## Adding React Native to your app + +### Configuring Gradle + +React Native uses the React Native Gradle Plugin to configure your dependencies and project setup. + +First, let's edit your `settings.gradle` file by adding this line: + +```groovy +includeBuild('../node_modules/@react-native/gradle-plugin') +``` + +Then you need to open your top level `build.gradle` and include this line: + +```diff +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath("com.android.tools.build:gradle:7.3.1") ++ classpath("com.facebook.react:react-native-gradle-plugin") + } +} +``` + +This makes sure the React Native Gradle Plugin is available inside your project. +Finally, add those lines inside your app's `build.gradle` file (it's a different `build.gradle` file inside your app folder): + +```diff +apply plugin: "com.android.application" ++apply plugin: "com.facebook.react" + +repositories { + mavenCentral() +} + +dependencies { + // Other dependencies here ++ implementation "com.facebook.react:react-android" ++ implementation "com.facebook.react:hermes-android" +} +``` + +Those depedencies are available on `mavenCentral()` so make sure you have it defined in your `repositories{}` block. + +:::info +We intentionally don't specify the version for those `implementation` dependencies as the React Native Gradle Plugin will take care of it. If you don't use the React Native Gradle Plugin, you'll have to specify version manually. +::: + +### Enable native modules autolinking + +To use the power of [autolinking](/~https://github.com/react-native-community/cli/blob/master/docs/autolinking.md), we have to apply it a few places. First add the following entry to `settings.gradle`: + +```gradle +apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) +``` + +Next add the following entry at the very bottom of the `app/build.gradle`: + +```gradle +apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) +``` + +### Configuring permissions + +Next, make sure you have the Internet permission in your `AndroidManifest.xml`: + +```xml + +``` + +If you need to access to the `DevSettingsActivity` add to your `AndroidManifest.xml`: + +```xml + +``` + +This is only used in dev mode when reloading JavaScript from the development server, so you can strip this in release builds if you need to. + +### Cleartext Traffic (API level 28+) + +> Starting with Android 9 (API level 28), cleartext traffic is disabled by default; this prevents your application from connecting to the [Metro bundler][metro]. The changes below allow cleartext traffic in debug builds. + +#### 1. Apply the `usesCleartextTraffic` option to your Debug `AndroidManifest.xml` + +```xml + + + + + +``` + +This is not required for Release builds. + +To learn more about Network Security Config and the cleartext traffic policy [see this link](https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted). + +### Code integration + +Now we will actually modify the native Android application to integrate React Native. + +#### The React Native component + +The first bit of code we will write is the actual React Native code for the new "High Score" screen that will be integrated into our application. + +##### 1. Create a `index.js` file + +First, create an empty `index.js` file in the root of your React Native project. + +`index.js` is the starting point for React Native applications, and it is always required. It can be a small file that `require`s other file that are part of your React Native component or application, or it can contain all the code that is needed for it. In our case, we will put everything in `index.js`. + +##### 2. Add your React Native code + +In your `index.js`, create your component. In our sample here, we will add a `` component within a styled ``: + +```jsx +import React from 'react'; +import {AppRegistry, StyleSheet, Text, View} from 'react-native'; + +const HelloWorld = () => { + return ( + + Hello, World + + ); +}; +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + }, + hello: { + fontSize: 20, + textAlign: 'center', + margin: 10, + }, +}); + +AppRegistry.registerComponent( + 'MyReactNativeApp', + () => HelloWorld, +); +``` + +##### 3. Configure permissions for development error overlay + +If your app is targeting the Android `API level 23` or greater, make sure you have the permission `android.permission.SYSTEM_ALERT_WINDOW` enabled for the development build. You can check this with `Settings.canDrawOverlays(this)`. This is required in dev builds because React Native development errors must be displayed above all the other windows. Due to the new permissions system introduced in the API level 23 (Android M), the user needs to approve it. This can be achieved by adding the following code to your Activity's in `onCreate()` method. + +```kotlin +companion object { + const val OVERLAY_PERMISSION_REQ_CODE = 1 // Choose any value +} + +... + +if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if(!Settings.canDrawOverlays(this)) { + val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, + Uri.parse("package: $packageName")) + startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); + } +} +``` + +Finally, the `onActivityResult()` method (as shown in the code below) has to be overridden to handle the permission Accepted or Denied cases for consistent UX. Also, for integrating Native Modules which use `startActivityForResult`, we need to pass the result to the `onActivityResult` method of our `ReactInstanceManager` instance. + +```kotlin +override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!Settings.canDrawOverlays(this)) { + // SYSTEM_ALERT_WINDOW permission not granted + } + } + } + reactInstanceManager?.onActivityResult(this, requestCode, resultCode, data) +} +``` + +#### The Magic: `ReactRootView` + +Let's add some native code in order to start the React Native runtime and tell it to render our JS component. To do this, we're going to create an `Activity` that creates a `ReactRootView`, starts a React application inside it and sets it as the main content view. + +> If you are targeting Android version <5, use the `AppCompatActivity` class from the `com.android.support:appcompat` package instead of `Activity`. + +```kotlin +class MyReactActivity : Activity(), DefaultHardwareBackBtnHandler { + private lateinit var reactRootView: ReactRootView + private lateinit var reactInstanceManager: ReactInstanceManager + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + SoLoader.init(this, false) + reactRootView = ReactRootView(this) + val packages: List = PackageList(application).packages + // Packages that cannot be autolinked yet can be added manually here, for example: + // packages.add(MyReactNativePackage()) + // Remember to include them in `settings.gradle` and `app/build.gradle` too. + reactInstanceManager = ReactInstanceManager.builder() + .setApplication(application) + .setCurrentActivity(this) + .setBundleAssetName("index.android.bundle") + .setJSMainModulePath("index") + .addPackages(packages) + .setUseDeveloperSupport(BuildConfig.DEBUG) + .setInitialLifecycleState(LifecycleState.RESUMED) + .build() + // The string here (e.g. "MyReactNativeApp") has to match + // the string in AppRegistry.registerComponent() in index.js + reactRootView?.startReactApplication(reactInstanceManager, "MyReactNativeApp", null) + setContentView(reactRootView) + } + + override fun invokeDefaultOnBackPressed() { + super.onBackPressed() + } +} +``` + +> If you are using a starter kit for React Native, replace the "HelloWorld" string with the one in your index.js file (it’s the first argument to the `AppRegistry.registerComponent()` method). + +Perform a “Sync Project files with Gradle” operation. + +If you are using Android Studio, use `Alt + Enter` to add all missing imports in your MyReactActivity class. Be careful to use your package’s `BuildConfig` and not the one from the `facebook` package. + +We need set the theme of `MyReactActivity` to `Theme.AppCompat.Light.NoActionBar` because some React Native UI components rely on this theme. + +```xml + + +``` + +> A `ReactInstanceManager` can be shared by multiple activities and/or fragments. You will want to make your own `ReactFragment` or `ReactActivity` and have a singleton _holder_ that holds a `ReactInstanceManager`. When you need the `ReactInstanceManager` (e.g., to hook up the `ReactInstanceManager` to the lifecycle of those Activities or Fragments) use the one provided by the singleton. + +Next, we need to pass some activity lifecycle callbacks to the `ReactInstanceManager` and `ReactRootView`: + +```kotlin +override fun onPause() { + super.onPause() + reactInstanceManager.onHostPause(this) +} + +override fun onResume() { + super.onResume() + reactInstanceManager.onHostResume(this, this) +} + +override fun onDestroy() { + super.onDestroy() + reactInstanceManager.onHostDestroy(this) + reactRootView.unmountReactApplication() +} +``` + +We also need to pass back button events to React Native: + +```kotlin +override fun onBackPressed() { + reactInstanceManager.onBackPressed() + super.onBackPressed() +} +``` + +This allows JavaScript to control what happens when the user presses the hardware back button (e.g. to implement navigation). When JavaScript doesn't handle the back button press, your `invokeDefaultOnBackPressed` method will be called. By default this finishes your `Activity`. + +Finally, we need to hook up the dev menu. By default, this is activated by (rage) shaking the device, but this is not very useful in emulators. So we make it show when you press the hardware menu button (use Ctrl + M if you're using Android Studio emulator): + +```kotlin +override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean { + if (keyCode == KeyEvent.KEYCODE_MENU && reactInstanceManager != null) { + reactInstanceManager.showDevOptionsDialog() + return true + } + return super.onKeyUp(keyCode, event) +} +``` + +Now your activity is ready to run some JavaScript code. + +### Test your integration + +You have now done all the basic steps to integrate React Native with your current application. Now we will start the [Metro bundler][metro] to build the `index.bundle` package and the server running on localhost to serve it. + +##### 1. Run the packager + +To run your app, you need to first start the development server. To do this, run the following command in the root directory of your React Native project: + + + + +```shell +npm start +``` + + + + +```shell +yarn start +``` + + + + +##### 2. Run the app + +Now build and run your Android app as normal. + +Once you reach your React-powered activity inside the app, it should load the JavaScript code from the development server and display: + +![Screenshot](/docs/assets/EmbeddedAppAndroid.png) + +### Creating a release build in Android Studio + +You can use Android Studio to create your release builds too! It’s as quick as creating release builds of your previously-existing native Android app. + +If you use the React Native Gradle Plugin as described above, everything should work when running app from Android Studio. + +If you're not using the React Native Gradle Plugin, there’s one additional step which you’ll have to do before every release build. You need to execute the following to create a React Native bundle, which will be included with your native Android app: + +```shell +$ npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/com/your-company-name/app-package-name/src/main/assets/index.android.bundle --assets-dest android/com/your-company-name/app-package-name/src/main/res/ +``` + +> Don’t forget to replace the paths with correct ones and create the assets folder if it doesn’t exist. + +Now, create a release build of your native app from within Android Studio as usual and you should be good to go! + +### Now what? + +At this point you can continue developing your app as usual. Refer to our [debugging](debugging) and [deployment](running-on-device) docs to learn more about working with React Native. + +[metro]: https://facebook.github.io/metro/ diff --git a/website/versioned_docs/version-0.73.0/_integration-with-existing-apps-objc.md b/website/versioned_docs/version-0.73.0/_integration-with-existing-apps-objc.md new file mode 100644 index 00000000000..3b7c0701724 --- /dev/null +++ b/website/versioned_docs/version-0.73.0/_integration-with-existing-apps-objc.md @@ -0,0 +1,403 @@ +import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants'; + +## Key Concepts + +The keys to integrating React Native components into your iOS application are to: + +1. Set up React Native dependencies and directory structure. +2. Understand what React Native components you will use in your app. +3. Add these components as dependencies using CocoaPods. +4. Develop your React Native components in JavaScript. +5. Add a `RCTRootView` to your iOS app. This view will serve as the container for your React Native component. +6. Start the React Native server and run your native application. +7. Verify that the React Native aspect of your application works as expected. + +## Prerequisites + +Follow the React Native CLI Quickstart in the [environment setup guide](environment-setup) to configure your development environment for building React Native apps for iOS. + +### 1. Set up directory structure + +To ensure a smooth experience, create a new folder for your integrated React Native project, then copy your existing iOS project to a `/ios` subfolder. + +### 2. Install JavaScript dependencies + +Go to the root directory for your project and create a new `package.json` file with the following contents: + +``` +{ + "name": "MyReactNativeApp", + "version": "0.0.1", + "private": true, + "scripts": { + "start": "yarn react-native start" + } +} +``` + +Next, make sure you have [installed the yarn package manager](https://yarnpkg.com/lang/en/docs/install/). + +Install the `react` and `react-native` packages. Open a terminal or command prompt, then navigate to the directory with your `package.json` file and run: + + + + +```shell +npm install react-native +``` + + + + +```shell +yarn add react-native +``` + + + + +This will print a message similar to the following (scroll up in the yarn output to see it): + +> warning "`react-native@0.52.2`" has unmet peer dependency "`react@16.2.0`". + +This is OK, it means we also need to install React: + + + + +```shell +npm install react@version_printed_above +``` + + + + +```shell +yarn add react@version_printed_above +``` + + + + +Installation process has created a new `/node_modules` folder. This folder stores all the JavaScript dependencies required to build your project. + +Add `node_modules/` to your `.gitignore` file. + +### 3. Install CocoaPods + +[CocoaPods](https://cocoapods.org) is a package management tool for iOS and macOS development. We use it to add the actual React Native framework code locally into your current project. + +We recommend installing CocoaPods using [Homebrew](https://brew.sh/). + +```shell +brew install cocoapods +``` + +> It is technically possible not to use CocoaPods, but that would require manual library and linker additions that would overly complicate this process. + +## Adding React Native to your app + +Assume the [app for integration](/~https://github.com/JoelMarcey/iOS-2048) is a [2048](https://en.wikipedia.org/wiki/2048_%28video_game%29) game. Here is what the main menu of the native application looks like without React Native. + +![Before RN Integration](/docs/assets/react-native-existing-app-integration-ios-before.png) + +### Command Line Tools for Xcode + +Install the Command Line Tools. Choose **Settings... (or Preferences...)** in the Xcode menu. Go to the Locations panel and install the tools by selecting the most recent version in the Command Line Tools dropdown. + +![Xcode Command Line Tools](/docs/assets/GettingStartedXcodeCommandLineTools.png) + +### Configuring CocoaPods dependencies + +Before you integrate React Native into your application, you will want to decide what parts of the React Native framework you would like to integrate. We will use CocoaPods to specify which of these "subspecs" your app will depend on. + +The list of supported `subspec`s is available in [`/node_modules/react-native/React.podspec`](/~https://github.com/facebook/react-native/blob/main/packages/react-native/React.podspec). They are generally named by functionality. For example, you will generally always want the `Core` `subspec`. That will get you the `AppRegistry`, `StyleSheet`, `View` and other core React Native libraries. If you want to add the React Native `Text` library (e.g., for `` elements), then you will need the `RCTText` `subspec`. If you want the `Image` library (e.g., for `` elements), then you will need the `RCTImage` `subspec`. + +You can specify which `subspec`s your app will depend on in a `Podfile` file. The easiest way to create a `Podfile` is by running the CocoaPods `init` command in the `/ios` subfolder of your project: + +```shell +pod init +``` + +The `Podfile` will contain a boilerplate setup that you will tweak for your integration purposes. + +> The `Podfile` version changes depending on your version of `react-native`. Refer to https://react-native-community.github.io/upgrade-helper/ for the specific version of `Podfile` you should be using. + +Ultimately, your `Podfile` should look something similar to this: + +``` +# The target name is most likely the name of your project. +target 'NumberTileGame' do + + # Your 'node_modules' directory is probably in the root of your project, + # but if not, adjust the `:path` accordingly + pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector" + pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec" + pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired" + pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety" + pod 'React', :path => '../node_modules/react-native/' + pod 'React-Core', :path => '../node_modules/react-native/' + pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules' + pod 'React-Core/DevSupport', :path => '../node_modules/react-native/' + pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS' + pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation' + pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob' + pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image' + pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS' + pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network' + pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings' + pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text' + pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration' + pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/' + + pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact' + pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi' + pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor' + pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector' + pod 'ReactCommon/callinvoker', :path => "../node_modules/react-native/ReactCommon" + pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon" + pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga' + + pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' + pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' + pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' + +end +``` + +After you have created your `Podfile`, you are ready to install the React Native pod. + +```shell +$ pod install +``` + +You should see output such as: + +``` +Analyzing dependencies +Fetching podspec for `React` from `../node_modules/react-native` +Downloading dependencies +Installing React (0.62.0) +Generating Pods project +Integrating client project +Sending stats +Pod installation complete! There are 3 dependencies from the Podfile and 1 total pod installed. +``` + +> If this fails with errors mentioning `xcrun`, make sure that in Xcode in **Settings... (or Preferences...) > Locations** the Command Line Tools are assigned. + +### Code integration + +Now we will actually modify the native iOS application to integrate React Native. For our 2048 sample app, we will add a "High Score" screen in React Native. + +#### The React Native component + +The first bit of code we will write is the actual React Native code for the new "High Score" screen that will be integrated into our application. + +##### 1. Create a `index.js` file + +First, create an empty `index.js` file in the root of your React Native project. + +`index.js` is the starting point for React Native applications, and it is always required. It can be a small file that `require`s other file that are part of your React Native component or application, or it can contain all the code that is needed for it. In our case, we will put everything in `index.js`. + +##### 2. Add your React Native code + +In your `index.js`, create your component. In our sample here, we will add a `` component within a styled `` + +```jsx +import React from 'react'; +import {AppRegistry, StyleSheet, Text, View} from 'react-native'; + +const RNHighScores = ({scores}) => { + const contents = scores.map(score => ( + + {score.name}:{score.value} + {'\n'} + + )); + return ( + + + 2048 High Scores! + + {contents} + + ); +}; + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: '#FFFFFF', + }, + highScoresTitle: { + fontSize: 20, + textAlign: 'center', + margin: 10, + }, + scores: { + textAlign: 'center', + color: '#333333', + marginBottom: 5, + }, +}); + +// Module name +AppRegistry.registerComponent('RNHighScores', () => RNHighScores); +``` + +> `RNHighScores` is the name of your module that will be used when you add a view to React Native from within your iOS application. + +#### The Magic: `RCTRootView` + +Now that your React Native component is created via `index.js`, you need to add that component to a new or existing `ViewController`. The easiest path to take is to optionally create an event path to your component and then add that component to an existing `ViewController`. + +We will tie our React Native component with a new native view in the `ViewController` that will actually contain it called `RCTRootView` . + +##### 1. Create an Event Path + +You can add a new link on the main game menu to go to the "High Score" React Native page. + +![Event Path](/docs/assets/react-native-add-react-native-integration-link.png) + +##### 2. Event Handler + +We will now add an event handler from the menu link. A method will be added to the main `ViewController` of your application. This is where `RCTRootView` comes into play. + +When you build a React Native application, you use the [Metro bundler][metro] to create an `index.bundle` that will be served by the React Native server. Inside `index.bundle` will be our `RNHighScore` module. So, we need to point our `RCTRootView` to the location of the `index.bundle` resource (via `NSURL`) and tie it to the module. + +We will, for debugging purposes, log that the event handler was invoked. Then, we will create a string with the location of our React Native code that exists inside the `index.bundle`. Finally, we will create the main `RCTRootView`. Notice how we provide `RNHighScores` as the `moduleName` that we created [above](#the-react-native-component) when writing the code for our React Native component. + +First `import` the `RCTRootView` header. + +```objectivec +#import +``` + +> The `initialProperties` are here for illustration purposes so we have some data for our high score screen. In our React Native component, we will use `this.props` to get access to that data. + +```objectivec +- (IBAction)highScoreButtonPressed:(id)sender { + NSLog(@"High Score Button Pressed"); + NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.bundle?platform=ios"]; + + RCTRootView *rootView = + [[RCTRootView alloc] initWithBundleURL: jsCodeLocation + moduleName: @"RNHighScores" + initialProperties: + @{ + @"scores" : @[ + @{ + @"name" : @"Alex", + @"value": @"42" + }, + @{ + @"name" : @"Joel", + @"value": @"10" + } + ] + } + launchOptions: nil]; + UIViewController *vc = [[UIViewController alloc] init]; + vc.view = rootView; + [self presentViewController:vc animated:YES completion:nil]; +} +``` + +> Note that `RCTRootView initWithURL` starts up a new JSC VM. To save resources and simplify the communication between RN views in different parts of your native app, you can have multiple views powered by React Native that are associated with a single JS runtime. To do that, instead of using `[RCTRootView alloc] initWithURL`, use [`RCTBridge initWithBundleURL`](/~https://github.com/facebook/react-native/blob/main/packages/react-native/React/Base/RCTBridge.h#L94) to create a bridge and then use `RCTRootView initWithBridge`. + +> When moving your app to production, the `NSURL` can point to a pre-bundled file on disk via something like `[[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];`. You can use the `react-native-xcode.sh` script in `node_modules/react-native/scripts/` to generate that pre-bundled file. + +##### 3. Wire Up + +Wire up the new link in the main menu to the newly added event handler method. + +![Event Path](/docs/assets/react-native-add-react-native-integration-wire-up.png) + +> One of the easier ways to do this is to open the view in the storyboard and right click on the new link. Select something such as the `Touch Up Inside` event, drag that to the storyboard and then select the created method from the list provided. + +### Test your integration + +You have now done all the basic steps to integrate React Native with your current application. Now we will start the [Metro bundler][metro] to build the `index.bundle` package and the server running on `localhost` to serve it. + +##### 1. Add App Transport Security exception + +Apple has blocked implicit cleartext HTTP resource loading. So we need to add the following our project's `Info.plist` (or equivalent) file. + +```xml +NSAppTransportSecurity + + NSExceptionDomains + + localhost + + NSTemporaryExceptionAllowsInsecureHTTPLoads + + + + +``` + +> App Transport Security is good for your users. Make sure to re-enable it prior to releasing your app for production. + +##### 2. Run the packager + +To run your app, you need to first start the development server. To do this, run the following command in the root directory of your React Native project: + + + + +```shell +npm start +``` + + + + +```shell +yarn start +``` + + + + +##### 3. Run the app + +If you are using Xcode or your favorite editor, build and run your native iOS application as normal. Alternatively, you can run the app from the command line using: + + + + +```shell +npm run ios +``` + + + + +```shell +yarn ios +``` + + + + +In our sample application, you should see the link to the "High Scores" and then when you click on that you will see the rendering of your React Native component. + +Here is the _native_ application home screen: + +![Home Screen](/docs/assets/react-native-add-react-native-integration-example-home-screen.png) + +Here is the _React Native_ high score screen: + +![High Scores](/docs/assets/react-native-add-react-native-integration-example-high-scores.png) + +> If you are getting module resolution issues when running your application please see [this GitHub issue](/~https://github.com/facebook/react-native/issues/4968) for information and possible resolution. [This comment](/~https://github.com/facebook/react-native/issues/4968#issuecomment-220941717) seemed to be the latest possible resolution. + +### Now what? + +At this point you can continue developing your app as usual. Refer to our [debugging](debugging) and [deployment](running-on-device) docs to learn more about working with React Native. + +[metro]: https://facebook.github.io/metro/ diff --git a/website/versioned_docs/version-0.73.0/_integration-with-existing-apps-swift.md b/website/versioned_docs/version-0.73.0/_integration-with-existing-apps-swift.md new file mode 100644 index 00000000000..93d586d3fa5 --- /dev/null +++ b/website/versioned_docs/version-0.73.0/_integration-with-existing-apps-swift.md @@ -0,0 +1,381 @@ +import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants'; + +## Key Concepts + +The keys to integrating React Native components into your iOS application are to: + +1. Set up React Native dependencies and directory structure. +2. Understand what React Native components you will use in your app. +3. Add these components as dependencies using CocoaPods. +4. Develop your React Native components in JavaScript. +5. Add a `RCTRootView` to your iOS app. This view will serve as the container for your React Native component. +6. Start the React Native server and run your native application. +7. Verify that the React Native aspect of your application works as expected. + +## Prerequisites + +Follow the React Native CLI Quickstart in the [environment setup guide](environment-setup) to configure your development environment for building React Native apps for iOS. + +### 1. Set up directory structure + +To ensure a smooth experience, create a new folder for your integrated React Native project, then copy your existing iOS project to a `/ios` subfolder. + +### 2. Install JavaScript dependencies + +Go to the root directory for your project and create a new `package.json` file with the following contents: + +``` +{ + "name": "MyReactNativeApp", + "version": "0.0.1", + "private": true, + "scripts": { + "start": "yarn react-native start" + } +} +``` + +Next, install the `react` and `react-native` packages. Open a terminal or command prompt, then navigate to the directory with your `package.json` file and run: + + + + +```shell +npm install react-native +``` + + + + +```shell +yarn add react-native +``` + + + + +This will print a message similar to the following (scroll up in the yarn output to see it): + +> warning "`react-native@0.52.2`" has unmet peer dependency "`react@16.2.0`". + +This is OK, it means we also need to install React: + + + + +```shell +npm install react@version_printed_above +``` + + + + +```shell +yarn add react@version_printed_above +``` + + + + +Yarn has created a new `/node_modules` folder. This folder stores all the JavaScript dependencies required to build your project. + +Add `node_modules/` to your `.gitignore` file. + +### 3. Install CocoaPods + +[CocoaPods](https://cocoapods.org) is a package management tool for iOS and macOS development. We use it to add the actual React Native framework code locally into your current project. + +We recommend installing CocoaPods using [Homebrew](https://brew.sh/). + +```shell +$ brew install cocoapods +``` + +> It is technically possible not to use CocoaPods, but that would require manual library and linker additions that would overly complicate this process. + +## Adding React Native to your app + +Assume the [app for integration](/~https://github.com/JoelMarcey/swift-2048) is a [2048](https://en.wikipedia.org/wiki/2048_%28video_game%29) game. Here is what the main menu of the native application looks like without React Native. + +![Before RN Integration](/docs/assets/react-native-existing-app-integration-ios-before.png) + +### Command Line Tools for Xcode + +Install the Command Line Tools. Choose **Settings... (or Preferences...)** in the Xcode menu. Go to the Locations panel and install the tools by selecting the most recent version in the Command Line Tools dropdown. + +![Xcode Command Line Tools](/docs/assets/GettingStartedXcodeCommandLineTools.png) + +### Configuring CocoaPods dependencies + +Before you integrate React Native into your application, you will want to decide what parts of the React Native framework you would like to integrate. We will use CocoaPods to specify which of these "subspecs" your app will depend on. + +The list of supported `subspec`s is available in [`/node_modules/react-native/React.podspec`](/~https://github.com/facebook/react-native/blob/main/packages/react-native/React.podspec). They are generally named by functionality. For example, you will generally always want the `Core` `subspec`. That will get you the `AppRegistry`, `StyleSheet`, `View` and other core React Native libraries. If you want to add the React Native `Text` library (e.g., for `` elements), then you will need the `RCTText` `subspec`. If you want the `Image` library (e.g., for `` elements), then you will need the `RCTImage` `subspec`. + +You can specify which `subspec`s your app will depend on in a `Podfile` file. The easiest way to create a `Podfile` is by running the CocoaPods `init` command in the `/ios` subfolder of your project: + +```shell +$ pod init +``` + +The `Podfile` will contain a boilerplate setup that you will tweak for your integration purposes. + +> The `Podfile` version changes depending on your version of `react-native`. Refer to https://react-native-community.github.io/upgrade-helper/ for the specific version of `Podfile` you should be using. + +Ultimately, your `Podfile` should look something similar to this: +[Podfile Template](/~https://github.com/facebook/react-native/blob/main/packages/react-native/template/ios/Podfile) + +After you have created your `Podfile`, you are ready to install the React Native pod. + +```shell +$ pod install +``` + +You should see output such as: + +``` +Analyzing dependencies +Fetching podspec for `React` from `../node_modules/react-native` +Downloading dependencies +Installing React (0.62.0) +Generating Pods project +Integrating client project +Sending stats +Pod installation complete! There are 3 dependencies from the Podfile and 1 total pod installed. +``` + +> If this fails with errors mentioning `xcrun`, make sure that in Xcode in **Settings... (or Preferences...) > Locations** the Command Line Tools are assigned. + +> If you get a warning such as "_The `swift-2048 [Debug]` target overrides the `FRAMEWORK_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-swift-2048/Pods-swift-2048.debug.xcconfig`. This can lead to problems with the CocoaPods installation_", then make sure the `Framework Search Paths` in `Build Settings` for both `Debug` and `Release` only contain `$(inherited)`. + +### Code integration + +Now we will actually modify the native iOS application to integrate React Native. For our 2048 sample app, we will add a "High Score" screen in React Native. + +#### The React Native component + +The first bit of code we will write is the actual React Native code for the new "High Score" screen that will be integrated into our application. + +##### 1. Create a `index.js` file + +First, create an empty `index.js` file in the root of your React Native project. + +`index.js` is the starting point for React Native applications, and it is always required. It can be a small file that `require`s other file that are part of your React Native component or application, or it can contain all the code that is needed for it. In our case, we will put everything in `index.js`. + +##### 2. Add your React Native code + +In your `index.js`, create your component. In our sample here, we will add a `` component within a styled `` + +```jsx +import React from 'react'; +import {AppRegistry, StyleSheet, Text, View} from 'react-native'; + +const RNHighScores = ({scores}) => { + const contents = scores.map(score => ( + + {score.name}:{score.value} + {'\n'} + + )); + return ( + + + 2048 High Scores! + + {contents} + + ); +}; + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: '#FFFFFF', + }, + highScoresTitle: { + fontSize: 20, + textAlign: 'center', + margin: 10, + }, + scores: { + textAlign: 'center', + color: '#333333', + marginBottom: 5, + }, +}); + +// Module name +AppRegistry.registerComponent('RNHighScores', () => RNHighScores); +``` + +> `RNHighScores` is the name of your module that will be used when you add a view to React Native from within your iOS application. + +#### The Magic: `RCTRootView` + +Now that your React Native component is created via `index.js`, you need to add that component to a new or existing `ViewController`. The easiest path to take is to optionally create an event path to your component and then add that component to an existing `ViewController`. + +We will tie our React Native component with a new native view in the `ViewController` that will actually contain it called `RCTRootView` . + +##### 1. Create an Event Path + +You can add a new link on the main game menu to go to the "High Score" React Native page. + +![Event Path](/docs/assets/react-native-add-react-native-integration-link.png) + +##### 2. Event Handler + +We will now add an event handler from the menu link. A method will be added to the main `ViewController` of your application. This is where `RCTRootView` comes into play. + +When you build a React Native application, you use the [Metro bundler][metro] to create an `index.bundle` that will be served by the React Native server. Inside `index.bundle` will be our `RNHighScore` module. So, we need to point our `RCTRootView` to the location of the `index.bundle` resource (via `NSURL`) and tie it to the module. + +We will, for debugging purposes, log that the event handler was invoked. Then, we will create a string with the location of our React Native code that exists inside the `index.bundle`. Finally, we will create the main `RCTRootView`. Notice how we provide `RNHighScores` as the `moduleName` that we created [above](#the-react-native-component) when writing the code for our React Native component. + +First `import` the `React` library. + +```jsx +import React +``` + +> The `initialProperties` are here for illustration purposes so we have some data for our high score screen. In our React Native component, we will use `this.props` to get access to that data. + +```swift +@IBAction func highScoreButtonTapped(sender : UIButton) { + NSLog("Hello") + let jsCodeLocation = URL(string: "http://localhost:8081/index.bundle?platform=ios") + let mockData:NSDictionary = ["scores": + [ + ["name":"Alex", "value":"42"], + ["name":"Joel", "value":"10"] + ] + ] + + let rootView = RCTRootView( + bundleURL: jsCodeLocation, + moduleName: "RNHighScores", + initialProperties: mockData as [NSObject : AnyObject], + launchOptions: nil + ) + let vc = UIViewController() + vc.view = rootView + self.present(vc, animated: true, completion: nil) +} +``` + +> Note that `RCTRootView bundleURL` starts up a new JSC VM. To save resources and simplify the communication between RN views in different parts of your native app, you can have multiple views powered by React Native that are associated with a single JS runtime. To do that, instead of using `RCTRootView bundleURL`, use [`RCTBridge initWithBundleURL`](/~https://github.com/facebook/react-native/blob/main/packages/react-native/React/Base/RCTBridge.h#94) to create a bridge and then use `RCTRootView initWithBridge`. + +> When moving your app to production, the `NSURL` can point to a pre-bundled file on disk via something like `let mainBundle = NSBundle(URLForResource: "main" withExtension:"jsbundle")`. You can use the `react-native-xcode.sh` script in `node_modules/react-native/scripts/` to generate that pre-bundled file. + +##### 3. Wire Up + +Wire up the new link in the main menu to the newly added event handler method. + +![Event Path](/docs/assets/react-native-add-react-native-integration-wire-up.png) + +> One of the easier ways to do this is to open the view in the storyboard and right click on the new link. Select something such as the `Touch Up Inside` event, drag that to the storyboard and then select the created method from the list provided. + +##### 3. Window Reference + +Add an window reference to your AppDelegate.swift file. Ultimately, your AppDelegate should look something similar to this: + +```swift +import UIKit + +@main +class AppDelegate: UIResponder, UIApplicationDelegate { + + // Add window reference + var window: UIWindow? + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + .... +} +``` + +### Test your integration + +You have now done all the basic steps to integrate React Native with your current application. Now we will start the [Metro bundler][metro] to build the `index.bundle` package and the server running on `localhost` to serve it. + +##### 1. Add App Transport Security exception + +Apple has blocked implicit cleartext HTTP resource loading. So we need to add the following our project's `Info.plist` (or equivalent) file. + +```xml +NSAppTransportSecurity + + NSExceptionDomains + + localhost + + NSTemporaryExceptionAllowsInsecureHTTPLoads + + + + +``` + +> App Transport Security is good for your users. Make sure to re-enable it prior to releasing your app for production. + +##### 2. Run the packager + +To run your app, you need to first start the development server. To do this, run the following command in the root directory of your React Native project: + + + + +```shell +npm start +``` + + + + +```shell +yarn start +``` + + + + +##### 3. Run the app + +If you are using Xcode or your favorite editor, build and run your native iOS application as normal. Alternatively, you can run the app from the command line using following command from the root directory of your React Native project: + + + + +```shell +npm run ios +``` + + + + +```shell +yarn ios +``` + + + + +In our sample application, you should see the link to the "High Scores" and then when you click on that you will see the rendering of your React Native component. + +Here is the _native_ application home screen: + +![Home Screen](/docs/assets/react-native-add-react-native-integration-example-home-screen.png) + +Here is the _React Native_ high score screen: + +![High Scores](/docs/assets/react-native-add-react-native-integration-example-high-scores.png) + +> If you are getting module resolution issues when running your application please see [this GitHub issue](/~https://github.com/facebook/react-native/issues/4968) for information and possible resolution. [This comment](/~https://github.com/facebook/react-native/issues/4968#issuecomment-220941717) seemed to be the latest possible resolution. + +### Now what? + +At this point you can continue developing your app as usual. Refer to our [debugging](debugging) and [deployment](running-on-device) docs to learn more about working with React Native. + +[metro]: https://facebook.github.io/metro/ diff --git a/website/versioned_docs/version-0.73.0/_markdown-new-architecture-warning.mdx b/website/versioned_docs/version-0.73.0/_markdown-new-architecture-warning.mdx new file mode 100644 index 00000000000..d52c490153b --- /dev/null +++ b/website/versioned_docs/version-0.73.0/_markdown-new-architecture-warning.mdx @@ -0,0 +1,7 @@ +:::caution + +This documentation is still **experimental** and details are subject to changes as we iterate. Feel free to share your feedback on the [discussion inside the working group](/~https://github.com/reactwg/react-native-new-architecture/discussions/8) for this page. + +Moreover, it contains several **manual steps**. Please note that this won't be representative of the final developer experience once the New Architecture is stable. We're working on tools, templates and libraries to help you get started fast on the New Architecture, without having to go through the whole setup. + +::: diff --git a/website/versioned_docs/version-0.73.0/_remove-global-cli.md b/website/versioned_docs/version-0.73.0/_remove-global-cli.md new file mode 100644 index 00000000000..08d0d9ba3c1 --- /dev/null +++ b/website/versioned_docs/version-0.73.0/_remove-global-cli.md @@ -0,0 +1,5 @@ +> If you previously installed a global `react-native-cli` package, please remove it as it may cause unexpected issues: +> +> ```shell +> npm uninstall -g react-native-cli @react-native-community/cli +> ``` diff --git a/website/versioned_docs/version-0.73.0/accessibility.md b/website/versioned_docs/version-0.73.0/accessibility.md new file mode 100644 index 00000000000..0df4e15a858 --- /dev/null +++ b/website/versioned_docs/version-0.73.0/accessibility.md @@ -0,0 +1,487 @@ +--- +id: accessibility +title: Accessibility +description: Create mobile apps accessible to assistive technology with React Native's suite of APIs designed to work with Android and iOS. +--- + +Both Android and iOS provide APIs for integrating apps with assistive technologies like the bundled screen readers VoiceOver (iOS) and TalkBack (Android). React Native has complementary APIs that let your app accommodate all users. + +:::info +Android and iOS differ slightly in their approaches, and thus the React Native implementations may vary by platform. +::: + +## Accessibility properties + +### `accessible` + +When `true`, indicates that the view is an accessibility element. When a view is an accessibility element, it groups its children into a single selectable component. By default, all touchable elements are accessible. + +On Android, `accessible={true}` property for a react-native View will be translated into native `focusable={true}`. + +```tsx + + text one + text two + +``` + +In the above example, we can't get accessibility focus separately on 'text one' and 'text two'. Instead we get focus on a parent view with 'accessible' property. + +### `accessibilityLabel` + +When a view is marked as accessible, it is a good practice to set an accessibilityLabel on the view, so that people who use VoiceOver know what element they have selected. VoiceOver will read this string when a user selects the associated element. + +To use, set the `accessibilityLabel` property to a custom string on your View, Text or Touchable: + +```tsx + + + Press me! + + +``` + +In the above example, the `accessibilityLabel` on the TouchableOpacity element would default to "Press me!". The label is constructed by concatenating all Text node children separated by spaces. + +### `accessibilityLabelledBy`
Android
+ +A reference to another element [nativeID](view.md#nativeid) used to build complex forms. +The value of `accessibilityLabelledBy` should match the `nativeID` of the related element: + +```tsx + + Label for Input Field + + +``` + +In the above example, the screenreader announces `Input, Edit Box for Label for Input Field` when focusing on the TextInput. + +### `accessibilityHint` + +An accessibility hint helps users understand what will happen when they perform an action on the accessibility element when that result is not clear from the accessibility label. + +To use, set the `accessibilityHint` property to a custom string on your View, Text or Touchable: + +```tsx + + + Back + + +``` + +
iOS
+ +In the above example, VoiceOver will read the hint after the label, if the user has hints enabled in the device's VoiceOver settings. Read more about guidelines for `accessibilityHint` in the [iOS Developer Docs](https://developer.apple.com/documentation/objectivec/nsobject/1615093-accessibilityhint) + +
Android
+ +In the above example, TalkBack will read the hint after the label. At this time, hints cannot be turned off on Android. + +### `accessibilityLanguage`
iOS
+ +By using the `accessibilityLanguage` property, the screen reader will understand which language to use while reading the element's **label**, **value** and **hint**. The provided string value must follow the [BCP 47 specification](https://www.rfc-editor.org/info/bcp47). + +```tsx + + 🍕 + +``` + +### `accessibilityIgnoresInvertColors`
iOS
+ +Inverting screen colors is an Accessibility feature that makes the iPhone and iPad easier on the eyes for some people with a sensitivity to brightness, easier to distinguish for some people with color blindness, and easier to make out for some people with low vision. However, sometimes you have views such as photos that you don't want to be inverted. In this case, you can set this property to be `true` so that these specific views won't have their colors inverted. + +### `accessibilityLiveRegion`
Android
+ +When components dynamically change, we want TalkBack to alert the end user. This is made possible by the `accessibilityLiveRegion` property. It can be set to `none`, `polite` and `assertive`: + +- **none** Accessibility services should not announce changes to this view. +- **polite** Accessibility services should announce changes to this view. +- **assertive** Accessibility services should interrupt ongoing speech to immediately announce changes to this view. + +```tsx + + + Click me + + + + Clicked {count} times + +``` + +In the above example method `addOne` changes the state variable `count`. As soon as an end user clicks the TouchableWithoutFeedback, TalkBack reads text in the Text view because of its `accessibilityLiveRegion="polite"` property. + +### `accessibilityRole` + +`accessibilityRole` communicates the purpose of a component to the user of an assistive technology. + +`accessibilityRole` can be one of the following: + +- **adjustable** Used when an element can be "adjusted" (e.g. a slider). +- **alert** Used when an element contains important text to be presented to the user. +- **button** Used when the element should be treated as a button. +- **checkbox** Used when an element represents a checkbox which can be checked, unchecked, or have mixed checked state. +- **combobox** Used when an element represents a combo box, which allows the user to select among several choices. +- **header** Used when an element acts as a header for a content section (e.g. the title of a navigation bar). +- **image** Used when the element should be treated as an image. Can be combined with button or link, for example. +- **imagebutton** Used when the element should be treated as a button and is also an image. +- **keyboardkey** Used when the element acts as a keyboard key. +- **link** Used when the element should be treated as a link. +- **menu** Used when the component is a menu of choices. +- **menubar** Used when a component is a container of multiple menus. +- **menuitem** Used to represent an item within a menu. +- **none** Used when the element has no role. +- **progressbar** Used to represent a component which indicates progress of a task. +- **radio** Used to represent a radio button. +- **radiogroup** Used to represent a group of radio buttons. +- **scrollbar** Used to represent a scroll bar. +- **search** Used when the text field element should also be treated as a search field. +- **spinbutton** Used to represent a button which opens a list of choices. +- **summary** Used when an element can be used to provide a quick summary of current conditions in the app when the app first launches. +- **switch** Used to represent a switch which can be turned on and off. +- **tab** Used to represent a tab. +- **tablist** Used to represent a list of tabs. +- **text** Used when the element should be treated as static text that cannot change. +- **timer** Used to represent a timer. +- **togglebutton** Used to represent a toggle button. Should be used with accessibilityState checked to indicate if the button is toggled on or off. +- **toolbar** Used to represent a tool bar (a container of action buttons or components). +- **grid** Used with ScrollView, VirtualizedList, FlatList, or SectionList to represent a grid. Adds the in/out of grid announcements to the android GridView. + +### `accessibilityState` + +Describes the current state of a component to the user of an assistive technology. + +`accessibilityState` is an object. It contains the following fields: + +| Name | Description | Type | Required | +| -------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | -------- | +| disabled | Indicates whether the element is disabled or not. | boolean | No | +| selected | Indicates whether a selectable element is currently selected or not. | boolean | No | +| checked | Indicates the state of a checkable element. This field can either take a boolean or the "mixed" string to represent mixed checkboxes. | boolean or 'mixed' | No | +| busy | Indicates whether an element is currently busy or not. | boolean | No | +| expanded | Indicates whether an expandable element is currently expanded or collapsed. | boolean | No | + +To use, set the `accessibilityState` to an object with a specific definition. + +### `accessibilityValue` + +Represents the current value of a component. It can be a textual description of a component's value, or for range-based components, such as sliders and progress bars, it contains range information (minimum, current, and maximum). + +`accessibilityValue` is an object. It contains the following fields: + +| Name | Description | Type | Required | +| ---- | ---------------------------------------------------------------------------------------------- | ------- | ------------------------- | +| min | The minimum value of this component's range. | integer | Required if `now` is set. | +| max | The maximum value of this component's range. | integer | Required if `now` is set. | +| now | The current value of this component's range. | integer | No | +| text | A textual description of this component's value. Will override `min`, `now`, and `max` if set. | string | No | + +### `accessibilityViewIsModal`
iOS
+ +A Boolean value indicating whether VoiceOver should ignore the elements within views that are siblings of the receiver. + +For example, in a window that contains sibling views `A` and `B`, setting `accessibilityViewIsModal` to `true` on view `B` causes VoiceOver to ignore the elements in the view `A`. On the other hand, if view `B` contains a child view `C` and you set `accessibilityViewIsModal` to `true` on view `C`, VoiceOver does not ignore the elements in view `A`. + +### `accessibilityElementsHidden`
iOS
+ +A Boolean value indicating whether the accessibility elements contained within this accessibility element are hidden. + +For example, in a window that contains sibling views `A` and `B`, setting `accessibilityElementsHidden` to `true` on view `B` causes VoiceOver to ignore the elements in the view `B`. This is similar to the Android property `importantForAccessibility="no-hide-descendants"`. + +### `aria-valuemax` + +Represents the maximum value for range-based components, such as sliders and progress bars. + +### `aria-valuemin` + +Represents the minimum value for range-based components, such as sliders and progress bars. + +### `aria-valuenow` + +Represents the current value for range-based components, such as sliders and progress bars. + +### `aria-valuetext` + +Represents the textual description of the component. + +### `aria-busy` + +Indicates an element is being modified and that assistive technologies may want to wait until the changes are complete before informing the user about the update. + +| Type | Default | +| ------- | ------- | +| boolean | false | + +### `aria-checked` + +Indicates the state of a checkable element. This field can either take a boolean or the "mixed" string to represent mixed checkboxes. + +| Type | Default | +| ---------------- | ------- | +| boolean, 'mixed' | false | + +### `aria-disabled` + +Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. + +| Type | Default | +| ------- | ------- | +| boolean | false | + +### `aria-expanded` + +Indicates whether an expandable element is currently expanded or collapsed. + +| Type | Default | +| ------- | ------- | +| boolean | false | + +### `aria-hidden` + +Indicates whether the accessibility elements contained within this accessibility element are hidden. + +For example, in a window that contains sibling views `A` and `B`, setting `aria-hidden` to `true` on view `B` causes VoiceOver to ignore the elements in the view `B`. + +| Type | Default | +| ------- | ------- | +| boolean | false | + +### `aria-label` + +Defines a string value that labels an interactive element. + +| Type | +| ------ | +| string | + +### `aria-labelledby`
Android
+ +Identifies the element that labels the element it is applied to. The value of `aria-labelledby` should match the [`nativeID`](view.md#nativeid) of the related element: + +```tsx + + Label for Input Field + + +``` + +| Type | +| ------ | +| string | + +### `aria-live`
Android
+ +Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region. + +- **off** Accessibility services should not announce changes to this view. +- **polite** Accessibility services should announce changes to this view. +- **assertive** Accessibility services should interrupt ongoing speech to immediately announce changes to this view. + +| Type | Default | +| ---------------------------------------- | ------- | +| enum(`'assertive'`, `'off'`, `'polite'`) | `'off'` | + +--- + +### `aria-modal`
iOS
+ +Boolean value indicating whether VoiceOver should ignore the elements within views that are siblings of the receiver. + +| Type | Default | +| ------- | ------- | +| boolean | false | + +### `aria-selected` + +Indicates whether a selectable element is currently selected or not. + +| Type | +| ------- | +| boolean | + +### `importantForAccessibility`
Android
+ +In the case of two overlapping UI components with the same parent, default accessibility focus can have unpredictable behavior. The `importantForAccessibility` property will resolve this by controlling if a view fires accessibility events and if it is reported to accessibility services. It can be set to `auto`, `yes`, `no` and `no-hide-descendants` (the last value will force accessibility services to ignore the component and all of its children). + +```tsx + + + First layout + + + Second layout + + +``` + +In the above example, the `yellow` layout and its descendants are completely invisible to TalkBack and all other accessibility services. So we can use overlapping views with the same parent without confusing TalkBack. + +### `onAccessibilityEscape`
iOS
+ +Assign this property to a custom function which will be called when someone performs the "escape" gesture, which is a two finger Z shaped gesture. An escape function should move back hierarchically in the user interface. This can mean moving up or back in a navigation hierarchy or dismissing a modal user interface. If the selected element does not have an `onAccessibilityEscape` function, the system will attempt to traverse up the view hierarchy until it finds a view that does or bonk to indicate it was unable to find one. + +### `onAccessibilityTap` + +Use this property to assign a custom function to be called when someone activates an accessible element by double tapping on it while it's selected. + +### `onMagicTap`
iOS
+ +Assign this property to a custom function which will be called when someone performs the "magic tap" gesture, which is a double-tap with two fingers. A magic tap function should perform the most relevant action a user could take on a component. In the Phone app on iPhone, a magic tap answers a phone call, or ends the current one. If the selected element does not have an `onMagicTap` function, the system will traverse up the view hierarchy until it finds a view that does. + +### `role` + +`role` communicates the purpose of a component to the user of an assistive technology. Has precedence over the [`accessibilityRole`](accessibility#accessibilityrole) prop. + +`role` can be one of the following: + +- **alert** Used when an element contains important text to be presented to the user. +- **button** Used when the element should be treated as a button. +- **checkbox** Used when an element represents a checkbox which can be checked, unchecked, or have mixed checked state. +- **combobox** Used when an element represents a combo box, which allows the user to select among several choices. +- **grid** Used with ScrollView, VirtualizedList, FlatList, or SectionList to represent a grid. Adds the in/out of grid announcements to the android GridView. +- **heading** Used when an element acts as a header for a content section (e.g. the title of a navigation bar). +- **img** Used when the element should be treated as an image. Can be combined with button or link, for example. +- **link** Used when the element should be treated as a link. +- **list** Used to identify a list of items. +- **menu** Used when the component is a menu of choices. +- **menubar** Used when a component is a container of multiple menus. +- **menuitem** Used to represent an item within a menu. +- **none** Used when the element has no role. +- **presentation** Used when the element has no role. +- **progressbar** Used to represent a component which indicates progress of a task. +- **radio** Used to represent a radio button. +- **radiogroup** Used to represent a group of radio buttons. +- **scrollbar** Used to represent a scroll bar. +- **searchbox** Used when the text field element should also be treated as a search field. +- **slider** Used when an element can be "adjusted" (e.g. a slider). +- **spinbutton** Used to represent a button which opens a list of choices. +- **summary** Used when an element can be used to provide a quick summary of current conditions in the app when the app first launches. +- **switch** Used to represent a switch which can be turned on and off. +- **tab** Used to represent a tab. +- **tablist** Used to represent a list of tabs. +- **timer** Used to represent a timer. +- **toolbar** Used to represent a tool bar (a container of action buttons or components). + +## Accessibility Actions + +Accessibility actions allow an assistive technology to programmatically invoke the actions of a component. In order to support accessibility actions, a component must do two things: + +- Define the list of actions it supports via the `accessibilityActions` property. +- Implement an `onAccessibilityAction` function to handle action requests. + +The `accessibilityActions` property should contain a list of action objects. Each action object should contain the following fields: + +| Name | Type | Required | +| ----- | ------ | -------- | +| name | string | Yes | +| label | string | No | + +Actions either represent standard actions, such as clicking a button or adjusting a slider, or custom actions specific to a given component such as deleting an email message. The `name` field is required for both standard and custom actions, but `label` is optional for standard actions. + +When adding support for standard actions, `name` must be one of the following: + +- `'magicTap'` - iOS only - While VoiceOver focus is on or inside the component, the user double tapped with two fingers. +- `'escape'` - iOS only - While VoiceOver focus is on or inside the component, the user performed a two finger scrub gesture (left, right, left). +- `'activate'` - Activate the component. Typically this should perform the same action as when the user touches or clicks the component when not using an assistive technology. This is generated when a screen reader user double taps the component. +- `'increment'` - Increment an adjustable component. On iOS, VoiceOver generates this action when the component has a role of `'adjustable'` and the user places focus on it and swipes upward. On Android, TalkBack generates this action when the user places accessibility focus on the component and presses the volume up button. +- `'decrement'` - Decrement an adjustable component. On iOS, VoiceOver generates this action when the component has a role of `'adjustable'` and the user places focus on it and swipes downward. On Android, TalkBack generates this action when the user places accessibility focus on the component and presses the volume down button. +- `'longpress'` - Android only - This action is generated when the user places accessibility focus on the component and double tap and holds one finger on the screen. Typically, this should perform the same action as when the user holds down one finger on the component while not using an assistive technology. + +The `label` field is optional for standard actions, and is often unused by assistive technologies. For custom actions, it is a localized string containing a description of the action to be presented to the user. + +To handle action requests, a component must implement an `onAccessibilityAction` function. The only argument to this function is an event containing the name of the action to perform. The below example from RNTester shows how to create a component which defines and handles several custom actions. + +```tsx + { + switch (event.nativeEvent.actionName) { + case 'cut': + Alert.alert('Alert', 'cut action success'); + break; + case 'copy': + Alert.alert('Alert', 'copy action success'); + break; + case 'paste': + Alert.alert('Alert', 'paste action success'); + break; + } + }} +/> +``` + +## Checking if a Screen Reader is Enabled + +The `AccessibilityInfo` API allows you to determine whether or not a screen reader is currently active. See the [AccessibilityInfo documentation](accessibilityinfo) for details. + +## Sending Accessibility Events
Android
+ +Sometimes it is useful to trigger an accessibility event on a UI component (i.e. when a custom view appears on a screen or set accessibility focus to a view). Native UIManager module exposes a method ‘sendAccessibilityEvent’ for this purpose. It takes two arguments: view tag and a type of an event. The supported event types are `typeWindowStateChanged`, `typeViewFocused` and `typeViewClicked`. + +```tsx +import {Platform, UIManager, findNodeHandle} from 'react-native'; + +if (Platform.OS === 'android') { + UIManager.sendAccessibilityEvent( + findNodeHandle(this), + UIManager.AccessibilityEventTypes.typeViewFocused, + ); +} +``` + +## Testing TalkBack Support
Android
+ +To enable TalkBack, go to the Settings app on your Android device or emulator. Tap Accessibility, then TalkBack. Toggle the "Use service" switch to enable or disable it. + +Android emulators don't have TalkBack installed by default. You can install TalkBack on your emulator via the Google Play Store. Make sure to choose an emulator with the Google Play store installed. These are available in Android Studio. + +You can use the volume key shortcut to toggle TalkBack. To turn on the volume key shortcut, go to the Settings app, then Accessibility. At the top, turn on Volume key shortcut. + +To use the volume key shortcut, press both volume keys for 3 seconds to start an accessibility tool. + +Additionally, if you prefer, you can toggle TalkBack via command line with: + +```shell +# disable +adb shell settings put secure enabled_accessibility_services com.android.talkback/com.google.android.marvin.talkback.TalkBackService + +# enable +adb shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService +``` + +## Testing VoiceOver Support
iOS
+ +To enable VoiceOver, go to the Settings app on your iOS device (it's not available for simulator). Tap General, then Accessibility. There you will find many tools that people use to make their devices more usable, such as bolder text, increased contrast, and VoiceOver. + +To enable VoiceOver, tap on VoiceOver under "Vision" and toggle the switch that appears at the top. + +At the very bottom of the Accessibility settings, there is an "Accessibility Shortcut". You can use this to toggle VoiceOver by triple clicking the Home button. + +## Additional Resources + +- [Making React Native Apps Accessible](https://engineering.fb.com/ios/making-react-native-apps-accessible/) diff --git a/website/versioned_docs/version-0.73.0/accessibilityinfo.md b/website/versioned_docs/version-0.73.0/accessibilityinfo.md new file mode 100644 index 00000000000..4fb955f42f2 --- /dev/null +++ b/website/versioned_docs/version-0.73.0/accessibilityinfo.md @@ -0,0 +1,242 @@ +--- +id: accessibilityinfo +title: AccessibilityInfo +--- + +Sometimes it's useful to know whether or not the device has a screen reader that is currently active. The `AccessibilityInfo` API is designed for this purpose. You can use it to query the current state of the screen reader as well as to register to be notified when the state of the screen reader changes. + +## Example + +```SnackPlayer name=AccessibilityInfo%20Example&supportedPlatforms=android,ios +import React, {useState, useEffect} from 'react'; +import {AccessibilityInfo, View, Text, StyleSheet} from 'react-native'; + +const App = () => { + const [reduceMotionEnabled, setReduceMotionEnabled] = useState(false); + const [screenReaderEnabled, setScreenReaderEnabled] = useState(false); + + useEffect(() => { + const reduceMotionChangedSubscription = AccessibilityInfo.addEventListener( + 'reduceMotionChanged', + isReduceMotionEnabled => { + setReduceMotionEnabled(isReduceMotionEnabled); + }, + ); + const screenReaderChangedSubscription = AccessibilityInfo.addEventListener( + 'screenReaderChanged', + isScreenReaderEnabled => { + setScreenReaderEnabled(isScreenReaderEnabled); + }, + ); + + AccessibilityInfo.isReduceMotionEnabled().then(isReduceMotionEnabled => { + setReduceMotionEnabled(isReduceMotionEnabled); + }); + AccessibilityInfo.isScreenReaderEnabled().then(isScreenReaderEnabled => { + setScreenReaderEnabled(isScreenReaderEnabled); + }); + + return () => { + reduceMotionChangedSubscription.remove(); + screenReaderChangedSubscription.remove(); + }; + }, []); + + return ( + + + The reduce motion is {reduceMotionEnabled ? 'enabled' : 'disabled'}. + + + The screen reader is {screenReaderEnabled ? 'enabled' : 'disabled'}. + + + ); +}; + +const styles = StyleSheet.create({ + container: { + flex: 1, + alignItems: 'center', + justifyContent: 'center', + }, + status: { + margin: 30, + }, +}); + +export default App; +``` + +--- + +# Reference + +## Methods + +### `addEventListener()` + +```tsx +static addEventListener( + eventName: AccessibilityChangeEventName | AccessibilityAnnouncementEventName, + handler: ( + event: AccessibilityChangeEvent | AccessibilityAnnouncementFinishedEvent, + ) => void, +): EmitterSubscription; +``` + +Add an event handler. Supported events: + +| Event name | Description | +| ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `accessibilityServiceChanged`
Android
| Fires when some services such as TalkBack, other Android assistive technologies, and third-party accessibility services are enabled. The argument to the event handler is a boolean. The boolean is `true` when a some accessibility services is enabled and `false` otherwise. | +| `announcementFinished`
iOS
| Fires when the screen reader has finished making an announcement. The argument to the event handler is a dictionary with these keys:
  • `announcement`: The string announced by the screen reader.
  • `success`: A boolean indicating whether the announcement was successfully made.
| +| `boldTextChanged`
iOS
| Fires when the state of the bold text toggle changes. The argument to the event handler is a boolean. The boolean is `true` when bold text is enabled and `false` otherwise. | +| `grayscaleChanged`
iOS
| Fires when the state of the gray scale toggle changes. The argument to the event handler is a boolean. The boolean is `true` when a gray scale is enabled and `false` otherwise. | +| `invertColorsChanged`
iOS
| Fires when the state of the invert colors toggle changes. The argument to the event handler is a boolean. The boolean is `true` when invert colors is enabled and `false` otherwise. | +| `reduceMotionChanged` | Fires when the state of the reduce motion toggle changes. The argument to the event handler is a boolean. The boolean is `true` when a reduce motion is enabled (or when "Transition Animation Scale" in "Developer options" is "Animation off") and `false` otherwise. | +| `reduceTransparencyChanged`
iOS
| Fires when the state of the reduce transparency toggle changes. The argument to the event handler is a boolean. The boolean is `true` when reduce transparency is enabled and `false` otherwise. | +| `screenReaderChanged` | Fires when the state of the screen reader changes. The argument to the event handler is a boolean. The boolean is `true` when a screen reader is enabled and `false` otherwise. | + +--- + +### `announceForAccessibility()` + +```tsx +static announceForAccessibility(announcement: string); +``` + +Post a string to be announced by the screen reader. + +--- + +### `announceForAccessibilityWithOptions()` + +```tsx +static announceForAccessibilityWithOptions( + announcement: string, + options: options: {queue?: boolean}, +); +``` + +Post a string to be announced by the screen reader with modification options. By default announcements will interrupt any existing speech, but on iOS they can be queued behind existing speech by setting `queue` to `true` in the options object. + +**Parameters:** + +| Name | Type | Description | +| ------------------------------------------------------------- | ------ | ---------------------------------------------------------------------------------------- | +| announcement
Required
| string | The string to be announced | +| options
Required
| object | `queue` - queue the announcement behind existing speech
iOS
| + +--- + +### `getRecommendedTimeoutMillis()`
Android
+ +```tsx +static getRecommendedTimeoutMillis(originalTimeout: number): Promise; +``` + +Gets the timeout in millisecond that the user needs. +This value is set in "Time to take action (Accessibility timeout)" of "Accessibility" settings. + +**Parameters:** + +| Name | Type | Description | +| ---------------------------------------------------------------- | ------ | ------------------------------------------------------------------------------------- | +| originalTimeout
Required
| number | The timeout to return if "Accessibility timeout" is not set. Specify in milliseconds. | + +--- + +### `isAccessibilityServiceEnabled()`
Android
+ +```tsx +static isAccessibilityServiceEnabled(): Promise; +``` + +Check whether any accessibility service is enabled. This includes TalkBack but also any third-party accessibility app that may be installed. To only check whether TalkBack is enabled, use [isScreenReaderEnabled](#isscreenreaderenabled). Returns a promise which resolves to a boolean. The result is `true` when some accessibility services is enabled and `false` otherwise. + +> **Note**: Please use [isScreenReaderEnabled](#isscreenreaderenabled) if you only want to check the status of TalkBack. + +--- + +### `isBoldTextEnabled()`
iOS
+ +```tsx +static isBoldTextEnabled(): Promise: +``` + +Query whether a bold text is currently enabled. Returns a promise which resolves to a boolean. The result is `true` when bold text is enabled and `false` otherwise. + +--- + +### `isGrayscaleEnabled()`
iOS
+ +```tsx +static isGrayscaleEnabled(): Promise; +``` + +Query whether grayscale is currently enabled. Returns a promise which resolves to a boolean. The result is `true` when grayscale is enabled and `false` otherwise. + +--- + +### `isInvertColorsEnabled()`
iOS
+ +```tsx +static isInvertColorsEnabled(): Promise; +``` + +Query whether invert colors is currently enabled. Returns a promise which resolves to a boolean. The result is `true` when invert colors is enabled and `false` otherwise. + +--- + +### `isReduceMotionEnabled()` + +```tsx +static isReduceMotionEnabled(): Promise; +``` + +Query whether reduce motion is currently enabled. Returns a promise which resolves to a boolean. The result is `true` when reduce motion is enabled and `false` otherwise. + +--- + +### `isReduceTransparencyEnabled()`
iOS
+ +```tsx +static isReduceTransparencyEnabled(): Promise; +``` + +Query whether reduce transparency is currently enabled. Returns a promise which resolves to a boolean. The result is `true` when a reduce transparency is enabled and `false` otherwise. + +--- + +### `isScreenReaderEnabled()` + +```tsx +static isScreenReaderEnabled(): Promise; +``` + +Query whether a screen reader is currently enabled. Returns a promise which resolves to a boolean. The result is `true` when a screen reader is enabled and `false` otherwise. + +--- + +### `prefersCrossFadeTransitions()`
iOS
+ +```tsx +static prefersCrossFadeTransitions(): Promise; +``` + +Query whether reduce motion and prefer cross-fade transitions settings are currently enabled. Returns a promise which resolves to a boolean. The result is `true` when prefer cross-fade transitions is enabled and `false` otherwise. + +--- + +### `setAccessibilityFocus()` + +```tsx +static setAccessibilityFocus(reactTag: number); +``` + +Set accessibility focus to a React component. + +On Android, this calls `UIManager.sendAccessibilityEvent` method with passed `reactTag` and `UIManager.AccessibilityEventTypes.typeViewFocused` arguments. + +> **Note**: Make sure that any `View` you want to receive the accessibility focus has `accessible={true}`. diff --git a/website/versioned_docs/version-0.73.0/actionsheetios.md b/website/versioned_docs/version-0.73.0/actionsheetios.md new file mode 100644 index 00000000000..fd060e0dec9 --- /dev/null +++ b/website/versioned_docs/version-0.73.0/actionsheetios.md @@ -0,0 +1,139 @@ +--- +id: actionsheetios +title: ActionSheetIOS +--- + +Displays native to iOS [Action Sheet](https://developer.apple.com/design/human-interface-guidelines/ios/views/action-sheets/) component. + +## Example + +```SnackPlayer name=ActionSheetIOS&supportedPlatforms=ios +import React, {useState} from 'react'; +import {ActionSheetIOS, Button, StyleSheet, Text, View} from 'react-native'; + +const App = () => { + const [result, setResult] = useState('🔮'); + + const onPress = () => + ActionSheetIOS.showActionSheetWithOptions( + { + options: ['Cancel', 'Generate number', 'Reset'], + destructiveButtonIndex: 2, + cancelButtonIndex: 0, + userInterfaceStyle: 'dark', + }, + buttonIndex => { + if (buttonIndex === 0) { + // cancel action + } else if (buttonIndex === 1) { + setResult(String(Math.floor(Math.random() * 100) + 1)); + } else if (buttonIndex === 2) { + setResult('🔮'); + } + }, + ); + + return ( + + {result} + + + ); +}; + + +// CSS +.container { + display: flex; + justify-content: center; + align-items: center; +} + +``` + +```tsx +// React Native Counter Example using Hooks! + +import React, {useState} from 'react'; +import {View, Text, Button, StyleSheet} from 'react-native'; + +const App = () => { + const [count, setCount] = useState(0); + + return ( + + You clicked {count} times +