Skip to content

Commit

Permalink
Remove ReactNative.NativeComponent from React Native
Browse files Browse the repository at this point in the history
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
  • Loading branch information
elicwhite authored and facebook-github-bot committed Feb 13, 2020
1 parent 2b5283e commit 8293e4c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 41 deletions.
5 changes: 1 addition & 4 deletions Libraries/Components/ScrollResponder.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,7 @@ const ScrollResponderMixin = {
* down to make it meet the keyboard's top. Default is false.
*/
scrollResponderScrollNativeHandleToKeyboard: function<T>(
nodeHandle:
| number
| React.ElementRef<HostComponent<T>>
| React.ElementRef<Class<ReactNative.NativeComponent<T>>>,
nodeHandle: number | React.ElementRef<HostComponent<T>>,
additionalOffset?: number,
preventNegativeScrollOffset?: boolean,
) {
Expand Down
24 changes: 2 additions & 22 deletions Libraries/__flowtests__/ReactNativeTypes-flowtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<HostComponent<mixed>> | null,
instance: React.ElementRef<HostComponent<mixed>> | null,
): void {}

const MyHostComponent = (('Host': any): HostComponent<mixed>);
Expand All @@ -33,20 +30,3 @@ const MyHostComponent = (('Host': any): HostComponent<mixed>);
hostComponentRef.measureLayout(hostComponentRef, () => {});
}}
/>;

declare var NativeComponent: _InternalReactNativeComponentClass<{...}>;
class MyNativeComponent extends NativeComponent {}

<MyNativeComponent
ref={nativeComponentRef => {
// $FlowExpectedError - NativeComponent cannot be passed as HostComponent.
takesHostComponentInstance(nativeComponentRef);

if (nativeComponentRef == null) {
return;
}

// $FlowExpectedError - NativeComponent cannot be passed as HostComponent.
nativeComponentRef.measureLayout(nativeComponentRef, () => {});
}}
/>;
1 change: 0 additions & 1 deletion jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ jest
.NativeMethodsMixin;

Object.assign(NativeMethodsMixin, MockNativeMethods);
Object.assign(ReactNative.NativeComponent.prototype, MockNativeMethods);

return ReactNative;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModuleProps>;
type NativeType = NativeComponentType<ModuleProps>;
interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>) => void;
Expand All @@ -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<ModuleProps>;
type NativeType = NativeComponentType<ModuleProps>;
interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>) => void;
Expand All @@ -60,15 +60,15 @@ 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';
type ModuleProps = $ReadOnly<{|
...ViewProps,
|}>;
type NativeType = NativeComponent<ModuleProps>;
type NativeType = NativeComponentType<ModuleProps>;
interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -42,7 +42,7 @@ type ModuleProps = $ReadOnly<{|
onBubblingEventDefinedInlineNull: BubblingEventHandler<null>,
|}>;
type NativeType = NativeComponent<ModuleProps>;
type NativeType = NativeComponentType<ModuleProps>;
interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void;
Expand All @@ -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,
Expand All @@ -86,7 +86,7 @@ type ModuleProps = $ReadOnly<{|
onBubblingEventDefinedInlineNull: BubblingEventHandler<null>,
|}>;
type NativeType = NativeComponent<ModuleProps>;
type NativeType = NativeComponentType<ModuleProps>;
interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +16,7 @@ type ModuleProps = $ReadOnly<{| ...ViewProps,
onDirectEventDefinedInlineNull: DirectEventHandler<null>,
onBubblingEventDefinedInlineNull: BubblingEventHandler<null>,
|}>;
type NativeType = NativeComponent<ModuleProps>;
type NativeType = NativeComponentType<ModuleProps>;
interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void,
+scrollTo: (viewRef: React.ElementRef<NativeType>, y: Int32, animated: boolean) => void,
Expand Down Expand Up @@ -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,
Expand All @@ -81,7 +81,7 @@ type ModuleProps = $ReadOnly<{| ...ViewProps,
onDirectEventDefinedInlineNull: DirectEventHandler<null>,
onBubblingEventDefinedInlineNull: BubblingEventHandler<null>,
|}>;
type NativeType = NativeComponent<ModuleProps>;
type NativeType = NativeComponentType<ModuleProps>;
interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void,
+scrollTo: (viewRef: React.ElementRef<NativeType>, y: Int32, animated: boolean) => void,
Expand Down

0 comments on commit 8293e4c

Please sign in to comment.