From 8293e4c3012f118bb48b3f959a826ccefda26fac Mon Sep 17 00:00:00 2001 From: Eli White Date: Thu, 13 Feb 2020 15:06:03 -0800 Subject: [PATCH] Remove ReactNative.NativeComponent from React Native Summary: This class is no longer used by the core and thus can be removed. It isn't exposed as part of our public API so this is technically not a breaking change, although it may still cause people trouble if they are reaching into internals. It is expected that people will use forwardRef instead of this class. I will follow up this diff with a removal from the ReactNativeRenderer as well. Changelog: [Internal] Remove ReactNative.NativeComponent from React Native Reviewed By: JoshuaGross Differential Revision: D19888400 fbshipit-source-id: 78da51e6c0edf9d8706395d376c3bfe75dabda03 --- Libraries/Components/ScrollResponder.js | 5 +--- .../ReactNativeTypes-flowtest.js | 24 ++----------------- jest/setup.js | 1 - .../__test_fixtures__/failures.js | 12 +++++----- .../__test_fixtures__/fixtures.js | 8 +++---- .../__snapshots__/index-test.js.snap | 8 +++---- 6 files changed, 17 insertions(+), 41 deletions(-) diff --git a/Libraries/Components/ScrollResponder.js b/Libraries/Components/ScrollResponder.js index fe8652ca65c..9353c90beb1 100644 --- a/Libraries/Components/ScrollResponder.js +++ b/Libraries/Components/ScrollResponder.js @@ -570,10 +570,7 @@ const ScrollResponderMixin = { * down to make it meet the keyboard's top. Default is false. */ scrollResponderScrollNativeHandleToKeyboard: function( - nodeHandle: - | number - | React.ElementRef> - | React.ElementRef>>, + nodeHandle: number | React.ElementRef>, additionalOffset?: number, preventNegativeScrollOffset?: boolean, ) { diff --git a/Libraries/__flowtests__/ReactNativeTypes-flowtest.js b/Libraries/__flowtests__/ReactNativeTypes-flowtest.js index cb21b05ab45..e6c0bb124d5 100644 --- a/Libraries/__flowtests__/ReactNativeTypes-flowtest.js +++ b/Libraries/__flowtests__/ReactNativeTypes-flowtest.js @@ -11,13 +11,10 @@ 'use strict'; import * as React from 'react'; -import type { - HostComponent, - _InternalReactNativeComponentClass, -} from '../Renderer/shims/ReactNativeTypes'; +import type {HostComponent} from '../Renderer/shims/ReactNativeTypes'; function takesHostComponentInstance( - instance: React$ElementRef> | null, + instance: React.ElementRef> | null, ): void {} const MyHostComponent = (('Host': any): HostComponent); @@ -33,20 +30,3 @@ const MyHostComponent = (('Host': any): HostComponent); hostComponentRef.measureLayout(hostComponentRef, () => {}); }} />; - -declare var NativeComponent: _InternalReactNativeComponentClass<{...}>; -class MyNativeComponent extends NativeComponent {} - - { - // $FlowExpectedError - NativeComponent cannot be passed as HostComponent. - takesHostComponentInstance(nativeComponentRef); - - if (nativeComponentRef == null) { - return; - } - - // $FlowExpectedError - NativeComponent cannot be passed as HostComponent. - nativeComponentRef.measureLayout(nativeComponentRef, () => {}); - }} -/>; diff --git a/jest/setup.js b/jest/setup.js index 09bc4b3d2b6..b807bf829d6 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -150,7 +150,6 @@ jest .NativeMethodsMixin; Object.assign(NativeMethodsMixin, MockNativeMethods); - Object.assign(ReactNative.NativeComponent.prototype, MockNativeMethods); return ReactNative; }) diff --git a/packages/babel-plugin-inline-view-configs/__test_fixtures__/failures.js b/packages/babel-plugin-inline-view-configs/__test_fixtures__/failures.js index 3a46274d5c7..6ba62d5a2c6 100644 --- a/packages/babel-plugin-inline-view-configs/__test_fixtures__/failures.js +++ b/packages/babel-plugin-inline-view-configs/__test_fixtures__/failures.js @@ -16,13 +16,13 @@ const COMMANDS_EXPORTED_WITH_DIFFERENT_NAME = ` const codegenNativeComponent = require('codegenNativeComponent'); import type {ViewProps} from 'ViewPropTypes'; -import type {NativeComponent} from 'codegenNativeComponent'; +import type {NativeComponentType} from 'codegenNativeComponent'; type ModuleProps = $ReadOnly<{| ...ViewProps, |}>; -type NativeType = NativeComponent; +type NativeType = NativeComponentType; interface NativeCommands { +hotspotUpdate: (viewRef: React.ElementRef) => void; @@ -39,13 +39,13 @@ const OTHER_COMMANDS_EXPORT = ` const codegenNativeComponent = require('codegenNativeComponent'); import type {ViewProps} from 'ViewPropTypes'; -import type {NativeComponent} from 'codegenNativeComponent'; +import type {NativeComponentType} from 'codegenNativeComponent'; type ModuleProps = $ReadOnly<{| ...ViewProps, |}>; -type NativeType = NativeComponent; +type NativeType = NativeComponentType; interface NativeCommands { +hotspotUpdate: (viewRef: React.ElementRef) => void; @@ -60,7 +60,7 @@ const COMMANDS_EXPORTED_WITH_SHORTHAND = ` // @flow const codegenNativeComponent = require('codegenNativeComponent'); -import type {NativeComponent} from 'codegenNativeComponent'; +import type {NativeComponentType} from 'codegenNativeComponent'; import type {ViewProps} from 'ViewPropTypes'; @@ -68,7 +68,7 @@ type ModuleProps = $ReadOnly<{| ...ViewProps, |}>; -type NativeType = NativeComponent; +type NativeType = NativeComponentType; interface NativeCommands { +hotspotUpdate: (viewRef: React.ElementRef) => void; diff --git a/packages/babel-plugin-inline-view-configs/__test_fixtures__/fixtures.js b/packages/babel-plugin-inline-view-configs/__test_fixtures__/fixtures.js index aa231385778..946b622ea87 100644 --- a/packages/babel-plugin-inline-view-configs/__test_fixtures__/fixtures.js +++ b/packages/babel-plugin-inline-view-configs/__test_fixtures__/fixtures.js @@ -27,7 +27,7 @@ import type { DirectEventHandler, WithDefault, } from 'CodegenFlowtypes'; -import type {NativeComponent} from 'codegenNativeComponent'; +import type {NativeComponentType} from 'codegenNativeComponent'; import type {ViewProps} from 'ViewPropTypes'; @@ -42,7 +42,7 @@ type ModuleProps = $ReadOnly<{| onBubblingEventDefinedInlineNull: BubblingEventHandler, |}>; -type NativeType = NativeComponent; +type NativeType = NativeComponentType; interface NativeCommands { +hotspotUpdate: (viewRef: React.ElementRef, x: Int32, y: Int32) => void; @@ -64,7 +64,7 @@ const FULL_NATIVE_COMPONENT_WITH_TYPE_EXPORT = ` const codegenNativeCommands = require('codegenNativeCommands'); const codegenNativeComponent = require('codegenNativeComponent'); -import type {NativeComponent} from 'codegenNativeComponent'; +import type {NativeComponentType} from 'codegenNativeComponent'; import type { Int32, @@ -86,7 +86,7 @@ type ModuleProps = $ReadOnly<{| onBubblingEventDefinedInlineNull: BubblingEventHandler, |}>; -type NativeType = NativeComponent; +type NativeType = NativeComponentType; interface NativeCommands { +hotspotUpdate: (viewRef: React.ElementRef, x: Int32, y: Int32) => void; diff --git a/packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap b/packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap index 21b1ac3f2ee..67d908a6075 100644 --- a/packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap +++ b/packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap @@ -7,7 +7,7 @@ const codegenNativeCommands = require('codegenNativeCommands'); const codegenNativeComponent = require('codegenNativeComponent'); import type { Int32, BubblingEventHandler, DirectEventHandler, WithDefault } from 'CodegenFlowtypes'; -import type { NativeComponent } from 'codegenNativeComponent'; +import type { NativeComponentType } from 'codegenNativeComponent'; import type { ViewProps } from 'ViewPropTypes'; type ModuleProps = $ReadOnly<{| ...ViewProps, // Props @@ -16,7 +16,7 @@ type ModuleProps = $ReadOnly<{| ...ViewProps, onDirectEventDefinedInlineNull: DirectEventHandler, onBubblingEventDefinedInlineNull: BubblingEventHandler, |}>; -type NativeType = NativeComponent; +type NativeType = NativeComponentType; interface NativeCommands { +hotspotUpdate: (viewRef: React.ElementRef, x: Int32, y: Int32) => void, +scrollTo: (viewRef: React.ElementRef, y: Int32, animated: boolean) => void, @@ -71,7 +71,7 @@ const codegenNativeCommands = require('codegenNativeCommands'); const codegenNativeComponent = require('codegenNativeComponent'); -import type { NativeComponent } from 'codegenNativeComponent'; +import type { NativeComponentType } from 'codegenNativeComponent'; import type { Int32, BubblingEventHandler, DirectEventHandler, WithDefault } from 'CodegenFlowtypes'; import type { ViewProps } from 'ViewPropTypes'; type ModuleProps = $ReadOnly<{| ...ViewProps, @@ -81,7 +81,7 @@ type ModuleProps = $ReadOnly<{| ...ViewProps, onDirectEventDefinedInlineNull: DirectEventHandler, onBubblingEventDefinedInlineNull: BubblingEventHandler, |}>; -type NativeType = NativeComponent; +type NativeType = NativeComponentType; interface NativeCommands { +hotspotUpdate: (viewRef: React.ElementRef, x: Int32, y: Int32) => void, +scrollTo: (viewRef: React.ElementRef, y: Int32, animated: boolean) => void,