diff --git a/.circleci/README.md b/.circleci/README.md new file mode 100644 index 00000000000000..9c944ef6d105c0 --- /dev/null +++ b/.circleci/README.md @@ -0,0 +1,5 @@ +# Circle CI + +This directory is home to the Circle CI configuration file. Circle is our continuous integration service provider. You can see the overall status of React Native's builds at https://circleci.com/gh/facebook/react-native + +You may also see an individual PR's build status by scrolling down to the Checks section in the PR. diff --git a/.circleci/config.yml b/.circleci/config.yml index 27e9ccbecdb154..1b75edce484827 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,56 +1,52 @@ aliases: - - &restore-node-cache + # Cache Management + - &restore-yarn-cache keys: - - v1-dependencies-{{ arch }}-{{ checksum "package.json" }} + - v1-yarn-{{ arch }}-{{ checksum "package.json" }} # Fallback in case checksum fails - - v1-dependencies-{{ arch }}- - - - &save-node-cache + - v1-yarn-{{ arch }}- + - &save-yarn-cache paths: - node_modules - key: v1-dependencies-{{ arch }}-{{ checksum "package.json" }} + - ~/.cache/yarn + key: v1-yarn-{{ arch }}-{{ checksum "package.json" }} - &restore-cache-analysis keys: - - v1-analysis-dependencies-{{ arch }}-{{ checksum "package.json" }}{{ checksum "danger/package.json" }} + - v1-analysis-dependencies-{{ arch }}-{{ checksum "package.json" }}{{ checksum "bots/package.json" }} # Fallback in case checksum fails - v1-analysis-dependencies-{{ arch }}- - &save-cache-analysis paths: - - danger/node_modules + - bots/node_modules - node_modules - key: v1-analysis-dependencies-{{ arch }}-{{ checksum "package.json" }}{{ checksum "danger/package.json" }} + key: v1-analysis-dependencies-{{ arch }}-{{ checksum "package.json" }}{{ checksum "bots/package.json" }} - &restore-cache-android-packages keys: - - v2-android-sdkmanager-packages-{{ arch }}-{{ checksum "scripts/circle-ci-android-setup.sh" }} + - v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-{{ checksum "scripts/circle-ci-android-setup.sh" }} # Fallback in case checksum fails - - v2-android-sdkmanager-packages-{{ arch }}- + - v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha- - &save-cache-android-packages paths: - /opt/android/sdk - key: v2-android-sdkmanager-packages-{{ arch }}-{{ checksum "scripts/circle-ci-android-setup.sh" }} + key: v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-{{ checksum "scripts/circle-ci-android-setup.sh" }} - &restore-cache-ndk keys: - - v1-android-ndk-{{ arch }}-r10e-32-64 - - - &install-ndk - | - source scripts/circle-ci-android-setup.sh && getAndroidNDK - + - v2-android-ndk-{{ arch }}-r10e-32-64 - &save-cache-ndk paths: - /opt/ndk - key: v1-android-ndk-{{ arch }}-r10e-32-64 + key: v2-android-ndk-{{ arch }}-r10e-32-64 - &restore-cache-buck keys: - - v2-buck-{{ arch }}-v2017.11.16.01 + - v2-buck-{{ arch }}-v2018.02.16.01 - &save-cache-buck paths: - ~/buck - key: v2-buck-{{ arch }}-v2017.11.16.01 + key: v2-buck-{{ arch }}-v2018.02.16.01 - &restore-cache-watchman keys: @@ -60,36 +56,7 @@ aliases: - ~/watchman key: v1-watchman-{{ arch }}-v4.9.0 - - &install-node-dependencies - | - npm install --no-package-lock --no-spin --no-progress - - - &install-buck - | - if [[ ! -e ~/buck ]]; then - git clone https://github.com/facebook/buck.git ~/buck --branch v2017.11.16.01 --depth=1 - fi - cd ~/buck && ant - buck --version - - - &install-node - | - curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - - sudo apt-get install -y nodejs - - - &run-node-tests - | - npm test -- --maxWorkers=2 - - - &run-lint-checks - | - npm run lint - - - &run-flow-checks - | - npm run flow -- check - - + # Branch Filtering - &filter-only-master-stable branches: only: @@ -112,8 +79,41 @@ aliases: - /.*-stable/ - gh-pages - - &create-ndk-directory + # Dependency Management + - &install-ndk + | + source scripts/circle-ci-android-setup.sh && getAndroidNDK + + - &yarn + | + yarn install --non-interactive --cache-folder ~/.cache/yarn + + - &install-yarn | + curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - + echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list + sudo apt-get update && sudo apt-get install yarn + + - &install-node-dependencies + | + npm install --no-package-lock --no-spin --no-progress + + - &install-buck + | + if [[ ! -e ~/buck ]]; then + git clone https://github.com/facebook/buck.git ~/buck --branch v2018.02.16.01 --depth=1 + fi + cd ~/buck && ant + buck --version + + - &install-node + | + curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - + sudo apt-get install -y nodejs + + - &create-ndk-directory + name: Create Android NDK Directory + command: | if [[ ! -e /opt/ndk ]]; then sudo mkdir /opt/ndk fi @@ -122,7 +122,8 @@ aliases: # CircleCI does not support interpolating env variables in the environment # https://circleci.com/docs/2.0/env-vars/#interpolating-environment-variables-to-set-other-environment-variables - &configure-android-path - | + name: Configure Environment Variables + command: | echo 'export PATH=${ANDROID_NDK}:~/react-native/gradle-2.9/bin:~/buck/bin:$PATH' >> $BASH_ENV source $BASH_ENV @@ -130,29 +131,54 @@ aliases: | source scripts/circle-ci-android-setup.sh && getAndroidSDK - - &install-build-dependencies - | + - &install-android-build-dependencies + name: Install Android Build Dependencies + command: | sudo apt-get update -y sudo apt-get install ant autoconf automake g++ gcc libqt5widgets5 lib32z1 lib32stdc++6 make maven python-dev python3-dev qml-module-qtquick-controls qtdeclarative5-dev file -y + # Test Definitions + - &run-js-tests + name: JavaScript Test Suite + command: yarn test-ci + + - &run-lint-checks + name: Lint code + command: yarn lint --format junit -o ~/react-native/reports/junit/js-lint-results.xml + when: always + + - &run-flow-checks + name: Check for errors in code using Flow + command: yarn flow check + when: always + + - &run-license-checks + name: Check license + command: ./scripts/circleci/check_license.sh + when: always + - &build-android-app name: Build Android App command: | buck build ReactAndroid/src/main/java/com/facebook/react buck build ReactAndroid/src/main/java/com/facebook/react/shell + - &create-avd + name: Create Android Virtual Device + command: source scripts/circle-ci-android-setup.sh && createAVD + + - &launch-avd + name: Launch Android Virtual Device in Background + command: source scripts/circle-ci-android-setup.sh && launchAVD + background: true + - &wait-for-avd name: Wait for Android Virtual Device command: source scripts/circle-ci-android-setup.sh && waitForAVD - - &check-js-bundle - name: Check for JavaScript Bundle - command: | - if [[ ! -e ReactAndroid/src/androidTest/assets/AndroidTestBundle.js ]]; then - echo "JavaScript bundle missing, verify build-js-bundle step"; exit 1; - else - echo "JavaScript bundle found."; - fi + - &build-js-bundle + name: Build JavaScript Bundle + command: node local-cli/cli.js bundle --max-workers 2 --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js - &compile-native-libs name: Compile Native Libs for Unit and Integration Tests @@ -160,24 +186,62 @@ aliases: no_output_timeout: 6m - &run-android-unit-tests - name: Unit Tests + name: Run Unit Tests command: buck test ReactAndroid/src/test/... --config build.threads=$BUILD_THREADS - - &run-android-integration-tests - name: Build and Install Test APK - command: source scripts/circle-ci-android-setup.sh && NO_BUCKD=1 retry3 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=$BUILD_THREADS + - &run-android-instrumentation-tests + name: Run Instrumentation Tests + command: | + if [[ ! -e ReactAndroid/src/androidTest/assets/AndroidTestBundle.js ]]; then + echo "JavaScript bundle missing, cannot run instrumentation tests. Verify build-js-bundle step completed successfully."; exit 1; + fi + source scripts/circle-ci-android-setup.sh && NO_BUCKD=1 retry3 timeout 300 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=$BUILD_THREADS - &collect-android-test-results name: Collect Test Results command: | - mkdir -p ~/junit/ - find . -type f -regex ".*/build/test-results/debug/.*xml" -exec cp {} ~/junit/ \; - find . -type f -regex ".*/outputs/androidTest-results/connected/.*xml" -exec cp {} ~/junit/ \; + find . -type f -regex ".*/build/test-results/debug/.*xml" -exec cp {} ~/react-native/reports/junit/ \; + find . -type f -regex ".*/outputs/androidTest-results/connected/.*xml" -exec cp {} ~/react-native/reports/junit/ \; + find . -type f -regex ".*/buck-out/gen/ReactAndroid/src/test/.*/.*xml" -exec cp {} ~/react-native/reports/junit/ \; when: always + - &setup-artifacts + name: Initial Setup + command: | + mkdir -p ~/react-native/reports/junit/ + + - &build-objc-ios-test-app + name: Build iOS Test App + command: ./scripts/objc-test-ios.sh + + - &run-objc-ios-tests + name: iOS Test Suite + command: ./scripts/objc-test-ios.sh test + + - &build-objc-tvos-test-app + name: Build tvOS Test App + command: ./scripts/objc-test-tvos.sh + + - &run-objc-tvos-tests + name: tvOS Test Suite + command: ./scripts/objc-test-tvos.sh test + + - &run-objc-ios-e2e-tests + name: iOS End-to-End Test Suite + command: node ./scripts/run-ci-e2e-tests.js --ios --js --retries 3; + + - &run-objc-tvos-e2e-tests + name: tvOS End-to-End Test Suite + command: node ./scripts/run-ci-e2e-tests.js --tvos --js --retries 3; + defaults: &defaults working_directory: ~/react-native +js_defaults: &js_defaults + <<: *defaults + docker: + - image: circleci/node:8 + android_defaults: &android_defaults <<: *defaults docker: @@ -191,125 +255,151 @@ android_defaults: &android_defaults - ANDROID_NDK: '/opt/ndk/android-ndk-r10e' - BUILD_THREADS: 2 +macos_defaults: &macos_defaults + <<: *defaults + macos: + xcode: "9.2.0" + version: 2 jobs: - # Runs JavaScript lint and flow checks - run-js-checks: - <<: *defaults - docker: - - image: circleci/node:8 + + # Set up a Node environment for downstream jobs + checkout_code: + <<: *js_defaults steps: - checkout - - restore-cache: *restore-node-cache - - run: *install-node-dependencies - - save-cache: *save-node-cache + - run: *setup-artifacts + + - restore-cache: *restore-yarn-cache + - run: *yarn + - save-cache: *save-yarn-cache + + - persist_to_workspace: + root: . + paths: . + + # Runs JavaScript lint and flow checks. + # Currently will fail a PR if lint/flow raises issues. + analyze: + <<: *js_defaults + steps: + - attach_workspace: + at: ~/react-native + - run: *run-lint-checks - run: *run-flow-checks + - run: *run-license-checks + + - store_test_results: + path: ~/react-native/reports/junit + - store_artifacts: + path: ~/react-native/yarn.lock # Runs JavaScript tests on Node 8 - test-js-node-8: - <<: *defaults - docker: - - image: circleci/node:8 + test_javascript: + <<: *js_defaults steps: - - checkout - - restore-cache: *restore-node-cache - - run: *install-node-dependencies - - save-cache: *save-node-cache - - run: *run-node-tests + - attach_workspace: + at: ~/react-native + + - run: *run-js-tests + + - store_test_results: + path: ~/react-native/reports/junit # Runs JavaScript tests on Node 6 - test-js-node-6: + test_javascript_node6_compatibility: <<: *defaults docker: - image: circleci/node:6 steps: - checkout - - restore-cache: *restore-node-cache - - run: *install-node-dependencies - - save-cache: *save-node-cache - - run: *run-node-tests + - run: *setup-artifacts + + - restore-cache: *restore-yarn-cache + - run: *yarn + - save-cache: *save-yarn-cache + + - run: *run-js-tests + + - store_test_results: + path: ~/react-native/reports/junit # Runs unit tests on iOS devices - test-objc-ios: - <<: *defaults - macos: - xcode: "9.0" - dependencies: - pre: - - xcrun instruments -w "iPhone 5s (10.3.1)" || true + test_ios: + <<: *macos_defaults steps: - - checkout - - restore-cache: *restore-node-cache - - run: *install-node-dependencies - - save-cache: *save-node-cache - - run: ./scripts/objc-test-ios.sh + - attach_workspace: + at: ~/react-native + + - run: xcrun instruments -w "iPhone 5s (11.1)" || true + - run: brew install watchman + - run: *run-objc-ios-tests + + - store_test_results: + path: ~/react-native/reports/junit # Runs unit tests on tvOS devices - test-objc-tvos: - <<: *defaults - macos: - xcode: "9.0" - dependencies: - pre: - - xcrun instruments -w "Apple TV 1080p (10.0)" || true + test_tvos: + <<: *macos_defaults steps: - - checkout - - restore-cache: *restore-node-cache - - run: *install-node-dependencies - - save-cache: *save-node-cache - - run: ./scripts/objc-test-tvos.sh + - attach_workspace: + at: ~/react-native + + - run: xcrun instruments -w "Apple TV 1080p (11.1)" || true + - run: brew install watchman + - run: *run-objc-tvos-tests + + - store_test_results: + path: ~/react-native/reports/junit # Runs end to end tests - test-objc-e2e: - <<: *defaults - macos: - xcode: "9.0" - dependencies: - pre: - - xcrun instruments -w "iPhone 5s (10.3.1)" || true + test_ios_e2e: + <<: *macos_defaults steps: - - checkout - - restore-cache: *restore-node-cache - - run: *install-node-dependencies - - save-cache: *save-node-cache - - run: node ./scripts/run-ci-e2e-tests.js --ios --js --retries 3; + - attach_workspace: + at: ~/react-native + + - run: xcrun instruments -w "iPhone 5s (11.1)" || true + - run: *run-objc-ios-e2e-tests + + - store_test_results: + path: ~/react-native/reports/junit # Checks podspec - test-podspec: - <<: *defaults - macos: - xcode: "9.0" + test_podspec: + <<: *macos_defaults steps: - - checkout - - restore-cache: *restore-node-cache - - run: *install-node-dependencies - - save-cache: *save-node-cache + - attach_workspace: + at: ~/react-native + - run: ./scripts/process-podspecs.sh # Publishes new version onto npm - deploy: + publish_npm_package: <<: *android_defaults steps: + # Checkout code so that we can work with `git` in publish.js - checkout - - # Configure Android dependencies + + # Configure Android SDK and related dependencies - run: *configure-android-path - - run: *install-build-dependencies + - run: *install-android-build-dependencies - restore-cache: *restore-cache-android-packages - run: *install-android-packages - save-cache: *save-cache-android-packages + + # Install Android NDK - run: *create-ndk-directory - restore-cache: *restore-cache-ndk - run: *install-ndk - save-cache: *save-cache-ndk + + # Fetch dependencies using BUCK - restore-cache: *restore-cache-buck - run: *install-buck - save-cache: *save-cache-buck - - run: *install-node - - restore-cache: *restore-node-cache - - run: *install-node-dependencies - - save-cache: *save-node-cache + - run: buck fetch ReactAndroid/src/test/java/com/facebook/react/modules - run: buck fetch ReactAndroid/src/main/java/com/facebook/react - run: buck fetch ReactAndroid/src/main/java/com/facebook/react/shell @@ -317,6 +407,12 @@ jobs: - run: buck fetch ReactAndroid/src/androidTest/... - run: ./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog :ReactAndroid:downloadJSCHeaders + - run: *install-node + - run: *install-yarn + - restore-cache: *restore-yarn-cache + - run: *yarn + - save-cache: *save-yarn-cache + - run: name: Publish React Native Package command: | @@ -330,64 +426,37 @@ jobs: echo "Skipping deploy." fi - # Build JavaScript bundle for Android tests - build-js-bundle: - <<: *defaults - docker: - - image: circleci/node:8 - steps: - - checkout - - restore-cache: *restore-node-cache - - run: *install-node-dependencies - - save-cache: *save-node-cache - - run: - name: Build JavaScript Bundle - command: node local-cli/cli.js bundle --max-workers 2 --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js - - persist_to_workspace: - root: ReactAndroid/src/androidTest/assets/ - paths: - - AndroidTestBundle.js - - store_artifacts: - path: ReactAndroid/src/androidTest/assets/AndroidTestBundle.js - - # Runs unit tests tests on Android - test-android: + # Set up an Android environment for downstream jobs + test_android: <<: *android_defaults steps: - - checkout - - # Configure Android dependencies + - attach_workspace: + at: ~/react-native + + # Configure Android SDK and related dependencies - run: *configure-android-path - - run: *install-build-dependencies + - run: *install-android-build-dependencies - restore-cache: *restore-cache-android-packages - run: *install-android-packages - save-cache: *save-cache-android-packages # Starting emulator in advance as it takes some time to boot. - - run: - name: Create Android Virtual Device - command: source scripts/circle-ci-android-setup.sh && createAVD - - run: - name: Launch Android Virtual Device in Background - command: source scripts/circle-ci-android-setup.sh && launchAVD - background: true - + - run: *create-avd + - run: *launch-avd + # Keep configuring Android dependencies while AVD boots up + + # Install Android NDK - run: *create-ndk-directory - restore-cache: *restore-cache-ndk - run: *install-ndk - save-cache: *save-cache-ndk + # Fetch dependencies using BUCK - restore-cache: *restore-cache-buck - run: *install-buck - save-cache: *save-cache-buck - - run: *install-node - - - restore-cache: *restore-node-cache - - run: *install-node-dependencies - - save-cache: *save-node-cache - - run: buck fetch ReactAndroid/src/test/java/com/facebook/react/modules - run: buck fetch ReactAndroid/src/main/java/com/facebook/react - run: buck fetch ReactAndroid/src/main/java/com/facebook/react/shell @@ -395,53 +464,56 @@ jobs: - run: buck fetch ReactAndroid/src/androidTest/... - run: ./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog :ReactAndroid:downloadJSCHeaders + # Build and compile - run: *build-android-app - run: *compile-native-libs - # The JavaScript Bundle is built as part of the build-js-bundle workflow, - # and is required for instrumentation tests. - - attach_workspace: - at: ReactAndroid/src/androidTest/assets/ - - run: *check-js-bundle + # Build JavaScript Bundle for instrumentation tests + - run: *install-node + - run: *build-js-bundle # Wait for AVD to finish booting before running tests - run: *wait-for-avd - # Tests + # Test Suite - run: *run-android-unit-tests - - run: *run-android-integration-tests + - run: *run-android-instrumentation-tests # post (always runs) - run: *collect-android-test-results - store_test_results: - path: ~/junit - - store_artifacts: - path: ~/junit + path: ~/react-native/reports/junit - analyze-pull-request: - <<: *defaults - docker: - - image: circleci/node:8 + + # Analyze pull request and raise any lint/flow issues. + # Issues will be posted to the PR itself via GitHub bots. + # This workflow should only fail if the bots fail to run. + analyze_pr: + <<: *js_defaults steps: - - checkout + - attach_workspace: + at: ~/react-native + - restore-cache: *restore-cache-analysis - - run: *install-node-dependencies + - run: *yarn - run: - name: Install Dependencies + name: Install Additional Dependencies command: | - if [ -n "$CIRCLE_PULL_REQUEST" ]; then - npm install github@0.2.4 - cd danger - npm install --no-package-lock --no-spin --no-progress + if [ -n "$CIRCLE_PR_NUMBER" ]; then + yarn add github@0.2.4 + cd bots + yarn install --non-interactive --cache-folder ~/.cache/yarn else echo "Skipping dependency installation." fi - save-cache: *save-cache-analysis + - run: name: Analyze Pull Request command: | - if [ -n "$CIRCLE_PULL_REQUEST" ]; then - cd danger && DANGER_GITHUB_API_TOKEN="e622517d9f1136ea8900""07c6373666312cdfaa69" npm run danger + # DANGER_GITHUB_API_TOKEN=Facebook-Open-Source-Bot public_repo access token + if [ -n "$CIRCLE_PR_NUMBER" ]; then + cd bots && DANGER_GITHUB_API_TOKEN="b186c9a82bab3b08ec80""c0818117619eec6f281a" yarn danger else echo "Skipping pull request analysis." fi @@ -449,52 +521,102 @@ jobs: - run: name: Analyze Code command: | - if [ -n "$CIRCLE_PULL_REQUEST" ]; then - cat <(echo eslint; npm run lint --silent -- --format=json; echo flow; npm run flow --silent -- check --json) | GITHUB_TOKEN="af6ef0d15709bc91d""06a6217a5a826a226fb57b7" CI_USER=$CIRCLE_PROJECT_USERNAME CI_REPO=$CIRCLE_PROJECT_REPONAME PULL_REQUEST_NUMBER=$CIRCLE_PR_NUMBER node bots/code-analysis-bot.js + # GITHUB_TOKEN=eslint-bot public_repo access token + if [ -n "$CIRCLE_PR_NUMBER" ]; then + cat <(echo eslint; yarn --silent lint --format=json; echo flow; yarn --silent flow check --json) | GITHUB_TOKEN="af6ef0d15709bc91d""06a6217a5a826a226fb57b7" CI_USER=$CIRCLE_PROJECT_USERNAME CI_REPO=$CIRCLE_PROJECT_REPONAME PULL_REQUEST_NUMBER=$CIRCLE_PR_NUMBER node bots/code-analysis-bot.js else echo "Skipping code analysis." fi when: always - + # Workflows enables us to run multiple jobs in parallel workflows: version: 2 - build: + tests: jobs: - # Run lint and flow checks - - run-js-checks: + # Checkout repo and run Yarn + - checkout_code: + filters: *filter-ignore-gh-pages + + # Run lint, flow, and other checks + - analyze: filters: *filter-ignore-gh-pages + requires: + - checkout_code - # Test JavaScript on Node 8 and 6 - - test-js-node-8: + # Test JavaScript + - test_javascript: filters: *filter-ignore-gh-pages - - test-js-node-6: + requires: + - checkout_code + + # Test JavaScript using Node 6, the minimum supported version + - test_javascript_node6_compatibility: filters: *filter-ignore-gh-pages # Test Android - - build-js-bundle: + - test_android: filters: *filter-ignore-gh-pages - - test-android: requires: - - build-js-bundle + - checkout_code # Test iOS & tvOS - - test-objc-ios: + - test_ios: filters: *filter-ignore-gh-pages - - test-objc-tvos: + requires: + - checkout_code + - test_tvos: filters: *filter-ignore-gh-pages - - test-objc-e2e: + requires: + - checkout_code + + # End-to-end tests + - test_ios_e2e: filters: *filter-ignore-gh-pages - - # If we are on a stable branch, deploy to `npm` - - hold: - type: approval - - deploy: - filters: *filter-only-stable requires: - - hold - - - analyze-pull-request: + - checkout_code + + # Only runs on PRs + analyze: + jobs: + # Checkout repo and run Yarn + - checkout_code: + filters: *filter-ignore-master-stable + + # Run code checks + - analyze_pr: filters: *filter-ignore-master-stable + requires: + - checkout_code + + # Only runs on NN-stable branches + deploy: + jobs: + # If we are on a stable branch, wait for approval to deploy to npm + - approve_publish_npm_package: + filters: *filter-only-stable + type: approval + + - publish_npm_package: + requires: + - approve_publish_npm_package + + # These tests are flaky or are yet to be fixed. They are placed on their own + # workflow to avoid marking benign PRs as broken. + # To run them, uncomment the entire block and open a PR (do not merge). + # Once a test is fixed, move the test definition to the 'tests' workflow. + # disabled_tests: + # jobs: + # # Checkout repo and run Yarn (pre-req, should succeed) + # - checkout_code: + # filters: *filter-ignore-gh-pages + + # # The following were DISABLED because they have not run since + # # the migration from Travis, and they have broken since then, + # # CocoaPods + # - test_podspec: + # filters: *filter-ignore-gh-pages + # requires: + # - checkout_code diff --git a/.eslintrc b/.eslintrc index 3f1c59d4df004b..2c1f512a16ce28 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,10 +3,6 @@ "parser": "babel-eslint", - "ecmaFeatures": { - "jsx": true - }, - "env": { "es6": true, "jest": true, @@ -173,10 +169,10 @@ // ESLint Comments Plugin // The following rules are made available via `eslint-plugin-eslint-comments` - 'eslint-comments/no-aggregating-enable': 1, // disallows eslint-enable comments for multiple eslint-disable comments - 'eslint-comments/no-unlimited-disable': 1, // disallows eslint-disable comments without rule names - 'eslint-comments/no-unused-disable': 1, // disallow disables that don't cover any errors - 'eslint-comments/no-unused-enable': 1, // // disallow enables that don't enable anything or enable rules that weren't disabled + "eslint-comments/no-aggregating-enable": 1, // disallows eslint-enable comments for multiple eslint-disable comments + "eslint-comments/no-unlimited-disable": 1, // disallows eslint-disable comments without rule names + "eslint-comments/no-unused-disable": 1, // disallow disables that don't cover any errors + "eslint-comments/no-unused-enable": 1, // // disallow enables that don't enable anything or enable rules that weren't disabled // Flow Plugin // The following rules are made available via `eslint-plugin-flowtype` @@ -205,7 +201,7 @@ "new-parens": 1, // disallow the omission of parentheses when invoking a constructor with no arguments "no-nested-ternary": 0, // disallow nested ternary expressions (off by default) "no-array-constructor": 1, // disallow use of the Array constructor - 'no-empty-character-class': 1, // disallow the use of empty character classes in regular expressions + "no-empty-character-class": 1, // disallow the use of empty character classes in regular expressions "no-lonely-if": 0, // disallow if as the only statement in an else block (off by default) "no-new-object": 1, // disallow use of the Object constructor "no-spaced-func": 1, // disallow space between function identifier and application @@ -262,5 +258,37 @@ "jest/no-focused-tests": 1, "jest/no-identical-title": 1, "jest/valid-expect": 1, - } + }, + + "overrides": [ + { + "files": [ + "Libraries/**/*.js", + "RNTester/**/*.js", + "jest/**/*.js", + ], + "rules": { + // These folders currently run through babel and don't need to be + // compatible with node 4 + "comma-dangle": 0, + }, + }, + { + "files": [ + "local-cli/**/*.js", + ], + "rules": { + // This folder currently runs through babel and doesn't need to be + // compatible with node 4 + "comma-dangle": 0, + + "lint/extra-arrow-initializer": 0, + "no-alert": 0, + "no-console-disallow": 0, + }, + "env": { + "node": true, + }, + }, + ], } diff --git a/.flowconfig b/.flowconfig index d2a66865c6fc6b..b7aa19446d88dc 100644 --- a/.flowconfig +++ b/.flowconfig @@ -6,7 +6,7 @@ .*/local-cli/templates/.* ; Ignore the Dangerfile -/danger/dangerfile.js +/bots/dangerfile.js ; Ignore "BUCK" generated dirs /\.buckd/ @@ -52,4 +52,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError [version] -^0.63.0 +^0.66.0 diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 1f642ca4fb1b84..bbe1d31e0b8f46 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,122 +1,29 @@ -### Is this a bug report? - -(write your answer here) - - - -### Have you read the [Contributing Guidelines](https://facebook.github.io/react-native/docs/contributing.html)? - -(Write your answer here.) +(Describe your issue in detail.) ### Environment - - -### Steps to Reproduce - - - -(Write your steps here:) - -1. -2. -3. +(Run `react-native info` in your terminal and paste its contents here.) ### Expected Behavior - - (Write what you thought would happen.) ### Actual Behavior - +(Write what happened. Include screenshots if needed.) -(Write what happened. Add screenshots!) +### Steps to Reproduce -### Reproducible Demo +(Link to Snack, or steps to reproduce.) - -(Paste the link to an example project and exact instructions to reproduce the issue.) - - diff --git a/.github/stale.yml b/.github/stale.yml index dc018b58604d55..a738daf3783295 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -1,7 +1,7 @@ # Number of days of inactivity before an issue becomes stale -daysUntilStale: 60 +daysUntilStale: 180 # Number of days of inactivity before a stale issue is closed -daysUntilClose: 7 +daysUntilClose: 60 # Issues with these labels will never be considered stale exemptLabels: - Good first issue @@ -11,10 +11,10 @@ exemptLabels: staleLabel: Stale # Comment to post when marking an issue as stale. Set to `false` to disable markComment: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs. - Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. - If you think this issue should definitely remain open, please let us know why. + Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. + You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions. # Comment to post when closing a stale issue. Set to `false` to disable -closeComment: false +closeComment: > + Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information. +only: issues \ No newline at end of file diff --git a/.gitignore b/.gitignore index 15a2a9668a1a9f..19c3bbdce24975 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,9 @@ buck-out /ReactAndroid/src/main/jni/prebuilt/lib/x86/ /ReactAndroid/src/main/gen +# Watchman +.watchmanconfig + # Android .idea .gradle @@ -47,7 +50,11 @@ local.properties node_modules *.log .nvm -/danger/node_modules/ +/bots/node_modules/ + +# TODO: Check in yarn.lock in open source. Right now we need to keep it out +# from the GitHub repo as importing it might conflict with internal workspaces +*/**/yarn.lock # OS X .DS_Store diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 86206c295af7e5..bc151d02603d62 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,7 +14,7 @@ There are many ways to contribute to React Native, and many of them do not invol * Simply start using React Native. Go through the [Getting Started](https://facebook.github.io/react-native/docs/getting-started.html) guide. Does everything work as expected? If not, we're always looking for improvements. Let us know by [opening an issue](https://facebook.github.io/react-native/docs/contributing.html#reporting-new-issues). * Look through the [open issues](https://github.com/facebook/react-native/issues). Provide workarounds, ask for clarification, or suggest labels. Help [triage issues](https://facebook.github.io/react-native/docs/contributing.html#triaging-issues-and-pull-requests). * If you find an issue you would like to fix, [open a pull request](https://facebook.github.io/react-native/docs/contributing.html#your-first-pull-request). Issues tagged as [_Good first issue_](https://github.com/facebook/react-native/labels/Good%20first%20issue) are a good place to get started. -* Read through the [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html). If you find anything that is confusing or can be improved, you can make edits by clicking "Improve this page" at the bottom of most docs. +* Read through the [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html). If you find anything that is confusing or can be improved, you can make edits by clicking the "EDIT" button in the top-right corner of most docs. * Browse [Stack Overflow](https://stackoverflow.com/questions/tagged/react-native) and answer questions. This will help you get familiarized with common pitfalls or misunderstandings, which can be useful when contributing updates to the documentation. * Take a look at the [features requested](https://react-native.canny.io/feature-requests) by others in the community and consider opening a pull request if you see something you want to work on. @@ -78,7 +78,7 @@ Working on your first Pull Request? You can learn how from this free video serie [**How to Contribute to an Open Source Project on GitHub**](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github) -We have a list of [beginner friendly issues](https://github.com/facebook/react-native/labels/Good%20First%20Task) to help you get your feet wet in the React Native codebase and familiar with our contribution process. This is a great place to get started. +We have a list of [beginner friendly issues](https://github.com/facebook/react-native/labels/Good%20first%20issue) to help you get your feet wet in the React Native codebase and familiar with our contribution process. This is a great place to get started. ### Proposing a change @@ -141,11 +141,9 @@ Copy and paste this to the top of your new file(s): ```JS /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ ``` @@ -210,5 +208,5 @@ However, there are still some styles that the linter cannot pick up. ## License -By contributing to React Native, you agree that your contributions will be licensed under its BSD license. +By contributing to React Native, you agree that your contributions will be licensed under its MIT license. diff --git a/ContainerShip/scripts/run-android-ci-instrumentation-tests.js b/ContainerShip/scripts/run-android-ci-instrumentation-tests.js index 34ee3336a168d2..706159c4902bc4 100644 --- a/ContainerShip/scripts/run-android-ci-instrumentation-tests.js +++ b/ContainerShip/scripts/run-android-ci-instrumentation-tests.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ 'use strict'; diff --git a/IntegrationTests/AccessibilityManagerTest.js b/IntegrationTests/AccessibilityManagerTest.js index dfa9e9a19f289d..74dbe9ba19edab 100644 --- a/IntegrationTests/AccessibilityManagerTest.js +++ b/IntegrationTests/AccessibilityManagerTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule AccessibilityManagerTest diff --git a/IntegrationTests/AppEventsTest.js b/IntegrationTests/AppEventsTest.js index 62299ec337858d..ae061e167b86d8 100644 --- a/IntegrationTests/AppEventsTest.js +++ b/IntegrationTests/AppEventsTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AppEventsTest * @flow diff --git a/IntegrationTests/AsyncStorageTest.js b/IntegrationTests/AsyncStorageTest.js index ef7df1f1f365e5..3ce0265dd8ceb0 100644 --- a/IntegrationTests/AsyncStorageTest.js +++ b/IntegrationTests/AsyncStorageTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule AsyncStorageTest diff --git a/IntegrationTests/ImageCachePolicyTest.js b/IntegrationTests/ImageCachePolicyTest.js index 29b5e68d1d2117..d6fa4f544a1bf9 100644 --- a/IntegrationTests/ImageCachePolicyTest.js +++ b/IntegrationTests/ImageCachePolicyTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule ImageCachePolicyTest diff --git a/IntegrationTests/ImageSnapshotTest.js b/IntegrationTests/ImageSnapshotTest.js index ccb232796927ca..8ba7734286d673 100644 --- a/IntegrationTests/ImageSnapshotTest.js +++ b/IntegrationTests/ImageSnapshotTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule ImageSnapshotTest diff --git a/IntegrationTests/IntegrationTestHarnessTest.js b/IntegrationTests/IntegrationTestHarnessTest.js index 7c9f2527cabbd0..6291c915d68643 100644 --- a/IntegrationTests/IntegrationTestHarnessTest.js +++ b/IntegrationTests/IntegrationTestHarnessTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule IntegrationTestHarnessTest diff --git a/IntegrationTests/IntegrationTestsApp.js b/IntegrationTests/IntegrationTestsApp.js index 0594e289b7b145..6b255c2befe54a 100644 --- a/IntegrationTests/IntegrationTestsApp.js +++ b/IntegrationTests/IntegrationTestsApp.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule IntegrationTestsApp diff --git a/IntegrationTests/LayoutEventsTest.js b/IntegrationTests/LayoutEventsTest.js index ab7bc6040d113d..769ff98f6be8b5 100644 --- a/IntegrationTests/LayoutEventsTest.js +++ b/IntegrationTests/LayoutEventsTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule LayoutEventsTest * @flow diff --git a/IntegrationTests/LoggingTestModule.js b/IntegrationTests/LoggingTestModule.js index ec07f3271bf700..25b409353ce1d4 100644 --- a/IntegrationTests/LoggingTestModule.js +++ b/IntegrationTests/LoggingTestModule.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule LoggingTestModule */ diff --git a/IntegrationTests/PromiseTest.js b/IntegrationTests/PromiseTest.js index 9cf8651e3a3511..f6a81e3d6d5d16 100644 --- a/IntegrationTests/PromiseTest.js +++ b/IntegrationTests/PromiseTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule PromiseTest diff --git a/IntegrationTests/PropertiesUpdateTest.js b/IntegrationTests/PropertiesUpdateTest.js index a279c5aed0af08..623dc82c8ee94b 100644 --- a/IntegrationTests/PropertiesUpdateTest.js +++ b/IntegrationTests/PropertiesUpdateTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * @providesModule PropertiesUpdateTest */ 'use strict'; diff --git a/IntegrationTests/RCTRootViewIntegrationTestApp.js b/IntegrationTests/RCTRootViewIntegrationTestApp.js index 3793938d7e5adf..a97873d2c3224e 100644 --- a/IntegrationTests/RCTRootViewIntegrationTestApp.js +++ b/IntegrationTests/RCTRootViewIntegrationTestApp.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule RCTRootViewIntegrationTestApp */ diff --git a/IntegrationTests/ReactContentSizeUpdateTest.js b/IntegrationTests/ReactContentSizeUpdateTest.js index 07ae0ed661ce15..c5f5ae80c246b0 100644 --- a/IntegrationTests/ReactContentSizeUpdateTest.js +++ b/IntegrationTests/ReactContentSizeUpdateTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * @providesModule ReactContentSizeUpdateTest */ 'use strict'; @@ -30,7 +28,7 @@ var ReactContentSizeUpdateTest = createReactClass({ mixins: [Subscribable.Mixin, TimerMixin], - componentWillMount: function() { + UNSAFE_componentWillMount: function() { this.addListenerOn( RCTNativeAppEventEmitter, 'rootViewDidChangeIntrinsicSize', diff --git a/IntegrationTests/SimpleSnapshotTest.js b/IntegrationTests/SimpleSnapshotTest.js index 3998118dda8f6e..1c0be2a431d469 100644 --- a/IntegrationTests/SimpleSnapshotTest.js +++ b/IntegrationTests/SimpleSnapshotTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule SimpleSnapshotTest diff --git a/IntegrationTests/SizeFlexibilityUpdateTest.js b/IntegrationTests/SizeFlexibilityUpdateTest.js index 5d580f8fc6a028..679694a0d631ce 100644 --- a/IntegrationTests/SizeFlexibilityUpdateTest.js +++ b/IntegrationTests/SizeFlexibilityUpdateTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * @providesModule SizeFlexibilityUpdateTest */ 'use strict'; @@ -27,7 +25,7 @@ var SizeFlexibilityUpdateTest = createReactClass({ displayName: 'SizeFlexibilityUpdateTest', mixins: [Subscribable.Mixin], - componentWillMount: function() { + UNSAFE_componentWillMount: function() { this.addListenerOn( RCTNativeAppEventEmitter, 'rootViewDidChangeIntrinsicSize', diff --git a/IntegrationTests/SyncMethodTest.js b/IntegrationTests/SyncMethodTest.js index 76bb70a81f41d7..6318eaa4f14282 100644 --- a/IntegrationTests/SyncMethodTest.js +++ b/IntegrationTests/SyncMethodTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule SyncMethodTest diff --git a/IntegrationTests/TimersTest.js b/IntegrationTests/TimersTest.js index ddd052081cffd4..23da99dc6edbdc 100644 --- a/IntegrationTests/TimersTest.js +++ b/IntegrationTests/TimersTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule TimersTest diff --git a/IntegrationTests/WebSocketTest.js b/IntegrationTests/WebSocketTest.js index 78d00701b53683..6e459f913babc3 100644 --- a/IntegrationTests/WebSocketTest.js +++ b/IntegrationTests/WebSocketTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule WebSocketTest diff --git a/IntegrationTests/WebViewTest.js b/IntegrationTests/WebViewTest.js index c0381c639a8256..a41e244b58be3a 100644 --- a/IntegrationTests/WebViewTest.js +++ b/IntegrationTests/WebViewTest.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule WebViewTest */ diff --git a/IntegrationTests/launchWebSocketServer.command b/IntegrationTests/launchWebSocketServer.command index ebb305dc150326..a6531c5f8d78b2 100755 --- a/IntegrationTests/launchWebSocketServer.command +++ b/IntegrationTests/launchWebSocketServer.command @@ -1,11 +1,9 @@ #!/usr/bin/env bash # Copyright (c) 2015-present, Facebook, Inc. -# All rights reserved. # -# This source code is licensed under the BSD-style license found in the -# LICENSE file in the root directory of this source tree. An additional grant -# of patent rights can be found in the PATENTS file in the same directory. +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. # Set terminal title echo -en "\033]0;Web Socket Test Server\a" diff --git a/IntegrationTests/websocket_integration_test_server.js b/IntegrationTests/websocket_integration_test_server.js index b7887f1c5e3753..e338d85ae3b89d 100755 --- a/IntegrationTests/websocket_integration_test_server.js +++ b/IntegrationTests/websocket_integration_test_server.js @@ -2,11 +2,9 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule websocket_integration_test_server diff --git a/LICENSE b/LICENSE index 8085fec497caf6..9e051010d82dc6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,30 +1,21 @@ -BSD License +MIT License -For React Native software +Copyright (c) 2015-present, Facebook, Inc. -Copyright (c) 2015-present, Facebook, Inc. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name Facebook nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Libraries/.eslintrc b/Libraries/.eslintrc deleted file mode 100644 index ddcf4e27251d8f..00000000000000 --- a/Libraries/.eslintrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "rules": { - // This folder currently runs through babel and doesn't need to be - // compatible with node 4 - "comma-dangle": 0 - } -} diff --git a/Libraries/.npmignore b/Libraries/.npmignore new file mode 100644 index 00000000000000..c912533dd7d2dd --- /dev/null +++ b/Libraries/.npmignore @@ -0,0 +1 @@ +__tests__ diff --git a/Libraries/ART/ARTCGFloatArray.h b/Libraries/ART/ARTCGFloatArray.h index 9d748549973d30..72286a50527e84 100644 --- a/Libraries/ART/ARTCGFloatArray.h +++ b/Libraries/ART/ARTCGFloatArray.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ // A little helper to make sure we have the right memory allocation ready for use. diff --git a/Libraries/ART/ARTContainer.h b/Libraries/ART/ARTContainer.h index d83f7ae1a559f8..532145825bd74b 100644 --- a/Libraries/ART/ARTContainer.h +++ b/Libraries/ART/ARTContainer.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ART/ARTGroup.h b/Libraries/ART/ARTGroup.h index 4d94a9acded24b..d9dcb48c87b180 100644 --- a/Libraries/ART/ARTGroup.h +++ b/Libraries/ART/ARTGroup.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ART/ARTGroup.m b/Libraries/ART/ARTGroup.m index 672c3b6ebeb9f8..1bc70725c030e8 100644 --- a/Libraries/ART/ARTGroup.m +++ b/Libraries/ART/ARTGroup.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTGroup.h" diff --git a/Libraries/ART/ARTNode.h b/Libraries/ART/ARTNode.h index 0ade1f21b57a6c..8b66c205ef2440 100644 --- a/Libraries/ART/ARTNode.h +++ b/Libraries/ART/ARTNode.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ART/ARTNode.m b/Libraries/ART/ARTNode.m index 38b01a0c56c449..b27b014b9e7d0e 100644 --- a/Libraries/ART/ARTNode.m +++ b/Libraries/ART/ARTNode.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTNode.h" diff --git a/Libraries/ART/ARTRenderable.h b/Libraries/ART/ARTRenderable.h index 8eae9c25ae4a70..e5735a1fbd81ef 100644 --- a/Libraries/ART/ARTRenderable.h +++ b/Libraries/ART/ARTRenderable.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ART/ARTRenderable.m b/Libraries/ART/ARTRenderable.m index 7ba9a9a6073915..d7a3115586f3dd 100644 --- a/Libraries/ART/ARTRenderable.m +++ b/Libraries/ART/ARTRenderable.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTRenderable.h" diff --git a/Libraries/ART/ARTSerializablePath.js b/Libraries/ART/ARTSerializablePath.js index 4e8b3c2271a6c7..7f52bc6540eda2 100644 --- a/Libraries/ART/ARTSerializablePath.js +++ b/Libraries/ART/ARTSerializablePath.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule ARTSerializablePath */ diff --git a/Libraries/ART/ARTShape.h b/Libraries/ART/ARTShape.h index 7d13c268f6e802..ce685c564b06be 100644 --- a/Libraries/ART/ARTShape.h +++ b/Libraries/ART/ARTShape.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ART/ARTShape.m b/Libraries/ART/ARTShape.m index c07d68e62aa4a3..935c8894994a2b 100644 --- a/Libraries/ART/ARTShape.m +++ b/Libraries/ART/ARTShape.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTShape.h" diff --git a/Libraries/ART/ARTSurfaceView.h b/Libraries/ART/ARTSurfaceView.h index 8be8d95040c146..cb42928cedbe12 100644 --- a/Libraries/ART/ARTSurfaceView.h +++ b/Libraries/ART/ARTSurfaceView.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ART/ARTSurfaceView.m b/Libraries/ART/ARTSurfaceView.m index 16e2029083de59..c8f46069038603 100644 --- a/Libraries/ART/ARTSurfaceView.m +++ b/Libraries/ART/ARTSurfaceView.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTSurfaceView.h" diff --git a/Libraries/ART/ARTText.h b/Libraries/ART/ARTText.h index ee976e329a46e8..cdf8393a137629 100644 --- a/Libraries/ART/ARTText.h +++ b/Libraries/ART/ARTText.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ART/ARTText.m b/Libraries/ART/ARTText.m index dfffde26546656..0953c850dc293e 100644 --- a/Libraries/ART/ARTText.m +++ b/Libraries/ART/ARTText.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTText.h" diff --git a/Libraries/ART/ARTTextFrame.h b/Libraries/ART/ARTTextFrame.h index 1f6b557bfc77af..8ad06e0a01baed 100644 --- a/Libraries/ART/ARTTextFrame.h +++ b/Libraries/ART/ARTTextFrame.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ART/Brushes/ARTBrush.h b/Libraries/ART/Brushes/ARTBrush.h index 05020dd7bafa26..95709e65f19bc9 100644 --- a/Libraries/ART/Brushes/ARTBrush.h +++ b/Libraries/ART/Brushes/ARTBrush.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ART/Brushes/ARTBrush.m b/Libraries/ART/Brushes/ARTBrush.m index 1cc762b650f04a..4ade2c221143f7 100644 --- a/Libraries/ART/Brushes/ARTBrush.m +++ b/Libraries/ART/Brushes/ARTBrush.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTBrush.h" diff --git a/Libraries/ART/Brushes/ARTLinearGradient.h b/Libraries/ART/Brushes/ARTLinearGradient.h index d7ff2e5684458f..8e6abbc5fbbfde 100644 --- a/Libraries/ART/Brushes/ARTLinearGradient.h +++ b/Libraries/ART/Brushes/ARTLinearGradient.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTBrush.h" diff --git a/Libraries/ART/Brushes/ARTLinearGradient.m b/Libraries/ART/Brushes/ARTLinearGradient.m index f8412163b319c0..1415a6ffcbc80f 100644 --- a/Libraries/ART/Brushes/ARTLinearGradient.m +++ b/Libraries/ART/Brushes/ARTLinearGradient.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTLinearGradient.h" diff --git a/Libraries/ART/Brushes/ARTPattern.h b/Libraries/ART/Brushes/ARTPattern.h index 5f513ec60e2ae6..ce1767cc9b0bc8 100644 --- a/Libraries/ART/Brushes/ARTPattern.h +++ b/Libraries/ART/Brushes/ARTPattern.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTBrush.h" diff --git a/Libraries/ART/Brushes/ARTPattern.m b/Libraries/ART/Brushes/ARTPattern.m index 0d720613b80182..5c43586452d198 100644 --- a/Libraries/ART/Brushes/ARTPattern.m +++ b/Libraries/ART/Brushes/ARTPattern.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTPattern.h" diff --git a/Libraries/ART/Brushes/ARTRadialGradient.h b/Libraries/ART/Brushes/ARTRadialGradient.h index 7f86d93058ce80..d7895f8b74d084 100644 --- a/Libraries/ART/Brushes/ARTRadialGradient.h +++ b/Libraries/ART/Brushes/ARTRadialGradient.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTBrush.h" diff --git a/Libraries/ART/Brushes/ARTRadialGradient.m b/Libraries/ART/Brushes/ARTRadialGradient.m index 1dd449595316e7..19db9cb97b567a 100644 --- a/Libraries/ART/Brushes/ARTRadialGradient.m +++ b/Libraries/ART/Brushes/ARTRadialGradient.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTRadialGradient.h" diff --git a/Libraries/ART/Brushes/ARTSolidColor.h b/Libraries/ART/Brushes/ARTSolidColor.h index f212c735680f60..a16c2b915c72f8 100644 --- a/Libraries/ART/Brushes/ARTSolidColor.h +++ b/Libraries/ART/Brushes/ARTSolidColor.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTBrush.h" diff --git a/Libraries/ART/Brushes/ARTSolidColor.m b/Libraries/ART/Brushes/ARTSolidColor.m index 900621cfb4ea3c..096c4e043ed429 100644 --- a/Libraries/ART/Brushes/ARTSolidColor.m +++ b/Libraries/ART/Brushes/ARTSolidColor.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTSolidColor.h" diff --git a/Libraries/ART/RCTConvert+ART.h b/Libraries/ART/RCTConvert+ART.h index ef46e4e9341e3c..1deb3c600176ab 100644 --- a/Libraries/ART/RCTConvert+ART.h +++ b/Libraries/ART/RCTConvert+ART.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ART/RCTConvert+ART.m b/Libraries/ART/RCTConvert+ART.m index 6135dc4f4fd250..ea22d5426f18f9 100644 --- a/Libraries/ART/RCTConvert+ART.m +++ b/Libraries/ART/RCTConvert+ART.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "RCTConvert+ART.h" diff --git a/Libraries/ART/ReactNativeART.js b/Libraries/ART/ReactNativeART.js index 4a56d0275822ee..7d9f1b59063459 100644 --- a/Libraries/ART/ReactNativeART.js +++ b/Libraries/ART/ReactNativeART.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule ReactNativeART */ diff --git a/Libraries/ART/ViewManagers/ARTGroupManager.h b/Libraries/ART/ViewManagers/ARTGroupManager.h index 0a90eb3d6c18c9..a35e09481be639 100644 --- a/Libraries/ART/ViewManagers/ARTGroupManager.h +++ b/Libraries/ART/ViewManagers/ARTGroupManager.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTNodeManager.h" diff --git a/Libraries/ART/ViewManagers/ARTGroupManager.m b/Libraries/ART/ViewManagers/ARTGroupManager.m index 8b277641588803..2de0d0e5688739 100644 --- a/Libraries/ART/ViewManagers/ARTGroupManager.m +++ b/Libraries/ART/ViewManagers/ARTGroupManager.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTGroupManager.h" diff --git a/Libraries/ART/ViewManagers/ARTNodeManager.h b/Libraries/ART/ViewManagers/ARTNodeManager.h index 22f2ef166b24cf..3a8f99e7abdc7a 100644 --- a/Libraries/ART/ViewManagers/ARTNodeManager.h +++ b/Libraries/ART/ViewManagers/ARTNodeManager.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ART/ViewManagers/ARTNodeManager.m b/Libraries/ART/ViewManagers/ARTNodeManager.m index 3c697c129783aa..8e568ce6d8efd4 100644 --- a/Libraries/ART/ViewManagers/ARTNodeManager.m +++ b/Libraries/ART/ViewManagers/ARTNodeManager.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTNodeManager.h" diff --git a/Libraries/ART/ViewManagers/ARTRenderableManager.h b/Libraries/ART/ViewManagers/ARTRenderableManager.h index 376fcf518b3293..1e4b554f0f79f7 100644 --- a/Libraries/ART/ViewManagers/ARTRenderableManager.h +++ b/Libraries/ART/ViewManagers/ARTRenderableManager.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTNodeManager.h" diff --git a/Libraries/ART/ViewManagers/ARTRenderableManager.m b/Libraries/ART/ViewManagers/ARTRenderableManager.m index aaed2e31d11179..a30841b50c1046 100644 --- a/Libraries/ART/ViewManagers/ARTRenderableManager.m +++ b/Libraries/ART/ViewManagers/ARTRenderableManager.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTRenderableManager.h" diff --git a/Libraries/ART/ViewManagers/ARTShapeManager.h b/Libraries/ART/ViewManagers/ARTShapeManager.h index d6bc76baa09fdb..2f31b23a0eab10 100644 --- a/Libraries/ART/ViewManagers/ARTShapeManager.h +++ b/Libraries/ART/ViewManagers/ARTShapeManager.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTRenderableManager.h" diff --git a/Libraries/ART/ViewManagers/ARTShapeManager.m b/Libraries/ART/ViewManagers/ARTShapeManager.m index 3997586d18e4d1..57b603ca1a16b6 100644 --- a/Libraries/ART/ViewManagers/ARTShapeManager.m +++ b/Libraries/ART/ViewManagers/ARTShapeManager.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTShapeManager.h" diff --git a/Libraries/ART/ViewManagers/ARTSurfaceViewManager.h b/Libraries/ART/ViewManagers/ARTSurfaceViewManager.h index fc36435edb7707..5915536bd6f917 100644 --- a/Libraries/ART/ViewManagers/ARTSurfaceViewManager.h +++ b/Libraries/ART/ViewManagers/ARTSurfaceViewManager.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ART/ViewManagers/ARTSurfaceViewManager.m b/Libraries/ART/ViewManagers/ARTSurfaceViewManager.m index 10772b72c7f23d..54052a331d4585 100644 --- a/Libraries/ART/ViewManagers/ARTSurfaceViewManager.m +++ b/Libraries/ART/ViewManagers/ARTSurfaceViewManager.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTSurfaceViewManager.h" diff --git a/Libraries/ART/ViewManagers/ARTTextManager.h b/Libraries/ART/ViewManagers/ARTTextManager.h index 48da9c891f4757..c7d5304da3a3eb 100644 --- a/Libraries/ART/ViewManagers/ARTTextManager.h +++ b/Libraries/ART/ViewManagers/ARTTextManager.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTRenderableManager.h" diff --git a/Libraries/ART/ViewManagers/ARTTextManager.m b/Libraries/ART/ViewManagers/ARTTextManager.m index 430f26db537ab1..ac6688c3d925b9 100644 --- a/Libraries/ART/ViewManagers/ARTTextManager.m +++ b/Libraries/ART/ViewManagers/ARTTextManager.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "ARTTextManager.h" diff --git a/Libraries/ActionSheetIOS/ActionSheetIOS.js b/Libraries/ActionSheetIOS/ActionSheetIOS.js index 9797b47b36e51c..23db7680ab34e1 100644 --- a/Libraries/ActionSheetIOS/ActionSheetIOS.js +++ b/Libraries/ActionSheetIOS/ActionSheetIOS.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule ActionSheetIOS * @flow diff --git a/Libraries/ActionSheetIOS/RCTActionSheetManager.h b/Libraries/ActionSheetIOS/RCTActionSheetManager.h index 313939149fd1a6..b9a5b2df7329a1 100644 --- a/Libraries/ActionSheetIOS/RCTActionSheetManager.h +++ b/Libraries/ActionSheetIOS/RCTActionSheetManager.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import diff --git a/Libraries/ActionSheetIOS/RCTActionSheetManager.m b/Libraries/ActionSheetIOS/RCTActionSheetManager.m index 9f550f77af32a4..91f047323769c7 100644 --- a/Libraries/ActionSheetIOS/RCTActionSheetManager.m +++ b/Libraries/ActionSheetIOS/RCTActionSheetManager.m @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import "RCTActionSheetManager.h" diff --git a/Libraries/Alert/Alert.js b/Libraries/Alert/Alert.js index 3f2e2379eeb44a..bcb51714440444 100644 --- a/Libraries/Alert/Alert.js +++ b/Libraries/Alert/Alert.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule Alert * @flow @@ -30,14 +28,14 @@ type Options = { /** * Launches an alert dialog with the specified title and message. - * + * * See http://facebook.github.io/react-native/docs/alert.html */ class Alert { /** * Launches an alert dialog with the specified title and message. - * + * * See http://facebook.github.io/react-native/docs/alert.html#alert */ static alert( diff --git a/Libraries/Alert/AlertIOS.js b/Libraries/Alert/AlertIOS.js index b42b57c29ae481..b254406462399e 100644 --- a/Libraries/Alert/AlertIOS.js +++ b/Libraries/Alert/AlertIOS.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AlertIOS * @flow @@ -103,7 +101,7 @@ class AlertIOS { /** * Create and display a prompt to enter some text. - * + * * See http://facebook.github.io/react-native/docs/alertios.html#prompt */ static prompt( @@ -122,11 +120,10 @@ class AlertIOS { 'keyboardType) and the old syntax will be removed in a future version.'); var callback = type; - var defaultValue = message; RCTAlertManager.alertWithArgs({ title: title || '', type: 'plain-text', - defaultValue, + defaultValue: message, }, (id, value) => { callback(value); }); diff --git a/Libraries/Alert/RCTAlertManager.android.js b/Libraries/Alert/RCTAlertManager.android.js index f8ad604e16da60..f819b55e1b3d1f 100644 --- a/Libraries/Alert/RCTAlertManager.android.js +++ b/Libraries/Alert/RCTAlertManager.android.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule RCTAlertManager */ diff --git a/Libraries/Alert/RCTAlertManager.ios.js b/Libraries/Alert/RCTAlertManager.ios.js index 409ecf5caf0430..3aef740abed4d5 100644 --- a/Libraries/Alert/RCTAlertManager.ios.js +++ b/Libraries/Alert/RCTAlertManager.ios.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule RCTAlertManager * @flow diff --git a/Libraries/Animated/release/gulpfile.js b/Libraries/Animated/release/gulpfile.js index 3d2a52c4a40405..b454ea790c2731 100644 --- a/Libraries/Animated/release/gulpfile.js +++ b/Libraries/Animated/release/gulpfile.js @@ -1,10 +1,8 @@ /** - * Copyright 2013-2015, Facebook, Inc. - * All rights reserved. + * Copyright (c) 2013-present, Facebook, Inc. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * @providesModule gulpfile */ @@ -32,13 +30,10 @@ var PRODUCTION_HEADER = [ '/**', ' * Animated v<%= version %>', ' *', - ' * Copyright 2013-2015, Facebook, Inc.', - ' * All rights reserved.', - ' *', - ' * This source code is licensed under the BSD-style license found in the', - ' * LICENSE file in the root directory of this source tree. An additional grant', - ' * of patent rights can be found in the PATENTS file in the same directory.', + ' * Copyright (c) 2013-present, Facebook, Inc.', ' *', + ' * This source code is licensed under the MIT license found in the', + ' * LICENSE file in the root directory of this source tree.', ' */' ].join('\n') + '\n'; diff --git a/Libraries/Animated/release/package.json b/Libraries/Animated/release/package.json index 33654f7eae10e2..74f457a4dcd33c 100644 --- a/Libraries/Animated/release/package.json +++ b/Libraries/Animated/release/package.json @@ -7,7 +7,7 @@ "animated", "animation" ], - "license": "BSD-3-Clause", + "license": "MIT", "main": "Animated.js", "dependencies": { "fbjs": "^0.2.1" diff --git a/Libraries/Animated/src/Animated.js b/Libraries/Animated/src/Animated.js index 1eacd03c48c66e..32ec9ff8046954 100644 --- a/Libraries/Animated/src/Animated.js +++ b/Libraries/Animated/src/Animated.js @@ -1,37 +1,30 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule Animated * @flow + * @format */ -'use strict'; - -var AnimatedImplementation = require('AnimatedImplementation'); -var Image = require('Image'); -var Text = require('Text'); -var View = require('View'); +'use strict'; -let AnimatedScrollView; +const AnimatedImplementation = require('AnimatedImplementation'); +const Image = require('Image'); +const ScrollView = require('ScrollView'); +const Text = require('Text'); +const View = require('View'); const Animated = { View: AnimatedImplementation.createAnimatedComponent(View), Text: AnimatedImplementation.createAnimatedComponent(Text), Image: AnimatedImplementation.createAnimatedComponent(Image), - get ScrollView() { - // Make this lazy to avoid circular reference. - if (!AnimatedScrollView) { - AnimatedScrollView = AnimatedImplementation.createAnimatedComponent(require('ScrollView')); - } - return AnimatedScrollView; - }, + ScrollView: AnimatedImplementation.createAnimatedComponent(ScrollView), }; Object.assign((Animated: Object), AnimatedImplementation); -module.exports = ((Animated: any): (typeof AnimatedImplementation) & typeof Animated); +module.exports = ((Animated: any): typeof AnimatedImplementation & + typeof Animated); diff --git a/Libraries/Animated/src/AnimatedEvent.js b/Libraries/Animated/src/AnimatedEvent.js index 206516f5d96a95..f9300feb4e79ea 100644 --- a/Libraries/Animated/src/AnimatedEvent.js +++ b/Libraries/Animated/src/AnimatedEvent.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedEvent * @flow diff --git a/Libraries/Animated/src/AnimatedImplementation.js b/Libraries/Animated/src/AnimatedImplementation.js index 08d69c3bd80eca..b23a44db0e4fc7 100644 --- a/Libraries/Animated/src/AnimatedImplementation.js +++ b/Libraries/Animated/src/AnimatedImplementation.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedImplementation * @flow diff --git a/Libraries/Animated/src/AnimatedWeb.js b/Libraries/Animated/src/AnimatedWeb.js index b88acb940bd65b..f3af397b740931 100644 --- a/Libraries/Animated/src/AnimatedWeb.js +++ b/Libraries/Animated/src/AnimatedWeb.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow * @providesModule AnimatedWeb diff --git a/Libraries/Animated/src/Easing.js b/Libraries/Animated/src/Easing.js index 6cad73c334ccbe..f5c00fd813f7dc 100644 --- a/Libraries/Animated/src/Easing.js +++ b/Libraries/Animated/src/Easing.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule Easing * @flow diff --git a/Libraries/Animated/src/NativeAnimatedHelper.js b/Libraries/Animated/src/NativeAnimatedHelper.js index 6bebbe427cb50e..5765dcfc63b829 100644 --- a/Libraries/Animated/src/NativeAnimatedHelper.js +++ b/Libraries/Animated/src/NativeAnimatedHelper.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule NativeAnimatedHelper * @flow diff --git a/Libraries/Animated/src/SpringConfig.js b/Libraries/Animated/src/SpringConfig.js index e74d167efecedc..5b476f6723469e 100644 --- a/Libraries/Animated/src/SpringConfig.js +++ b/Libraries/Animated/src/SpringConfig.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule SpringConfig * @flow diff --git a/Libraries/Animated/src/__tests__/Animated-test.js b/Libraries/Animated/src/__tests__/Animated-test.js index 1ddbb38d559f06..d6409d7f8a9224 100644 --- a/Libraries/Animated/src/__tests__/Animated-test.js +++ b/Libraries/Animated/src/__tests__/Animated-test.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @emails oncall+react_native */ @@ -94,11 +92,11 @@ describe('Animated tests', () => { opacity: anim, }, }; - c.componentWillMount(); + c.UNSAFE_componentWillMount(); expect(anim.__detach).not.toBeCalled(); c._component = {}; - c.componentWillReceiveProps({ + c.UNSAFE_componentWillReceiveProps({ style: { opacity: anim, }, @@ -120,7 +118,7 @@ describe('Animated tests', () => { opacity: anim, }, }; - c.componentWillMount(); + c.UNSAFE_componentWillMount(); Animated.timing(anim, {toValue: 10, duration: 1000}).start(callback); c._component = {}; diff --git a/Libraries/Animated/src/__tests__/AnimatedNative-test.js b/Libraries/Animated/src/__tests__/AnimatedNative-test.js index 08388069d59ef4..1c6700e4dc0652 100644 --- a/Libraries/Animated/src/__tests__/AnimatedNative-test.js +++ b/Libraries/Animated/src/__tests__/AnimatedNative-test.js @@ -1,20 +1,22 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @emails oncall+react_native */ 'use strict'; +const ClassComponentMock = class {}; +ClassComponentMock.prototype.isReactComponent = true; + jest .clearAllMocks() - .setMock('Text', {}) - .setMock('View', {}) - .setMock('Image', {}) + .setMock('Text', ClassComponentMock) + .setMock('View', ClassComponentMock) + .setMock('Image', ClassComponentMock) + .setMock('ScrollView', ClassComponentMock) .setMock('React', {Component: class {}}) .setMock('NativeModules', { NativeAnimatedModule: {}, @@ -29,7 +31,7 @@ const NativeAnimatedHelper = require('NativeAnimatedHelper'); function createAndMountComponent(ComponentClass, props) { const component = new ComponentClass(); component.props = props; - component.componentWillMount(); + component.UNSAFE_componentWillMount(); // Simulate that refs were set. component._component = {}; component.componentDidMount(); diff --git a/Libraries/Animated/src/__tests__/Easing-test.js b/Libraries/Animated/src/__tests__/Easing-test.js index 048fdb711d3a49..14f18aacd628e0 100644 --- a/Libraries/Animated/src/__tests__/Easing-test.js +++ b/Libraries/Animated/src/__tests__/Easing-test.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @emails oncall+react_native */ diff --git a/Libraries/Animated/src/__tests__/Interpolation-test.js b/Libraries/Animated/src/__tests__/Interpolation-test.js index e95365423cb09b..27f4438ab1568d 100644 --- a/Libraries/Animated/src/__tests__/Interpolation-test.js +++ b/Libraries/Animated/src/__tests__/Interpolation-test.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @emails oncall+react_native */ diff --git a/Libraries/Animated/src/__tests__/bezier-test.js b/Libraries/Animated/src/__tests__/bezier-test.js index e34c4f799d7d8e..3f1070a48fd71e 100644 --- a/Libraries/Animated/src/__tests__/bezier-test.js +++ b/Libraries/Animated/src/__tests__/bezier-test.js @@ -121,7 +121,7 @@ describe('bezier', function() { assertClose(easing(0.5), 0.5, 2); }); }); - it('should be symetrical', function() { + it('should be symmetrical', function() { repeat(10)(function() { var a = Math.random(), b = 2 * Math.random() - 0.5, diff --git a/Libraries/Animated/src/animations/Animation.js b/Libraries/Animated/src/animations/Animation.js index 90ea28196ed014..000e44d77f9bc8 100644 --- a/Libraries/Animated/src/animations/Animation.js +++ b/Libraries/Animated/src/animations/Animation.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule Animation * @flow diff --git a/Libraries/Animated/src/animations/DecayAnimation.js b/Libraries/Animated/src/animations/DecayAnimation.js index 652bd9c9d3b708..7df0e104b72f48 100644 --- a/Libraries/Animated/src/animations/DecayAnimation.js +++ b/Libraries/Animated/src/animations/DecayAnimation.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule DecayAnimation * @flow diff --git a/Libraries/Animated/src/animations/SpringAnimation.js b/Libraries/Animated/src/animations/SpringAnimation.js index 67dee081b81b6a..8b6f96fe67bdb6 100644 --- a/Libraries/Animated/src/animations/SpringAnimation.js +++ b/Libraries/Animated/src/animations/SpringAnimation.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule SpringAnimation * @flow diff --git a/Libraries/Animated/src/animations/TimingAnimation.js b/Libraries/Animated/src/animations/TimingAnimation.js index a3db014fe1190c..1b6a4ae94cd9b0 100644 --- a/Libraries/Animated/src/animations/TimingAnimation.js +++ b/Libraries/Animated/src/animations/TimingAnimation.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule TimingAnimation * @flow diff --git a/Libraries/Animated/src/createAnimatedComponent.js b/Libraries/Animated/src/createAnimatedComponent.js index 7126deaf2ba109..357ee0bd59bcd1 100644 --- a/Libraries/Animated/src/createAnimatedComponent.js +++ b/Libraries/Animated/src/createAnimatedComponent.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule createAnimatedComponent * @flow @@ -17,7 +15,16 @@ const AnimatedProps = require('./nodes/AnimatedProps'); const React = require('React'); const ViewStylePropTypes = require('ViewStylePropTypes'); +const invariant = require('fbjs/lib/invariant'); + function createAnimatedComponent(Component: any): any { + invariant( + typeof Component === 'string' || + (Component.prototype && Component.prototype.isReactComponent), + '`createAnimatedComponent` does not support stateless functional components; ' + + 'use a class component instead.', + ); + class AnimatedComponent extends React.Component { _component: any; _invokeAnimatedPropsCallbackOnMount: boolean = false; @@ -42,7 +49,7 @@ function createAnimatedComponent(Component: any): any { this._component.setNativeProps(props); } - componentWillMount() { + UNSAFE_componentWillMount() { this._attachProps(this.props); } @@ -127,7 +134,7 @@ function createAnimatedComponent(Component: any): any { oldPropsAnimated && oldPropsAnimated.__detach(); } - componentWillReceiveProps(newProps) { + UNSAFE_componentWillReceiveProps(newProps) { this._attachProps(newProps); } @@ -149,7 +156,7 @@ function createAnimatedComponent(Component: any): any { ref={this._setComponentRef} // The native driver updates views directly through the UI thread so we // have to make sure the view doesn't get optimized away because it cannot - // go through the NativeViewHierachyManager since it operates on the shadow + // go through the NativeViewHierarchyManager since it operates on the shadow // thread. collapsable={ this._propsAnimated.__isNative ? false : props.collapsable diff --git a/Libraries/Animated/src/nodes/AnimatedAddition.js b/Libraries/Animated/src/nodes/AnimatedAddition.js index 53d338836ecf8b..2e3453965565f0 100644 --- a/Libraries/Animated/src/nodes/AnimatedAddition.js +++ b/Libraries/Animated/src/nodes/AnimatedAddition.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedAddition * @flow diff --git a/Libraries/Animated/src/nodes/AnimatedDiffClamp.js b/Libraries/Animated/src/nodes/AnimatedDiffClamp.js index eac26a10271b53..0f64e75c723c06 100644 --- a/Libraries/Animated/src/nodes/AnimatedDiffClamp.js +++ b/Libraries/Animated/src/nodes/AnimatedDiffClamp.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedDiffClamp * @flow diff --git a/Libraries/Animated/src/nodes/AnimatedDivision.js b/Libraries/Animated/src/nodes/AnimatedDivision.js index 8d658f458a5463..606e63937b9a86 100644 --- a/Libraries/Animated/src/nodes/AnimatedDivision.js +++ b/Libraries/Animated/src/nodes/AnimatedDivision.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedDivision * @flow diff --git a/Libraries/Animated/src/nodes/AnimatedInterpolation.js b/Libraries/Animated/src/nodes/AnimatedInterpolation.js index cfe9e701e4de22..eb4cc5d6995d77 100644 --- a/Libraries/Animated/src/nodes/AnimatedInterpolation.js +++ b/Libraries/Animated/src/nodes/AnimatedInterpolation.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedInterpolation * @flow @@ -374,7 +372,7 @@ class AnimatedInterpolation extends AnimatedWithChildren { return { inputRange: this._config.inputRange, - // Only the `outputRange` can contain strings so we don't need to tranform `inputRange` here + // Only the `outputRange` can contain strings so we don't need to transform `inputRange` here outputRange: this.__transformDataType(this._config.outputRange), extrapolateLeft: this._config.extrapolateLeft || this._config.extrapolate || 'extend', diff --git a/Libraries/Animated/src/nodes/AnimatedModulo.js b/Libraries/Animated/src/nodes/AnimatedModulo.js index 3ff75e737216da..24cd3f0b077c12 100644 --- a/Libraries/Animated/src/nodes/AnimatedModulo.js +++ b/Libraries/Animated/src/nodes/AnimatedModulo.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedModulo * @flow diff --git a/Libraries/Animated/src/nodes/AnimatedMultiplication.js b/Libraries/Animated/src/nodes/AnimatedMultiplication.js index d30ce2594a1675..dc01f7f17127f1 100644 --- a/Libraries/Animated/src/nodes/AnimatedMultiplication.js +++ b/Libraries/Animated/src/nodes/AnimatedMultiplication.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedMultiplication * @flow diff --git a/Libraries/Animated/src/nodes/AnimatedNode.js b/Libraries/Animated/src/nodes/AnimatedNode.js index c29f4b7f1a80b0..e75cfaf0e5c8fb 100644 --- a/Libraries/Animated/src/nodes/AnimatedNode.js +++ b/Libraries/Animated/src/nodes/AnimatedNode.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedNode * @flow diff --git a/Libraries/Animated/src/nodes/AnimatedProps.js b/Libraries/Animated/src/nodes/AnimatedProps.js index 0b9f6508d1526d..78cd11189edfa7 100644 --- a/Libraries/Animated/src/nodes/AnimatedProps.js +++ b/Libraries/Animated/src/nodes/AnimatedProps.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedProps * @flow diff --git a/Libraries/Animated/src/nodes/AnimatedStyle.js b/Libraries/Animated/src/nodes/AnimatedStyle.js index f2cdf31dfdea0a..c7bb24e3b42b14 100644 --- a/Libraries/Animated/src/nodes/AnimatedStyle.js +++ b/Libraries/Animated/src/nodes/AnimatedStyle.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedStyle * @flow diff --git a/Libraries/Animated/src/nodes/AnimatedTracking.js b/Libraries/Animated/src/nodes/AnimatedTracking.js index 1a54f78abb5a23..cf20d6e8bbf3fc 100644 --- a/Libraries/Animated/src/nodes/AnimatedTracking.js +++ b/Libraries/Animated/src/nodes/AnimatedTracking.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedTracking * @flow @@ -14,6 +12,10 @@ const AnimatedValue = require('./AnimatedValue'); const AnimatedNode = require('./AnimatedNode'); +const { + generateNewAnimationId, + shouldUseNativeDriver, +} = require('../NativeAnimatedHelper'); import type {EndCallback} from '../animations/Animation'; @@ -23,6 +25,7 @@ class AnimatedTracking extends AnimatedNode { _callback: ?EndCallback; _animationConfig: Object; _animationClass: any; + _useNativeDriver: boolean; constructor( value: AnimatedValue, @@ -36,16 +39,32 @@ class AnimatedTracking extends AnimatedNode { this._parent = parent; this._animationClass = animationClass; this._animationConfig = animationConfig; + this._useNativeDriver = shouldUseNativeDriver(animationConfig); this._callback = callback; this.__attach(); } + __makeNative() { + this.__isNative = true; + this._parent.__makeNative(); + super.__makeNative(); + this._value.__makeNative(); + } + __getValue(): Object { return this._parent.__getValue(); } __attach(): void { this._parent.__addChild(this); + if (this._useNativeDriver) { + // when the tracking starts we need to convert this node to a "native node" + // so that the parent node will be made "native" too. This is necessary as + // if we don't do this `update` method will get called. At that point it + // may be too late as it would mean the JS driver has already started + // updating node values + this.__makeNative(); + } } __detach(): void { @@ -62,6 +81,22 @@ class AnimatedTracking extends AnimatedNode { this._callback, ); } + + __getNativeConfig(): any { + const animation = new this._animationClass({ + ...this._animationConfig, + // remove toValue from the config as it's a ref to Animated.Value + toValue: undefined, + }); + const animationConfig = animation.__getNativeAnimationConfig(); + return { + type: 'tracking', + animationId: generateNewAnimationId(), + animationConfig, + toValue: this._parent.__getNativeTag(), + value: this._value.__getNativeTag(), + }; + } } module.exports = AnimatedTracking; diff --git a/Libraries/Animated/src/nodes/AnimatedTransform.js b/Libraries/Animated/src/nodes/AnimatedTransform.js index c95aa16f699d2b..48f82f9fe3443d 100644 --- a/Libraries/Animated/src/nodes/AnimatedTransform.js +++ b/Libraries/Animated/src/nodes/AnimatedTransform.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedTransform * @flow @@ -17,9 +15,9 @@ const AnimatedWithChildren = require('./AnimatedWithChildren'); const NativeAnimatedHelper = require('../NativeAnimatedHelper'); class AnimatedTransform extends AnimatedWithChildren { - _transforms: Array; + _transforms: $ReadOnlyArray; - constructor(transforms: Array) { + constructor(transforms: $ReadOnlyArray) { super(); this._transforms = transforms; } @@ -36,7 +34,7 @@ class AnimatedTransform extends AnimatedWithChildren { }); } - __getValue(): Array { + __getValue(): $ReadOnlyArray { return this._transforms.map(transform => { const result = {}; for (const key in transform) { @@ -51,7 +49,7 @@ class AnimatedTransform extends AnimatedWithChildren { }); } - __getAnimatedValue(): Array { + __getAnimatedValue(): $ReadOnlyArray { return this._transforms.map(transform => { const result = {}; for (const key in transform) { diff --git a/Libraries/Animated/src/nodes/AnimatedValue.js b/Libraries/Animated/src/nodes/AnimatedValue.js index 49f440471e1ba3..862d25f8e53a28 100644 --- a/Libraries/Animated/src/nodes/AnimatedValue.js +++ b/Libraries/Animated/src/nodes/AnimatedValue.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedValue * @flow @@ -20,6 +18,7 @@ const NativeAnimatedHelper = require('../NativeAnimatedHelper'); import type Animation, {EndCallback} from '../animations/Animation'; import type {InterpolationConfigType} from './AnimatedInterpolation'; +import type AnimatedTracking from './AnimatedTracking'; const NativeAnimatedAPI = NativeAnimatedHelper.API; @@ -76,7 +75,7 @@ class AnimatedValue extends AnimatedWithChildren { _startingValue: number; _offset: number; _animation: ?Animation; - _tracking: ?AnimatedNode; + _tracking: ?AnimatedTracking; _listeners: {[key: string]: ValueListenerCallback}; __nativeAnimatedValueListener: ?any; @@ -311,7 +310,7 @@ class AnimatedValue extends AnimatedWithChildren { /** * Typically only used internally. */ - track(tracking: AnimatedNode): void { + track(tracking: AnimatedTracking): void { this.stopTracking(); this._tracking = tracking; } diff --git a/Libraries/Animated/src/nodes/AnimatedValueXY.js b/Libraries/Animated/src/nodes/AnimatedValueXY.js index 496ccd7958fa1e..52c207c0f42ffe 100644 --- a/Libraries/Animated/src/nodes/AnimatedValueXY.js +++ b/Libraries/Animated/src/nodes/AnimatedValueXY.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedValueXY * @flow @@ -33,7 +31,7 @@ class AnimatedValueXY extends AnimatedWithChildren { _listeners: {[key: string]: {x: string, y: string}}; constructor( - valueIn?: ?{x: number | AnimatedValue, y: number | AnimatedValue}, + valueIn?: ?{+x: number | AnimatedValue, +y: number | AnimatedValue}, ) { super(); const value: any = valueIn || {x: 0, y: 0}; // @flowfixme: shouldn't need `: any` @@ -43,7 +41,7 @@ class AnimatedValueXY extends AnimatedWithChildren { } else { invariant( value.x instanceof AnimatedValue && value.y instanceof AnimatedValue, - 'AnimatedValueXY must be initalized with an object of numbers or ' + + 'AnimatedValueXY must be initialized with an object of numbers or ' + 'AnimatedValues.', ); this.x = value.x; diff --git a/Libraries/Animated/src/nodes/AnimatedWithChildren.js b/Libraries/Animated/src/nodes/AnimatedWithChildren.js index 4676437a9eae47..1f58cd834e165e 100644 --- a/Libraries/Animated/src/nodes/AnimatedWithChildren.js +++ b/Libraries/Animated/src/nodes/AnimatedWithChildren.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AnimatedWithChildren * @flow diff --git a/Libraries/Animated/src/polyfills/InteractionManager.js b/Libraries/Animated/src/polyfills/InteractionManager.js index db45ede6426fd0..c063e9234b3df1 100644 --- a/Libraries/Animated/src/polyfills/InteractionManager.js +++ b/Libraries/Animated/src/polyfills/InteractionManager.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ 'use strict'; diff --git a/Libraries/Animated/src/polyfills/Set.js b/Libraries/Animated/src/polyfills/Set.js index 988f0b3f13ff21..fd071410d42395 100644 --- a/Libraries/Animated/src/polyfills/Set.js +++ b/Libraries/Animated/src/polyfills/Set.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ 'use strict'; diff --git a/Libraries/Animated/src/polyfills/flattenStyle.js b/Libraries/Animated/src/polyfills/flattenStyle.js index 42a68020c6539c..2e4c8a1d36b476 100644 --- a/Libraries/Animated/src/polyfills/flattenStyle.js +++ b/Libraries/Animated/src/polyfills/flattenStyle.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ 'use strict'; module.exports = function(style) { diff --git a/Libraries/AppState/AppState.js b/Libraries/AppState/AppState.js index ebdb6d54913bb4..f2faa9480d2b57 100644 --- a/Libraries/AppState/AppState.js +++ b/Libraries/AppState/AppState.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule AppState * @flow @@ -47,8 +45,8 @@ class AppState extends NativeEventEmitter { let eventUpdated = false; // TODO: this is a terrible solution - in order to ensure `currentState` - // prop is up to date, we have to register an observer that updates it - // whenever the state changes, even if nobody cares. We should just + // prop is up to date, we have to register an observer that updates it + // whenever the state changes, even if nobody cares. We should just // deprecate the `currentState` property and get rid of this. this.addListener( 'appStateDidChange', @@ -72,14 +70,14 @@ class AppState extends NativeEventEmitter { } // TODO: now that AppState is a subclass of NativeEventEmitter, we could - // deprecate `addEventListener` and `removeEventListener` and just use - // addListener` and `listener.remove()` directly. That will be a breaking + // deprecate `addEventListener` and `removeEventListener` and just use + // addListener` and `listener.remove()` directly. That will be a breaking // change though, as both the method and event names are different // (addListener events are currently required to be globally unique). /** * Add a handler to AppState changes by listening to the `change` event type * and providing the handler. - * + * * See http://facebook.github.io/react-native/docs/appstate.html#addeventlistener */ addEventListener( @@ -107,7 +105,7 @@ class AppState extends NativeEventEmitter { /** * Remove a handler by passing the `change` event type and the handler. - * + * * See http://facebook.github.io/react-native/docs/appstate.html#removeeventlistener */ removeEventListener( diff --git a/Libraries/BatchedBridge/BatchedBridge.js b/Libraries/BatchedBridge/BatchedBridge.js index f3e735f48749a0..bfc6862cb83551 100644 --- a/Libraries/BatchedBridge/BatchedBridge.js +++ b/Libraries/BatchedBridge/BatchedBridge.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule BatchedBridge * @flow @@ -18,7 +16,7 @@ const MessageQueue = require('MessageQueue'); // This makes stacktraces to be placed at MessageQueue rather than at where they were launched // The parameter __fbUninstallRNGlobalErrorHandler is passed to MessageQueue to prevent the handler from being installed // -// __fbUninstallRNGlobalErrorHandler is conditionally set by the Inspector while the VM is paused for intialization +// __fbUninstallRNGlobalErrorHandler is conditionally set by the Inspector while the VM is paused for initialization // If the Inspector isn't present it defaults to undefined and the global error handler is installed // The Inspector can still call MessageQueue#uninstallGlobalErrorHandler to uninstalled on attach diff --git a/Libraries/BatchedBridge/MessageQueue.js b/Libraries/BatchedBridge/MessageQueue.js index 4309de35519cf6..428d388173989e 100644 --- a/Libraries/BatchedBridge/MessageQueue.js +++ b/Libraries/BatchedBridge/MessageQueue.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule MessageQueue * @flow diff --git a/Libraries/BatchedBridge/NativeModules.js b/Libraries/BatchedBridge/NativeModules.js index 2bf0f26c875119..324c4f6e995bdd 100644 --- a/Libraries/BatchedBridge/NativeModules.js +++ b/Libraries/BatchedBridge/NativeModules.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule NativeModules * @flow diff --git a/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js b/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js index 09ec56663b5c46..40ad81f5f5cb5f 100644 --- a/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js +++ b/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * These don't actually exist anywhere in the code. */ diff --git a/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js b/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js index 380bacf65e2c66..8c4f7d3c03063f 100644 --- a/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js +++ b/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * */ 'use strict'; diff --git a/Libraries/BatchedBridge/__tests__/MessageQueue-test.js b/Libraries/BatchedBridge/__tests__/MessageQueue-test.js index 106821dd2fcffe..ecf60bcd0455cc 100644 --- a/Libraries/BatchedBridge/__tests__/MessageQueue-test.js +++ b/Libraries/BatchedBridge/__tests__/MessageQueue-test.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @emails oncall+react_native * @format diff --git a/Libraries/BatchedBridge/__tests__/NativeModules-test.js b/Libraries/BatchedBridge/__tests__/NativeModules-test.js index 88435513e72966..b9cc2411d29512 100644 --- a/Libraries/BatchedBridge/__tests__/NativeModules-test.js +++ b/Libraries/BatchedBridge/__tests__/NativeModules-test.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @emails oncall+react_native */ diff --git a/Libraries/Blob/Blob.js b/Libraries/Blob/Blob.js index 590f48fc50dcc3..eca13a6a309e8f 100644 --- a/Libraries/Blob/Blob.js +++ b/Libraries/Blob/Blob.js @@ -1,26 +1,17 @@ /** * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule Blob * @flow + * @format */ 'use strict'; -const invariant = require('fbjs/lib/invariant'); -/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error - * found when Flow v0.54 was deployed. To see the error delete this comment and - * run Flow. */ -const uuid = require('uuid'); - -const { BlobModule } = require('NativeModules'); - -import type { BlobProps } from 'BlobTypes'; +import type {BlobData, BlobOptions} from 'BlobTypes'; /** * Opaque JS representation of some binary data in native. @@ -60,51 +51,16 @@ import type { BlobProps } from 'BlobTypes'; * Reference: https://developer.mozilla.org/en-US/docs/Web/API/Blob */ class Blob { - /** - * Size of the data contained in the Blob object, in bytes. - */ - size: number; - /* - * String indicating the MIME type of the data contained in the Blob. - * If the type is unknown, this string is empty. - */ - type: string; - - /* - * Unique id to identify the blob on native side (non-standard) - */ - blobId: string; - /* - * Offset to indicate part of blob, used when sliced (non-standard) - */ - offset: number; - - /** - * Construct blob instance from blob data from native. - * Used internally by modules like XHR, WebSocket, etc. - */ - static create(props: BlobProps): Blob { - return Object.assign(Object.create(Blob.prototype), props); - } + _data: ?BlobData; /** * Constructor for JS consumers. * Currently we only support creating Blobs from other Blobs. * Reference: https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob */ - constructor(parts: Array, options: any) { - const blobId = uuid(); - let size = 0; - parts.forEach((part) => { - invariant(part instanceof Blob, 'Can currently only create a Blob from other Blobs'); - size += part.size; - }); - BlobModule.createFromParts(parts, blobId); - return Blob.create({ - blobId, - offset: 0, - size, - }); + constructor(parts: Array = [], options?: BlobOptions) { + const BlobManager = require('BlobManager'); + this.data = BlobManager.createFromParts(parts, options).data; } /* @@ -112,9 +68,22 @@ class Blob { * the data in the specified range of bytes of the source Blob. * Reference: https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice */ + set data(data: ?BlobData) { + this._data = data; + } + + get data(): BlobData { + if (!this._data) { + throw new Error('Blob has been closed and is no longer available'); + } + + return this._data; + } + slice(start?: number, end?: number): Blob { - let offset = this.offset; - let size = this.size; + const BlobManager = require('BlobManager'); + let {offset, size} = this.data; + if (typeof start === 'number') { if (start > size) { start = size; @@ -129,8 +98,8 @@ class Blob { size = end - start; } } - return Blob.create({ - blobId: this.blobId, + return BlobManager.createFromOptions({ + blobId: this.data.blobId, offset, size, }); @@ -149,7 +118,24 @@ class Blob { * `new Blob([blob, ...])` actually copies the data in memory. */ close() { - BlobModule.release(this.blobId); + const BlobManager = require('BlobManager'); + BlobManager.release(this.data.blobId); + this.data = null; + } + + /** + * Size of the data contained in the Blob object, in bytes. + */ + get size(): number { + return this.data.size; + } + + /* + * String indicating the MIME type of the data contained in the Blob. + * If the type is unknown, this string is empty. + */ + get type(): string { + return this.data.type || ''; } } diff --git a/Libraries/Blob/BlobManager.js b/Libraries/Blob/BlobManager.js new file mode 100644 index 00000000000000..dd7cc00eabc652 --- /dev/null +++ b/Libraries/Blob/BlobManager.js @@ -0,0 +1,144 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @providesModule BlobManager + * @flow + * @format + */ + +'use strict'; + +const Blob = require('Blob'); +const BlobRegistry = require('BlobRegistry'); +const {BlobModule} = require('NativeModules'); + +import type {BlobData, BlobOptions} from 'BlobTypes'; + +/*eslint-disable no-bitwise */ +/*eslint-disable eqeqeq */ + +/** + * Based on the rfc4122-compliant solution posted at + * http://stackoverflow.com/questions/105034 + */ +function uuidv4(): string { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { + const r = (Math.random() * 16) | 0, + v = c == 'x' ? r : (r & 0x3) | 0x8; + return v.toString(16); + }); +} + +/** + * Module to manage blobs. Wrapper around the native blob module. + */ +class BlobManager { + /** + * If the native blob module is available. + */ + static isAvailable = !!BlobModule; + + /** + * Create blob from existing array of blobs. + */ + static createFromParts( + parts: Array, + options?: BlobOptions, + ): Blob { + const blobId = uuidv4(); + const items = parts.map(part => { + if ( + part instanceof ArrayBuffer || + (global.ArrayBufferView && part instanceof global.ArrayBufferView) + ) { + throw new Error( + "Creating blobs from 'ArrayBuffer' and 'ArrayBufferView' are not supported", + ); + } + if (part instanceof Blob) { + return { + data: part.data, + type: 'blob', + }; + } else { + return { + data: String(part), + type: 'string', + }; + } + }); + const size = items.reduce((acc, curr) => { + if (curr.type === 'string') { + return acc + global.unescape(encodeURI(curr.data)).length; + } else { + return acc + curr.data.size; + } + }, 0); + + BlobModule.createFromParts(items, blobId); + + return BlobManager.createFromOptions({ + blobId, + offset: 0, + size, + type: options ? options.type : '', + lastModified: options ? options.lastModified : Date.now(), + }); + } + + /** + * Create blob instance from blob data from native. + * Used internally by modules like XHR, WebSocket, etc. + */ + static createFromOptions(options: BlobData): Blob { + BlobRegistry.register(options.blobId); + return Object.assign(Object.create(Blob.prototype), {data: options}); + } + + /** + * Deallocate resources for a blob. + */ + static release(blobId: string): void { + BlobRegistry.unregister(blobId); + if (BlobRegistry.has(blobId)) { + return; + } + BlobModule.release(blobId); + } + + /** + * Inject the blob content handler in the networking module to support blob + * requests and responses. + */ + static addNetworkingHandler(): void { + BlobModule.addNetworkingHandler(); + } + + /** + * Indicate the websocket should return a blob for incoming binary + * messages. + */ + static addWebSocketHandler(socketId: number): void { + BlobModule.addWebSocketHandler(socketId); + } + + /** + * Indicate the websocket should no longer return a blob for incoming + * binary messages. + */ + static removeWebSocketHandler(socketId: number): void { + BlobModule.removeWebSocketHandler(socketId); + } + + /** + * Send a blob message to a websocket. + */ + static sendOverSocket(blob: Blob, socketId: number): void { + BlobModule.sendOverSocket(blob.data, socketId); + } +} + +module.exports = BlobManager; diff --git a/Libraries/Blob/BlobRegistry.js b/Libraries/Blob/BlobRegistry.js new file mode 100644 index 00000000000000..330c1659ae4235 --- /dev/null +++ b/Libraries/Blob/BlobRegistry.js @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @providesModule BlobRegistry + * @flow + * @format + */ + +const registry: {[key: string]: number} = {}; + +const register = (id: string) => { + if (registry[id]) { + registry[id]++; + } else { + registry[id] = 1; + } +}; + +const unregister = (id: string) => { + if (registry[id]) { + registry[id]--; + if (registry[id] <= 0) { + delete registry[id]; + } + } +}; + +const has = (id: string) => { + return registry[id] && registry[id] > 0; +}; + +module.exports = { + register, + unregister, + has, +}; diff --git a/Libraries/Blob/BlobTypes.js b/Libraries/Blob/BlobTypes.js index 8201df47bc306f..8e895d9006108f 100644 --- a/Libraries/Blob/BlobTypes.js +++ b/Libraries/Blob/BlobTypes.js @@ -1,25 +1,26 @@ /** * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule BlobTypes * @flow + * @format */ 'use strict'; -export type BlobProps = { +export type BlobData = { blobId: string, offset: number, size: number, + name?: string, type?: string, + lastModified?: number, }; -export type FileProps = BlobProps & { - name: string, +export type BlobOptions = { + type: string, lastModified: number, }; diff --git a/Libraries/Blob/File.js b/Libraries/Blob/File.js new file mode 100644 index 00000000000000..f5b03d85f7f178 --- /dev/null +++ b/Libraries/Blob/File.js @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @providesModule File + * @flow + * @format + */ +'use strict'; + +const Blob = require('Blob'); + +const invariant = require('fbjs/lib/invariant'); + +import type {BlobOptions} from 'BlobTypes'; + +/** + * The File interface provides information about files. + */ +class File extends Blob { + /** + * Constructor for JS consumers. + */ + constructor( + parts: Array, + name: string, + options?: BlobOptions, + ) { + invariant( + parts != null && name != null, + 'Failed to construct `File`: Must pass both `parts` and `name` arguments.', + ); + + super(parts, options); + this.data.name = name; + } + + /** + * Name of the file. + */ + get name(): string { + invariant(this.data.name != null, 'Files must have a name set.'); + return this.data.name; + } + + /* + * Last modified time of the file. + */ + get lastModified(): number { + return this.data.lastModified || 0; + } +} + +module.exports = File; diff --git a/Libraries/Blob/FileReader.js b/Libraries/Blob/FileReader.js new file mode 100644 index 00000000000000..b3ed89dc9318e6 --- /dev/null +++ b/Libraries/Blob/FileReader.js @@ -0,0 +1,154 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @providesModule FileReader + * @flow + * @format + */ + +'use strict'; + +const EventTarget = require('event-target-shim'); +const Blob = require('Blob'); +const {FileReaderModule} = require('NativeModules'); + +type ReadyState = + | 0 // EMPTY + | 1 // LOADING + | 2; // DONE + +type ReaderResult = string | ArrayBuffer; + +const READER_EVENTS = [ + 'abort', + 'error', + 'load', + 'loadstart', + 'loadend', + 'progress', +]; + +const EMPTY = 0; +const LOADING = 1; +const DONE = 2; + +class FileReader extends EventTarget(...READER_EVENTS) { + static EMPTY = EMPTY; + static LOADING = LOADING; + static DONE = DONE; + + EMPTY = EMPTY; + LOADING = LOADING; + DONE = DONE; + + _readyState: ReadyState; + _error: ?Error; + _result: ?ReaderResult; + _aborted: boolean = false; + _subscriptions: Array<*> = []; + + constructor() { + super(); + this._reset(); + } + + _reset(): void { + this._readyState = EMPTY; + this._error = null; + this._result = null; + } + + _clearSubscriptions(): void { + this._subscriptions.forEach(sub => sub.remove()); + this._subscriptions = []; + } + + _setReadyState(newState: ReadyState) { + this._readyState = newState; + this.dispatchEvent({type: 'readystatechange'}); + if (newState === DONE) { + if (this._aborted) { + this.dispatchEvent({type: 'abort'}); + } else if (this._error) { + this.dispatchEvent({type: 'error'}); + } else { + this.dispatchEvent({type: 'load'}); + } + this.dispatchEvent({type: 'loadend'}); + } + } + + readAsArrayBuffer() { + throw new Error('FileReader.readAsArrayBuffer is not implemented'); + } + + readAsDataURL(blob: Blob) { + this._aborted = false; + + FileReaderModule.readAsDataURL(blob.data).then( + (text: string) => { + if (this._aborted) { + return; + } + this._result = text; + this._setReadyState(DONE); + }, + error => { + if (this._aborted) { + return; + } + this._error = error; + this._setReadyState(DONE); + }, + ); + } + + readAsText(blob: Blob, encoding: string = 'UTF-8') { + this._aborted = false; + + FileReaderModule.readAsText(blob.data, encoding).then( + (text: string) => { + if (this._aborted) { + return; + } + this._result = text; + this._setReadyState(DONE); + }, + error => { + if (this._aborted) { + return; + } + this._error = error; + this._setReadyState(DONE); + }, + ); + } + + abort() { + this._aborted = true; + // only call onreadystatechange if there is something to abort, as per spec + if (this._readyState !== EMPTY && this._readyState !== DONE) { + this._reset(); + this._setReadyState(DONE); + } + // Reset again after, in case modified in handler + this._reset(); + } + + get readyState(): ReadyState { + return this._readyState; + } + + get error(): ?Error { + return this._error; + } + + get result(): ?ReaderResult { + return this._result; + } +} + +module.exports = FileReader; diff --git a/Libraries/Blob/RCTBlob.xcodeproj/project.pbxproj b/Libraries/Blob/RCTBlob.xcodeproj/project.pbxproj index bb5944caae6ad0..2ffded6f074d39 100755 --- a/Libraries/Blob/RCTBlob.xcodeproj/project.pbxproj +++ b/Libraries/Blob/RCTBlob.xcodeproj/project.pbxproj @@ -7,12 +7,18 @@ objects = { /* Begin PBXBuildFile section */ + 19BA88FE1F84391700741C5A /* RCTFileReaderModule.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = ADDFBA6A1F33455F0064C998 /* RCTFileReaderModule.h */; }; + 19BA88FF1F84392900741C5A /* RCTFileReaderModule.h in Headers */ = {isa = PBXBuildFile; fileRef = ADDFBA6A1F33455F0064C998 /* RCTFileReaderModule.h */; }; + 19BA89001F84392F00741C5A /* RCTFileReaderModule.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = ADDFBA6A1F33455F0064C998 /* RCTFileReaderModule.h */; }; + 19BA89011F84393D00741C5A /* RCTFileReaderModule.m in Sources */ = {isa = PBXBuildFile; fileRef = ADDFBA6B1F33455F0064C998 /* RCTFileReaderModule.m */; }; AD0871131E215B28007D136D /* RCTBlobManager.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = AD9A43C11DFC7126008DC588 /* RCTBlobManager.h */; }; AD0871161E215EC9007D136D /* RCTBlobManager.h in Headers */ = {isa = PBXBuildFile; fileRef = AD9A43C11DFC7126008DC588 /* RCTBlobManager.h */; }; AD0871181E215ED1007D136D /* RCTBlobManager.h in Headers */ = {isa = PBXBuildFile; fileRef = AD9A43C11DFC7126008DC588 /* RCTBlobManager.h */; }; AD08711A1E2162C8007D136D /* RCTBlobManager.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = AD9A43C11DFC7126008DC588 /* RCTBlobManager.h */; }; - AD9A43C31DFC7126008DC588 /* RCTBlobManager.m in Sources */ = {isa = PBXBuildFile; fileRef = AD9A43C21DFC7126008DC588 /* RCTBlobManager.m */; }; - ADD01A711E09404A00F6D226 /* RCTBlobManager.m in Sources */ = {isa = PBXBuildFile; fileRef = AD9A43C21DFC7126008DC588 /* RCTBlobManager.m */; }; + AD9A43C31DFC7126008DC588 /* RCTBlobManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = AD9A43C21DFC7126008DC588 /* RCTBlobManager.mm */; }; + ADD01A711E09404A00F6D226 /* RCTBlobManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = AD9A43C21DFC7126008DC588 /* RCTBlobManager.mm */; }; + ADDFBA6C1F33455F0064C998 /* RCTFileReaderModule.h in Headers */ = {isa = PBXBuildFile; fileRef = ADDFBA6A1F33455F0064C998 /* RCTFileReaderModule.h */; }; + ADDFBA6D1F33455F0064C998 /* RCTFileReaderModule.m in Sources */ = {isa = PBXBuildFile; fileRef = ADDFBA6B1F33455F0064C998 /* RCTFileReaderModule.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -22,6 +28,7 @@ dstPath = include/RCTBlob; dstSubfolderSpec = 16; files = ( + 19BA88FE1F84391700741C5A /* RCTFileReaderModule.h in Copy Headers */, AD08711A1E2162C8007D136D /* RCTBlobManager.h in Copy Headers */, ); name = "Copy Headers"; @@ -33,6 +40,7 @@ dstPath = include/RCTBlob; dstSubfolderSpec = 16; files = ( + 19BA89001F84392F00741C5A /* RCTFileReaderModule.h in Copy Headers */, AD0871131E215B28007D136D /* RCTBlobManager.h in Copy Headers */, ); name = "Copy Headers"; @@ -42,17 +50,21 @@ /* Begin PBXFileReference section */ 358F4ED71D1E81A9004DF814 /* libRCTBlob.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTBlob.a; sourceTree = BUILT_PRODUCTS_DIR; }; - AD9A43C11DFC7126008DC588 /* RCTBlobManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTBlobManager.h; sourceTree = ""; }; - AD9A43C21DFC7126008DC588 /* RCTBlobManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTBlobManager.m; sourceTree = ""; }; + AD9A43C11DFC7126008DC588 /* RCTBlobManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RCTBlobManager.h; sourceTree = ""; }; + AD9A43C21DFC7126008DC588 /* RCTBlobManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTBlobManager.mm; sourceTree = ""; }; ADD01A681E09402E00F6D226 /* libRCTBlob-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libRCTBlob-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + ADDFBA6A1F33455F0064C998 /* RCTFileReaderModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RCTFileReaderModule.h; sourceTree = ""; }; + ADDFBA6B1F33455F0064C998 /* RCTFileReaderModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTFileReaderModule.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXGroup section */ 358F4ECE1D1E81A9004DF814 = { isa = PBXGroup; children = ( + ADDFBA6A1F33455F0064C998 /* RCTFileReaderModule.h */, + ADDFBA6B1F33455F0064C998 /* RCTFileReaderModule.m */, AD9A43C11DFC7126008DC588 /* RCTBlobManager.h */, - AD9A43C21DFC7126008DC588 /* RCTBlobManager.m */, + AD9A43C21DFC7126008DC588 /* RCTBlobManager.mm */, 358F4ED81D1E81A9004DF814 /* Products */, ); indentWidth = 2; @@ -77,6 +89,7 @@ buildActionMask = 2147483647; files = ( AD0871161E215EC9007D136D /* RCTBlobManager.h in Headers */, + ADDFBA6C1F33455F0064C998 /* RCTFileReaderModule.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -84,6 +97,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 19BA88FF1F84392900741C5A /* RCTFileReaderModule.h in Headers */, AD0871181E215ED1007D136D /* RCTBlobManager.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -132,7 +146,7 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 0730; - ORGANIZATIONNAME = "Silk Labs"; + ORGANIZATIONNAME = Facebook; TargetAttributes = { 358F4ED61D1E81A9004DF814 = { CreatedOnToolsVersion = 7.3; @@ -166,7 +180,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - AD9A43C31DFC7126008DC588 /* RCTBlobManager.m in Sources */, + ADDFBA6D1F33455F0064C998 /* RCTFileReaderModule.m in Sources */, + AD9A43C31DFC7126008DC588 /* RCTBlobManager.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -174,7 +189,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - ADD01A711E09404A00F6D226 /* RCTBlobManager.m in Sources */, + 19BA89011F84393D00741C5A /* RCTFileReaderModule.m in Sources */, + ADD01A711E09404A00F6D226 /* RCTBlobManager.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Libraries/Blob/RCTBlobManager.h b/Libraries/Blob/RCTBlobManager.h index 03b3ffc60a6fb4..24b589ef987ae5 100755 --- a/Libraries/Blob/RCTBlobManager.h +++ b/Libraries/Blob/RCTBlobManager.h @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ #import @@ -13,4 +11,18 @@ @interface RCTBlobManager : NSObject +- (NSString *)store:(NSData *)data; + +- (void)store:(NSData *)data withId:(NSString *)blobId; + +- (NSData *)resolve:(NSDictionary *)blob; + +- (NSData *)resolve:(NSString *)blobId offset:(NSInteger)offset size:(NSInteger)size; + +- (NSData *)resolveURL:(NSURL *)url; + +- (void)remove:(NSString *)blobId; + +- (void)createFromParts:(NSArray *> *)parts withId:(NSString *)blobId; + @end diff --git a/Libraries/Blob/RCTBlobManager.m b/Libraries/Blob/RCTBlobManager.m deleted file mode 100755 index d556d634a1c7ff..00000000000000 --- a/Libraries/Blob/RCTBlobManager.m +++ /dev/null @@ -1,218 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import "RCTBlobManager.h" - -#import -#import - -static NSString *const kBlobUriScheme = @"blob"; - -@interface _RCTBlobContentHandler : NSObject - -- (instancetype)initWithBlobManager:(RCTBlobManager *)blobManager; - -@end - - -@implementation RCTBlobManager -{ - NSMutableDictionary *_blobs; - _RCTBlobContentHandler *_contentHandler; - NSOperationQueue *_queue; -} - -RCT_EXPORT_MODULE(BlobModule) - -@synthesize bridge = _bridge; - -+ (BOOL)requiresMainQueueSetup -{ - return NO; -} - -- (NSDictionary *)constantsToExport -{ - return @{ - @"BLOB_URI_SCHEME": kBlobUriScheme, - @"BLOB_URI_HOST": [NSNull null], - }; -} - -- (dispatch_queue_t)methodQueue -{ - return [[_bridge webSocketModule] methodQueue]; -} - -- (NSString *)store:(NSData *)data -{ - NSString *blobId = [NSUUID UUID].UUIDString; - [self store:data withId:blobId]; - return blobId; -} - -- (void)store:(NSData *)data withId:(NSString *)blobId -{ - if (!_blobs) { - _blobs = [NSMutableDictionary new]; - } - - _blobs[blobId] = data; -} - -- (NSData *)resolve:(NSDictionary *)blob -{ - NSString *blobId = [RCTConvert NSString:blob[@"blobId"]]; - NSNumber *offset = [RCTConvert NSNumber:blob[@"offset"]]; - NSNumber *size = [RCTConvert NSNumber:blob[@"size"]]; - - return [self resolve:blobId - offset:offset ? [offset integerValue] : 0 - size:size ? [size integerValue] : -1]; -} - -- (NSData *)resolve:(NSString *)blobId offset:(NSInteger)offset size:(NSInteger)size -{ - NSData *data = _blobs[blobId]; - if (!data) { - return nil; - } - if (offset != 0 || (size != -1 && size != data.length)) { - data = [data subdataWithRange:NSMakeRange(offset, size)]; - } - return data; -} - -RCT_EXPORT_METHOD(enableBlobSupport:(nonnull NSNumber *)socketID) -{ - if (!_contentHandler) { - _contentHandler = [[_RCTBlobContentHandler alloc] initWithBlobManager:self]; - } - [[_bridge webSocketModule] setContentHandler:_contentHandler forSocketID:socketID]; -} - -RCT_EXPORT_METHOD(disableBlobSupport:(nonnull NSNumber *)socketID) -{ - [[_bridge webSocketModule] setContentHandler:nil forSocketID:socketID]; -} - -RCT_EXPORT_METHOD(sendBlob:(NSDictionary *)blob socketID:(nonnull NSNumber *)socketID) -{ - [[_bridge webSocketModule] sendData:[self resolve:blob] forSocketID:socketID]; -} - -RCT_EXPORT_METHOD(createFromParts:(NSArray *> *)parts withId:(NSString *)blobId) -{ - NSMutableData *data = [NSMutableData new]; - for (NSDictionary *part in parts) { - NSData *partData = [self resolve:part]; - [data appendData:partData]; - } - [self store:data withId:blobId]; -} - -RCT_EXPORT_METHOD(release:(NSString *)blobId) -{ - [_blobs removeObjectForKey:blobId]; -} - -#pragma mark - RCTURLRequestHandler methods - -- (BOOL)canHandleRequest:(NSURLRequest *)request -{ - return [request.URL.scheme caseInsensitiveCompare:kBlobUriScheme] == NSOrderedSame; -} - -- (id)sendRequest:(NSURLRequest *)request withDelegate:(id)delegate -{ - // Lazy setup - if (!_queue) { - _queue = [NSOperationQueue new]; - _queue.maxConcurrentOperationCount = 2; - } - - __weak __block NSBlockOperation *weakOp; - __block NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^{ - NSURLResponse *response = [[NSURLResponse alloc] initWithURL:request.URL - MIMEType:nil - expectedContentLength:-1 - textEncodingName:nil]; - - [delegate URLRequest:weakOp didReceiveResponse:response]; - - NSURLComponents *components = [[NSURLComponents alloc] initWithURL:request.URL resolvingAgainstBaseURL:NO]; - - NSString *blobId = components.path; - NSInteger offset = 0; - NSInteger size = -1; - - if (components.queryItems) { - for (NSURLQueryItem *queryItem in components.queryItems) { - if ([queryItem.name isEqualToString:@"offset"]) { - offset = [queryItem.value integerValue]; - } - if ([queryItem.name isEqualToString:@"size"]) { - size = [queryItem.value integerValue]; - } - } - } - - NSData *data; - if (blobId) { - data = [self resolve:blobId offset:offset size:size]; - } - NSError *error; - if (data) { - [delegate URLRequest:weakOp didReceiveData:data]; - } else { - error = [[NSError alloc] initWithDomain:NSURLErrorDomain code:NSURLErrorBadURL userInfo:nil]; - } - [delegate URLRequest:weakOp didCompleteWithError:error]; - }]; - - weakOp = op; - [_queue addOperation:op]; - return op; -} - -- (void)cancelRequest:(NSOperation *)op -{ - [op cancel]; -} - -@end - -@implementation _RCTBlobContentHandler { - __weak RCTBlobManager *_blobManager; -} - -- (instancetype)initWithBlobManager:(RCTBlobManager *)blobManager -{ - if (self = [super init]) { - _blobManager = blobManager; - } - return self; -} - -- (id)processMessage:(id)message forSocketID:(NSNumber *)socketID withType:(NSString *__autoreleasing _Nonnull *)type -{ - if (![message isKindOfClass:[NSData class]]) { - *type = @"text"; - return message; - } - - *type = @"blob"; - return @{ - @"blobId": [_blobManager store:message], - @"offset": @0, - @"size": @(((NSData *)message).length), - }; -} - -@end diff --git a/Libraries/Blob/RCTBlobManager.mm b/Libraries/Blob/RCTBlobManager.mm new file mode 100755 index 00000000000000..56235ee04b6dfe --- /dev/null +++ b/Libraries/Blob/RCTBlobManager.mm @@ -0,0 +1,289 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RCTBlobManager.h" + +#import + +#import +#import +#import +#import + +static NSString *const kBlobURIScheme = @"blob"; + +@interface RCTBlobManager () + +@end + +@implementation RCTBlobManager +{ + // Blobs should be thread safe since they are used from the websocket and networking module, + // make sure to use proper locking when accessing this. + NSMutableDictionary *_blobs; + std::mutex _blobsMutex; + + NSOperationQueue *_queue; +} + +RCT_EXPORT_MODULE(BlobModule) + +@synthesize bridge = _bridge; + +- (void)setBridge:(RCTBridge *)bridge +{ + _bridge = bridge; + + std::lock_guard lock(_blobsMutex); + _blobs = [NSMutableDictionary new]; +} + ++ (BOOL)requiresMainQueueSetup +{ + return NO; +} + +- (NSDictionary *)constantsToExport +{ + return @{ + @"BLOB_URI_SCHEME": kBlobURIScheme, + @"BLOB_URI_HOST": [NSNull null], + }; +} + +- (NSString *)store:(NSData *)data +{ + NSString *blobId = [NSUUID UUID].UUIDString; + [self store:data withId:blobId]; + return blobId; +} + +- (void)store:(NSData *)data withId:(NSString *)blobId +{ + std::lock_guard lock(_blobsMutex); + _blobs[blobId] = data; +} + +- (NSData *)resolve:(NSDictionary *)blob +{ + NSString *blobId = [RCTConvert NSString:blob[@"blobId"]]; + NSNumber *offset = [RCTConvert NSNumber:blob[@"offset"]]; + NSNumber *size = [RCTConvert NSNumber:blob[@"size"]]; + return [self resolve:blobId + offset:offset ? [offset integerValue] : 0 + size:size ? [size integerValue] : -1]; +} + +- (NSData *)resolve:(NSString *)blobId offset:(NSInteger)offset size:(NSInteger)size +{ + NSData *data; + { + std::lock_guard lock(_blobsMutex); + data = _blobs[blobId]; + } + if (!data) { + return nil; + } + if (offset != 0 || (size != -1 && size != data.length)) { + data = [data subdataWithRange:NSMakeRange(offset, size)]; + } + return data; +} + +- (NSData *)resolveURL:(NSURL *)url +{ + NSURLComponents *components = [[NSURLComponents alloc] initWithURL:url resolvingAgainstBaseURL:NO]; + + NSString *blobId = components.path; + NSInteger offset = 0; + NSInteger size = -1; + + if (components.queryItems) { + for (NSURLQueryItem *queryItem in components.queryItems) { + if ([queryItem.name isEqualToString:@"offset"]) { + offset = [queryItem.value integerValue]; + } + if ([queryItem.name isEqualToString:@"size"]) { + size = [queryItem.value integerValue]; + } + } + } + + if (blobId) { + return [self resolve:blobId offset:offset size:size]; + } + return nil; +} + +- (void)remove:(NSString *)blobId +{ + std::lock_guard lock(_blobsMutex); + [_blobs removeObjectForKey:blobId]; +} + +RCT_EXPORT_METHOD(addNetworkingHandler) +{ + dispatch_async(_bridge.networking.methodQueue, ^{ + [self->_bridge.networking addRequestHandler:self]; + [self->_bridge.networking addResponseHandler:self]; + }); +} + +RCT_EXPORT_METHOD(addWebSocketHandler:(nonnull NSNumber *)socketID) +{ + dispatch_async(_bridge.webSocketModule.methodQueue, ^{ + [self->_bridge.webSocketModule setContentHandler:self forSocketID:socketID]; + }); +} + +RCT_EXPORT_METHOD(removeWebSocketHandler:(nonnull NSNumber *)socketID) +{ + dispatch_async(_bridge.webSocketModule.methodQueue, ^{ + [self->_bridge.webSocketModule setContentHandler:nil forSocketID:socketID]; + }); +} + +// @lint-ignore FBOBJCUNTYPEDCOLLECTION1 +RCT_EXPORT_METHOD(sendOverSocket:(NSDictionary *)blob socketID:(nonnull NSNumber *)socketID) +{ + dispatch_async(_bridge.webSocketModule.methodQueue, ^{ + [self->_bridge.webSocketModule sendData:[self resolve:blob] forSocketID:socketID]; + }); +} + +RCT_EXPORT_METHOD(createFromParts:(NSArray *> *)parts withId:(NSString *)blobId) +{ + NSMutableData *data = [NSMutableData new]; + for (NSDictionary *part in parts) { + NSString *type = [RCTConvert NSString:part[@"type"]]; + + if ([type isEqualToString:@"blob"]) { + NSData *partData = [self resolve:part[@"data"]]; + [data appendData:partData]; + } else if ([type isEqualToString:@"string"]) { + NSData *partData = [[RCTConvert NSString:part[@"data"]] dataUsingEncoding:NSUTF8StringEncoding]; + [data appendData:partData]; + } else { + [NSException raise:@"Invalid type for blob" format:@"%@ is invalid", type]; + } + } + [self store:data withId:blobId]; +} + +RCT_EXPORT_METHOD(release:(NSString *)blobId) +{ + [self remove:blobId]; +} + +#pragma mark - RCTURLRequestHandler methods + +- (BOOL)canHandleRequest:(NSURLRequest *)request +{ + return [request.URL.scheme caseInsensitiveCompare:kBlobURIScheme] == NSOrderedSame; +} + +- (id)sendRequest:(NSURLRequest *)request withDelegate:(id)delegate +{ + // Lazy setup + if (!_queue) { + _queue = [NSOperationQueue new]; + _queue.maxConcurrentOperationCount = 2; + } + + __weak __typeof(self) weakSelf = self; + __weak __block NSBlockOperation *weakOp; + __block NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^{ + __typeof(self) strongSelf = weakSelf; + if (!strongSelf) { + return; + } + NSURLResponse *response = [[NSURLResponse alloc] initWithURL:request.URL + MIMEType:nil + expectedContentLength:-1 + textEncodingName:nil]; + + [delegate URLRequest:weakOp didReceiveResponse:response]; + + NSData *data = [strongSelf resolveURL:response.URL]; + NSError *error; + if (data) { + [delegate URLRequest:weakOp didReceiveData:data]; + } else { + error = [[NSError alloc] initWithDomain:NSURLErrorDomain code:NSURLErrorBadURL userInfo:nil]; + } + [delegate URLRequest:weakOp didCompleteWithError:error]; + }]; + + weakOp = op; + [_queue addOperation:op]; + return op; +} + +- (void)cancelRequest:(NSOperation *)op +{ + [op cancel]; +} + +#pragma mark - RCTNetworkingRequestHandler methods + +// @lint-ignore FBOBJCUNTYPEDCOLLECTION1 +- (BOOL)canHandleNetworkingRequest:(NSDictionary *)data +{ + return data[@"blob"] != nil; +} + +// @lint-ignore FBOBJCUNTYPEDCOLLECTION1 +- (NSDictionary *)handleNetworkingRequest:(NSDictionary *)data +{ + // @lint-ignore FBOBJCUNTYPEDCOLLECTION1 + NSDictionary *blob = [RCTConvert NSDictionary:data[@"blob"]]; + + NSString *contentType = @"application/octet-stream"; + NSString *blobType = [RCTConvert NSString:blob[@"type"]]; + if (blobType != nil && blobType.length > 0) { + contentType = blob[@"type"]; + } + + return @{@"body": [self resolve:blob], @"contentType": contentType}; +} + +- (BOOL)canHandleNetworkingResponse:(NSString *)responseType +{ + return [responseType isEqualToString:@"blob"]; +} + +- (id)handleNetworkingResponse:(NSURLResponse *)response data:(NSData *)data +{ + return @{ + @"blobId": [self store:data], + @"offset": @0, + @"size": @(data.length), + @"name": RCTNullIfNil([response suggestedFilename]), + @"type": RCTNullIfNil([response MIMEType]), + }; +} + +#pragma mark - RCTWebSocketContentHandler methods + +- (id)processWebsocketMessage:(id)message + forSocketID:(NSNumber *)socketID + withType:(NSString *__autoreleasing _Nonnull *)type +{ + if (![message isKindOfClass:[NSData class]]) { + *type = @"text"; + return message; + } + + *type = @"blob"; + return @{ + @"blobId": [self store:message], + @"offset": @0, + @"size": @(((NSData *)message).length), + }; +} + +@end diff --git a/Libraries/Blob/RCTFileReaderModule.h b/Libraries/Blob/RCTFileReaderModule.h new file mode 100644 index 00000000000000..72d224b0d968cb --- /dev/null +++ b/Libraries/Blob/RCTFileReaderModule.h @@ -0,0 +1,12 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +@interface RCTFileReaderModule : NSObject + +@end diff --git a/Libraries/Blob/RCTFileReaderModule.m b/Libraries/Blob/RCTFileReaderModule.m new file mode 100644 index 00000000000000..5059e0b84180ee --- /dev/null +++ b/Libraries/Blob/RCTFileReaderModule.m @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + + +#import "RCTFileReaderModule.h" + +#import +#import + +#import "RCTBlobManager.h" + + +@implementation RCTFileReaderModule + +RCT_EXPORT_MODULE(FileReaderModule) + +@synthesize bridge = _bridge; + +RCT_EXPORT_METHOD(readAsText:(NSDictionary *)blob + encoding:(NSString *)encoding + resolve:(RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject) +{ + RCTBlobManager *blobManager = [[self bridge] moduleForClass:[RCTBlobManager class]]; + NSData *data = [blobManager resolve:blob]; + + if (data == nil) { + reject(RCTErrorUnspecified, + [NSString stringWithFormat:@"Unable to resolve data for blob: %@", [RCTConvert NSString:blob[@"blobId"]]], nil); + } else { + NSStringEncoding stringEncoding; + + if (encoding == nil) { + stringEncoding = NSUTF8StringEncoding; + } else { + stringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef) encoding)); + } + + NSString *text = [[NSString alloc] initWithData:data encoding:stringEncoding]; + + resolve(text); + } +} + +RCT_EXPORT_METHOD(readAsDataURL:(NSDictionary *)blob + resolve:(RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject) +{ + RCTBlobManager *blobManager = [[self bridge] moduleForClass:[RCTBlobManager class]]; + NSData *data = [blobManager resolve:blob]; + + if (data == nil) { + reject(RCTErrorUnspecified, + [NSString stringWithFormat:@"Unable to resolve data for blob: %@", [RCTConvert NSString:blob[@"blobId"]]], nil); + } else { + NSString *type = [RCTConvert NSString:blob[@"type"]]; + NSString *text = [NSString stringWithFormat:@"data:%@;base64,%@", + type != nil && [type length] > 0 ? type : @"application/octet-stream", + [data base64EncodedStringWithOptions:0]]; + + resolve(text); + } +} + +@end diff --git a/Libraries/Blob/URL.js b/Libraries/Blob/URL.js index ed40cae6567dc9..7349f7752f268c 100644 --- a/Libraries/Blob/URL.js +++ b/Libraries/Blob/URL.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule URL * @format @@ -52,16 +50,16 @@ if (BlobModule && typeof BlobModule.BLOB_URI_SCHEME === 'string') { */ class URL { constructor() { - throw new Error('Creating BlobURL objects is not supported yet.'); + throw new Error('Creating URL objects is not supported yet.'); } static createObjectURL(blob: Blob) { if (BLOB_URL_PREFIX === null) { throw new Error('Cannot create URL for blob!'); } - return `${BLOB_URL_PREFIX}${blob.blobId}?offset=${blob.offset}&size=${ - blob.size - }`; + return `${BLOB_URL_PREFIX}${blob.data.blobId}?offset=${ + blob.data.offset + }&size=${blob.size}`; } static revokeObjectURL(url: string) { diff --git a/Libraries/Blob/__mocks__/BlobModule.js b/Libraries/Blob/__mocks__/BlobModule.js new file mode 100644 index 00000000000000..2542c3a9339adc --- /dev/null +++ b/Libraries/Blob/__mocks__/BlobModule.js @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ +const BlobModule = { + createFromParts() {}, + release() {}, +}; + +module.exports = BlobModule; diff --git a/Libraries/Blob/__mocks__/FileReaderModule.js b/Libraries/Blob/__mocks__/FileReaderModule.js new file mode 100644 index 00000000000000..f5ccc39d36e200 --- /dev/null +++ b/Libraries/Blob/__mocks__/FileReaderModule.js @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ +const FileReaderModule = { + async readAsText() { + return ''; + }, + async readAsDataURL() { + return 'data:text/plain;base64,NDI='; + }, +}; + +module.exports = FileReaderModule; diff --git a/Libraries/Blob/__tests__/Blob-test.js b/Libraries/Blob/__tests__/Blob-test.js new file mode 100644 index 00000000000000..8d37915720c9b3 --- /dev/null +++ b/Libraries/Blob/__tests__/Blob-test.js @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @emails oncall+react_native + */ +'use strict'; + +jest.setMock('NativeModules', { + BlobModule: require('../__mocks__/BlobModule'), +}); + +var Blob = require('Blob'); + +describe('Blob', function() { + it('should create empty blob', () => { + const blob = new Blob(); + expect(blob).toBeInstanceOf(Blob); + expect(blob.data.offset).toBe(0); + expect(blob.data.size).toBe(0); + expect(blob.size).toBe(0); + expect(blob.type).toBe(''); + }); + + it('should create blob from other blobs and strings', () => { + const blobA = new Blob(); + const blobB = new Blob(); + const textA = 'i \u2665 dogs'; + const textB = '\uD800\uDC00'; + const textC = + 'Z\u0351\u036B\u0343\u036A\u0302\u036B\u033D\u034F\u0334\u0319\u0324' + + '\u031E\u0349\u035A\u032F\u031E\u0320\u034DA\u036B\u0357\u0334\u0362' + + '\u0335\u031C\u0330\u0354L\u0368\u0367\u0369\u0358\u0320G\u0311\u0357' + + '\u030E\u0305\u035B\u0341\u0334\u033B\u0348\u034D\u0354\u0339O\u0342' + + '\u030C\u030C\u0358\u0328\u0335\u0339\u033B\u031D\u0333!\u033F\u030B' + + '\u0365\u0365\u0302\u0363\u0310\u0301\u0301\u035E\u035C\u0356\u032C' + + '\u0330\u0319\u0317'; + + blobA.data.size = 34540; + blobB.data.size = 65452; + + const blob = new Blob([blobA, blobB, textA, textB, textC]); + + expect(blob.size).toBe( + blobA.size + + blobB.size + + global.Buffer.byteLength(textA, 'UTF-8') + + global.Buffer.byteLength(textB, 'UTF-8') + + global.Buffer.byteLength(textC, 'UTF-8'), + ); + expect(blob.type).toBe(''); + }); + + it('should slice a blob', () => { + const blob = new Blob(); + + blob.data.size = 34546; + + const sliceA = blob.slice(0, 2354); + + expect(sliceA.data.offset).toBe(0); + expect(sliceA.size).toBe(2354); + expect(sliceA.type).toBe(''); + + const sliceB = blob.slice(2384, 7621); + + expect(sliceB.data.offset).toBe(2384); + expect(sliceB.size).toBe(7621 - 2384); + expect(sliceB.type).toBe(''); + }); + + it('should close a blob', () => { + const blob = new Blob(); + + blob.close(); + + expect(() => blob.size).toThrow(); + }); +}); diff --git a/Libraries/Blob/__tests__/BlobManager-test.js b/Libraries/Blob/__tests__/BlobManager-test.js new file mode 100644 index 00000000000000..2ed118b446be1c --- /dev/null +++ b/Libraries/Blob/__tests__/BlobManager-test.js @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @emails oncall+react_native + */ +'use strict'; + +jest.setMock('NativeModules', { + BlobModule: require('../__mocks__/BlobModule'), +}); + +var Blob = require('Blob'); +var BlobManager = require('BlobManager'); + +describe('BlobManager', function() { + it('should create blob from parts', () => { + const blob = BlobManager.createFromParts([], {type: 'text/html'}); + expect(blob).toBeInstanceOf(Blob); + expect(blob.type).toBe('text/html'); + }); +}); diff --git a/Libraries/Blob/__tests__/File-test.js b/Libraries/Blob/__tests__/File-test.js new file mode 100644 index 00000000000000..d466d61b8b3502 --- /dev/null +++ b/Libraries/Blob/__tests__/File-test.js @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @emails oncall+react_native + */ +'use strict'; + +jest.setMock('NativeModules', { + BlobModule: require('../__mocks__/BlobModule'), +}); + +const File = require('File'); + +describe('File', function() { + it('should create empty file', () => { + const file = new File([], 'test.jpg'); + expect(file).toBeInstanceOf(File); + expect(file.data.offset).toBe(0); + expect(file.data.size).toBe(0); + expect(file.size).toBe(0); + expect(file.type).toBe(''); + expect(file.name).toBe('test.jpg'); + expect(file.lastModified).toEqual(expect.any(Number)); + }); + + it('should create empty file with type', () => { + const file = new File([], 'test.jpg', {type: 'image/jpeg'}); + expect(file.type).toBe('image/jpeg'); + }); + + it('should create empty file with lastModified', () => { + const file = new File([], 'test.jpg', {lastModified: 1337}); + expect(file.lastModified).toBe(1337); + }); + + it('should throw on invalid arguments', () => { + expect(() => new File()).toThrow(); + expect(() => new File([])).toThrow(); + }); +}); diff --git a/Libraries/Blob/__tests__/FileReader-test.js b/Libraries/Blob/__tests__/FileReader-test.js new file mode 100644 index 00000000000000..a278a4918a9d10 --- /dev/null +++ b/Libraries/Blob/__tests__/FileReader-test.js @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @emails oncall+react_native + */ +'use strict'; + +jest.unmock('event-target-shim').setMock('NativeModules', { + BlobModule: require('../__mocks__/BlobModule'), + FileReaderModule: require('../__mocks__/FileReaderModule'), +}); + +var Blob = require('Blob'); +var FileReader = require('FileReader'); + +describe('FileReader', function() { + it('should read blob as text', async () => { + const e = await new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = resolve; + reader.onerror = reject; + reader.readAsText(new Blob()); + }); + expect(e.target.result).toBe(''); + }); + + it('should read blob as data URL', async () => { + const e = await new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = resolve; + reader.onerror = reject; + reader.readAsDataURL(new Blob()); + }); + expect(e.target.result).toBe('data:text/plain;base64,NDI='); + }); +}); diff --git a/Libraries/BugReporting/BugReporting.js b/Libraries/BugReporting/BugReporting.js index bf795899139a69..11a59e6d5222ca 100644 --- a/Libraries/BugReporting/BugReporting.js +++ b/Libraries/BugReporting/BugReporting.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule BugReporting * @flow diff --git a/Libraries/BugReporting/dumpReactTree.js b/Libraries/BugReporting/dumpReactTree.js index 88a5b7f8ffbe2e..f8a137ceff7f2c 100644 --- a/Libraries/BugReporting/dumpReactTree.js +++ b/Libraries/BugReporting/dumpReactTree.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule dumpReactTree * @flow diff --git a/Libraries/BugReporting/getReactData.js b/Libraries/BugReporting/getReactData.js index 18f4b0888f846a..53c8fb6ccfc110 100644 --- a/Libraries/BugReporting/getReactData.js +++ b/Libraries/BugReporting/getReactData.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule getReactData * @flow diff --git a/Libraries/CameraRoll/CameraRoll.js b/Libraries/CameraRoll/CameraRoll.js index 78f8d365aaea24..3bc48664f35db1 100644 --- a/Libraries/CameraRoll/CameraRoll.js +++ b/Libraries/CameraRoll/CameraRoll.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @providesModule CameraRoll * @flow @@ -115,8 +113,10 @@ type GetPhotosReturn = Promise<{ * Shape of the return value of the `getPhotos` function. */ const getPhotosReturnChecker = createStrictShapeTypeChecker({ - // $FlowFixMe(>=0.41.0) edges: PropTypes.arrayOf( + /* $FlowFixMe(>=0.66.0 site=react_native_fb) This comment suppresses an + * error found when Flow v0.66 was deployed. To see the error delete this + * comment and run Flow. */ createStrictShapeTypeChecker({ node: createStrictShapeTypeChecker({ type: PropTypes.string.isRequired, @@ -147,15 +147,9 @@ const getPhotosReturnChecker = createStrictShapeTypeChecker({ }); /** - * `CameraRoll` provides access to the local camera roll / gallery. - * Before using this you must link the `RCTCameraRoll` library. - * You can refer to [Linking](docs/linking-libraries-ios.html) for help. - * - * ### Permissions - * The user's permission is required in order to access the Camera Roll on devices running iOS 10 or later. - * Add the `NSPhotoLibraryUsageDescription` key in your `Info.plist` with a string that describes how your - * app will use this data. This key will appear as `Privacy - Photo Library Usage Description` in Xcode. + * `CameraRoll` provides access to the local camera roll or photo library. * + * See https://facebook.github.io/react-native/docs/cameraroll.html */ class CameraRoll { static GroupTypesOptions: Object = GROUP_TYPES_OPTIONS; @@ -176,18 +170,9 @@ class CameraRoll { } /** - * Saves the photo or video to the camera roll / gallery. - * - * On Android, the tag must be a local image or video URI, such as `"file:///sdcard/img.png"`. - * - * On iOS, the tag can be any image URI (including local, remote asset-library and base64 data URIs) - * or a local video file URI (remote or data URIs are not supported for saving video at this time). - * - * If the tag has a file extension of .mov or .mp4, it will be inferred as a video. Otherwise - * it will be treated as a photo. To override the automatic choice, you can pass an optional - * `type` parameter that must be one of 'photo' or 'video'. + * Saves the photo or video to the camera roll or photo library. * - * Returns a Promise which will resolve with the new URI. + * See https://facebook.github.io/react-native/docs/cameraroll.html#savetocameraroll */ static saveToCameraRoll( tag: string, @@ -218,84 +203,7 @@ class CameraRoll { * Returns a Promise with photo identifier objects from the local camera * roll of the device matching shape defined by `getPhotosReturnChecker`. * - * Expects a params object of the following shape: - * - * - `first` : {number} : The number of photos wanted in reverse order of the photo application (i.e. most recent first for SavedPhotos). - * - `after` : {string} : A cursor that matches `page_info { end_cursor }` returned from a previous call to `getPhotos`. - * - `groupTypes` : {string} : Specifies which group types to filter the results to. Valid values are: - * - `Album` - * - `All` - * - `Event` - * - `Faces` - * - `Library` - * - `PhotoStream` - * - `SavedPhotos` // default - * - `groupName` : {string} : Specifies filter on group names, like 'Recent Photos' or custom album titles. - * - `assetType` : {string} : Specifies filter on asset type. Valid values are: - * - `All` - * - `Videos` - * - `Photos` // default - * - `mimeTypes` : {string} : Filter by mimetype (e.g. image/jpeg). - * - * Returns a Promise which when resolved will be of the following shape: - * - * - `edges` : {Array} An array of node objects - * - `node`: {object} An object with the following shape: - * - `type`: {string} - * - `group_name`: {string} - * - `image`: {object} : An object with the following shape: - * - `uri`: {string} - * - `height`: {number} - * - `width`: {number} - * - `isStored`: {boolean} - * - `timestamp`: {number} - * - `location`: {object} : An object with the following shape: - * - `latitude`: {number} - * - `longitude`: {number} - * - `altitude`: {number} - * - `heading`: {number} - * - `speed`: {number} - * - `page_info` : {object} : An object with the following shape: - * - `has_next_page`: {boolean} - * - `start_cursor`: {string} - * - `end_cursor`: {string} - * - * Loading images: - * ``` - * _handleButtonPress = () => { - * CameraRoll.getPhotos({ - * first: 20, - * assetType: 'All', - * }) - * .then(r => { - * this.setState({ photos: r.edges }); - * }) - * .catch((err) => { - * //Error Loading Images - * }); - * }; - * render() { - * return ( - * - *