A framework for building native macOS apps with React.
Перейти к файлу
Kacie Bawiec d2f314af75 Make ScrollView use ForwardRef
Summary:
Have ScrollView use forwardRef so that the host component methods like `measure` and `measureLayout` are available without having to call `getNativeScrollRef`. Instead, you can use `<ScrollView ref={myRef} />` and directly call all methods of ScrollView and host components on `myRef`.

Previous usage:
```
const myRef = React.createRef<React.ElementRef<typeof ScrollView>>();
<ScrollView ref={myRef} />

const innerViewRef = myRef.current.getNativeScrollRef();

innerViewRef.measure();
```
New usage:
```
const myRef = React.createRef<React.ElementRef<typeof View>>();
<ScrollView ref={myRef} />

// now, myRef.current can be used directly as the ref
myRef.current.measure();
myRef.current.measureLayout();

// Additionally, myRef still has access to ScrollView methods
myRef.current.scrollTo(...);
```

Changes:

* Added deprecation warnings to ScrollView methods `getNativeScrollRef`, `getScrollableNode`, and `getScrollResponder`
* Added the forwardRef call to create `ForwardedScrollView` - this takes in `ref` and passes it into the class ScrollView as `scrollViewRef`.
* Forwarded the ref to the native scroll view using `setAndForwardRef`.
* Added statics onto `ForwardedScrollView` so that `ScrollView.Context` can still be accessed.
* Added type `ScrollViewImperativeMethods`, which lists the public methods of ScrollView.
* Converted all public methods of ScrollView to arrow functions. This is because they need to be bound to the forwarded ref.
* Bound all public methods of ScrollView to the forwarded ref in the `setAndForwardRef` call.
* Flow typed the final output (ForwardedScrollView) as an abstract component that takes in the props of the `ScrollView` class, and has all methods of both the inner host component (`measure`, `measureLayout`, etc) and the public methods (`scrollTo`, etc).

Changes to mockScrollView:
* Changed mockScrollView to be able to mock the function component instead of a class component
* Updated necessary tests

Changelog:
[General] [Changed] - Make ScrollView use forwardRef

Reviewed By: TheSavior

Differential Revision: D19304480

fbshipit-source-id: 6c359897526d9d5ac6bc6ab6d5f9d82bfc0d8af4
2020-03-26 16:53:46 -07:00
.appveyor Update AppVeyor Node versions (#27980) 2020-02-18 16:46:20 -08:00
.circleci Green CI: Fix JavaScript e2e tests, disable failing Android e2e test (#28392) 2020-03-26 06:52:43 -07:00
.github Add Needs: Repro bot action (#28397) 2020-03-26 03:57:42 -07:00
IntegrationTests Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
Libraries Make ScrollView use ForwardRef 2020-03-26 16:53:46 -07:00
RNTester Fix sketchy null checks induced by new formatting in Prettier 2.0 2020-03-25 10:06:24 -07:00
React Fabric: Fixing a deadlock in RCTSurfacePresenter 2020-03-26 10:13:43 -07:00
ReactAndroid Replace fbsource// with // in xplat/js/ files [1] 2020-03-25 21:55:47 -07:00
ReactCommon Replace fbsource// with // in xplat/js/ files [4] 2020-03-26 01:12:50 -07:00
bots Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
docs Generate doc info for RN components 2019-09-19 18:36:25 -07:00
flow Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
flow-typed/npm add react-dom libdef to xplat/js 2020-02-04 16:19:13 -08:00
gradle/wrapper Update Gradle Wrapper to 6.2 (#28112) 2020-02-19 09:09:58 -08:00
jest Make ScrollView use ForwardRef 2020-03-26 16:53:46 -07:00
keystores Use fb_native_wrapper for all targets 2018-10-31 11:47:42 -07:00
local-cli Update references to the CLI (#23052) 2019-01-21 09:13:08 -08:00
packages Update React Hooks Plugin 2020-03-26 14:02:03 -07:00
scripts Green CI: Fix JavaScript e2e tests, disable failing Android e2e test (#28392) 2020-03-26 06:52:43 -07:00
template Deploy Flow 0.121 to Xplat (#901) 2020-03-25 23:22:09 -07:00
third-party-podspecs Upgrade Folly to v2020.01.13.00 (#27810) 2020-01-21 12:44:00 -08:00
tools/build_defs Remove remaining external references to JSC 2020-03-11 21:13:01 -07:00
.buckconfig Migrate to FBJNI (#27729) 2020-01-21 02:32:50 -08:00
.buckjavaargs
.clang-format Moving ObjC specific clang-format rules to the common config 2019-02-11 13:07:09 -08:00
.editorconfig https link to EditorConfig.org (#25267) 2019-06-18 01:58:07 -07:00
.eslintignore Clear some lint warnings (#27893) 2020-01-29 04:36:28 -08:00
.eslintrc Move error-subclass-name lint rule to GitHub 2019-10-09 11:48:07 -07:00
.flowconfig Deploy Flow 0.121 to Xplat (#901) 2020-03-25 23:22:09 -07:00
.flowconfig.android Deploy Flow 0.121 to Xplat (#901) 2020-03-25 23:22:09 -07:00
.gitattributes Re-sync with internal repository 2020-03-13 17:43:04 -07:00
.gitignore Update .gitignore to ignore ReactAndroid generated Gradle files (#28014) 2020-02-12 23:21:32 -08:00
.nvmrc
.prettierrc Set the Prettier config so it is not forced on users of @react-native-community/eslint-config (#24635) 2019-04-29 09:44:51 -07:00
CODE_OF_CONDUCT.md Adopt Contributor Covenant 2019-08-29 23:21:10 -07:00
CONTRIBUTING.md update RN docs link to reactnative.dev (#28175) 2020-02-26 01:21:39 -08:00
ECOSYSTEM.md Add document describing the RN ecosystem. (#24493) 2019-04-17 09:06:37 -07:00
LICENSE Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
LICENSE-docs
README.md Updating the URLs to point at new domain name reactnative.dev 2020-02-24 13:09:11 -08:00
React-Core.podspec Updating the URLs to point at new domain name reactnative.dev 2020-02-24 13:09:11 -08:00
React.podspec Updating the URLs to point at new domain name reactnative.dev 2020-02-24 13:09:11 -08:00
Releases.md Fix typo in Releases.md (#20487) 2018-08-01 07:16:56 -07:00
build.gradle.kts add Detox integrations to Android RNTester app 2020-02-11 10:09:18 -08:00
cli.js Show full price instead of monthly price within the lead form 2019-03-28 16:07:19 -07:00
gradlew Applied missing changes from bumping Gradle wrapper to 6.0.1 (#27639) 2020-01-13 12:54:08 -08:00
gradlew.bat fbshipit-source-id: da15f69185e724eaf7d4bc78dbc61fcdcb3074d5 2020-03-13 21:46:45 -07:00
index.js PlatformColor implementations for iOS and Android (#27908) 2020-03-02 15:12:09 -08:00
interface.js Move `react-native-implementation.js` to `index.js` 2019-09-12 03:29:51 -07:00
jest-preset.js Delete hasteImpl, providesModuleNodeModules, and modulePathNameMapper (#24811) 2019-06-05 10:55:08 -07:00
jest.config.js Tidy up license headers [3/n] 2019-10-16 10:06:34 -07:00
metro.config.js fix warning of root metro config (#27883) 2020-01-29 03:53:42 -08:00
package.json Upgrade React DevTools 4.0.6 -> 4.6.0 2020-03-26 16:45:23 -07:00
react-native.config.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
react.gradle fix: Bundle assets in monorepo (#26940) 2019-11-05 03:08:12 -08:00
rn-get-polyfills.js Remove Polyfills from RN Open Source 2019-04-04 15:20:33 -07:00
runXcodeTests.sh Move non-license comments out of license header 2019-10-15 20:12:12 -07:00
settings.gradle.kts Tidy up license headers 2019-10-22 07:46:08 -07:00
template.config.js Tidy up license headers [3/n] 2019-10-16 10:06:34 -07:00
yarn.lock Upgrade React DevTools 4.0.6 -> 4.6.0 2020-03-26 16:45:23 -07:00

README.md

React Native

Learn once, write anywhere:
Build mobile apps with React.

React Native is released under the MIT license. Current CircleCI build status. Current Appveyor build status. Current npm package version. PRs welcome! Follow @reactnative

Getting Started · Learn the Basics · Showcase · Contribute · Community · Support

React Native brings React's declarative UI framework to iOS and Android. With React Native, you use native UI controls and have full access to the native platform.

  • Declarative. React makes it painless to create interactive UIs. Declarative views make your code more predictable and easier to debug.
  • Component-Based. Build encapsulated components that manage their state, then compose them to make complex UIs.
  • Developer Velocity. See local changes in seconds. Changes to JavaScript code can be live reloaded without rebuilding the native app.
  • Portability. Reuse code across iOS, Android, and other platforms.

React Native is developed and supported by many companies and individual core contributors. Find out more in our ecosystem overview.

Contents

📋 Requirements

React Native apps may target iOS 10.0 and Android 4.1 (API 16) or newer. You may use Windows, macOS, or Linux as your development operating system, though building and running iOS apps is limited to macOS. Tools like Expo can be used to work around this.

🎉 Building your first React Native app

Follow the Getting Started guide. The recommended way to install React Native depends on your project. Here you can find short guides for the most common scenarios:

📖 Documentation

The full documentation for React Native can be found on our website.

The React Native documentation discusses components, APIs, and topics that are specific to React Native. For further documentation on the React API that is shared between React Native and React DOM, refer to the React documentation.

The source for the React Native documentation and website is hosted on a separate repo, @facebook/react-native-website.

🚀 Upgrading

Upgrading to new versions of React Native may give you access to more APIs, views, developer tools, and other goodies. See the Upgrading Guide for instructions.

React Native releases are discussed in the React Native Community, @react-native-community/react-native-releases.

👏 How to Contribute

The main purpose of this repository is to continue evolving React Native core. We want to make contributing to this project as easy and transparent as possible, and we are grateful to the community for contributing bug fixes and improvements. Read below to learn how you can take part in improving React Native.

Code of Conduct

Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Contributing Guide

Read our Contributing Guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React Native.

Open Source Roadmap

You can learn more about our vision for React Native in the Roadmap.

Good First Issues

We have a list of good first issues that contain bugs which have a relatively limited scope. This is a great place to get started, gain experience, and get familiar with our contribution process.

Discussions

Larger discussions and proposals are discussed in @react-native-community/discussions-and-proposals.

📄 License

React Native is MIT licensed, as found in the LICENSE file.

React Native documentation is Creative Commons licensed, as found in the LICENSE-docs file.