mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Codemod usages of NativeEventEmitter in react-native-github to only pass a native module on iOS
Summary: Changelog: [Internal] Reviewed By: yungsters Differential Revision: D27500993 fbshipit-source-id: 99b33e25daf46b7d1debc6435dd32505ad2cf855
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b28ddede7b
commit
87517aeecb
@@ -397,7 +397,11 @@ module.exports = {
|
||||
// $FlowExpectedError[missing-type-arg] - unsafe getter lint suppresion
|
||||
get nativeEventEmitter(): NativeEventEmitter {
|
||||
if (!nativeEventEmitter) {
|
||||
nativeEventEmitter = new NativeEventEmitter(NativeAnimatedModule);
|
||||
nativeEventEmitter = new NativeEventEmitter(
|
||||
// T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior
|
||||
// If you want to use the native module on other platforms, please remove this condition and test its behavior
|
||||
Platform.OS !== 'ios' ? null : NativeAnimatedModule,
|
||||
);
|
||||
}
|
||||
return nativeEventEmitter;
|
||||
},
|
||||
|
||||
@@ -12,6 +12,7 @@ import {type EventSubscription} from '../vendor/emitter/EventEmitter';
|
||||
import NativeEventEmitter from '../EventEmitter/NativeEventEmitter';
|
||||
import logError from '../Utilities/logError';
|
||||
import NativeAppState from './NativeAppState';
|
||||
import Platform from '../Utilities/Platform';
|
||||
|
||||
export type AppStateValues = 'inactive' | 'background' | 'active';
|
||||
|
||||
@@ -47,7 +48,9 @@ class AppState {
|
||||
this.isAvailable = true;
|
||||
|
||||
const emitter: NativeEventEmitter<NativeAppStateEventDefinitions> = new NativeEventEmitter(
|
||||
NativeAppState,
|
||||
// T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior
|
||||
// If you want to use the native module on other platforms, please remove this condition and test its behavior
|
||||
Platform.OS !== 'ios' ? null : NativeAppState,
|
||||
);
|
||||
this._emitter = emitter;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
import NativeEventEmitter from '../../EventEmitter/NativeEventEmitter';
|
||||
import LayoutAnimation from '../../LayoutAnimation/LayoutAnimation';
|
||||
import dismissKeyboard from '../../Utilities/dismissKeyboard';
|
||||
import Platform from '../../Utilities/Platform';
|
||||
import NativeKeyboardObserver from './NativeKeyboardObserver';
|
||||
import {type EventSubscription} from '../../vendor/emitter/EventEmitter';
|
||||
|
||||
@@ -103,7 +104,9 @@ type KeyboardEventDefinitions = {
|
||||
|
||||
class Keyboard {
|
||||
_emitter: NativeEventEmitter<KeyboardEventDefinitions> = new NativeEventEmitter(
|
||||
NativeKeyboardObserver,
|
||||
// T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior
|
||||
// If you want to use the native module on other platforms, please remove this condition and test its behavior
|
||||
Platform.OS !== 'ios' ? null : NativeKeyboardObserver,
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,11 @@ type ModalEventDefinitions = {
|
||||
|
||||
const ModalEventEmitter =
|
||||
Platform.OS === 'ios' && NativeModalManager != null
|
||||
? new NativeEventEmitter<ModalEventDefinitions>(NativeModalManager)
|
||||
? new NativeEventEmitter<ModalEventDefinitions>(
|
||||
// T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior
|
||||
// If you want to use the native module on other platforms, please remove this condition and test its behavior
|
||||
Platform.OS !== 'ios' ? null : NativeModalManager,
|
||||
)
|
||||
: null;
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
import NativeEventEmitter from '../EventEmitter/NativeEventEmitter';
|
||||
import NativePushNotificationManagerIOS from './NativePushNotificationManagerIOS';
|
||||
import invariant from 'invariant';
|
||||
import Platform from '../Utilities/Platform';
|
||||
|
||||
type NativePushNotificationIOSEventDefinitions = {
|
||||
remoteNotificationReceived: [
|
||||
@@ -37,7 +38,9 @@ type NativePushNotificationIOSEventDefinitions = {
|
||||
};
|
||||
|
||||
const PushNotificationEmitter = new NativeEventEmitter<NativePushNotificationIOSEventDefinitions>(
|
||||
NativePushNotificationManagerIOS,
|
||||
// T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior
|
||||
// If you want to use the native module on other platforms, please remove this condition and test its behavior
|
||||
Platform.OS !== 'ios' ? null : NativePushNotificationManagerIOS,
|
||||
);
|
||||
|
||||
const _notifHandlers = new Map();
|
||||
|
||||
@@ -18,6 +18,7 @@ import NativeAppearance, {
|
||||
} from './NativeAppearance';
|
||||
import invariant from 'invariant';
|
||||
import {isAsyncDebugging} from './DebugEnvironment';
|
||||
import Platform from '../Utilities/Platform';
|
||||
|
||||
type AppearanceListener = (preferences: AppearancePreferences) => void;
|
||||
const eventEmitter = new EventEmitter<{
|
||||
@@ -30,7 +31,9 @@ type NativeAppearanceEventDefinitions = {
|
||||
|
||||
if (NativeAppearance) {
|
||||
const nativeEventEmitter = new NativeEventEmitter<NativeAppearanceEventDefinitions>(
|
||||
NativeAppearance,
|
||||
// T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior
|
||||
// If you want to use the native module on other platforms, please remove this condition and test its behavior
|
||||
Platform.OS !== 'ios' ? null : NativeAppearance,
|
||||
);
|
||||
nativeEventEmitter.addListener(
|
||||
'appearanceChanged',
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
import NativeDevSettings from '../NativeModules/specs/NativeDevSettings';
|
||||
import NativeEventEmitter from '../EventEmitter/NativeEventEmitter';
|
||||
import Platform from '../Utilities/Platform';
|
||||
|
||||
let DevSettings: {
|
||||
addMenuItem(title: string, handler: () => mixed): void,
|
||||
@@ -27,7 +28,9 @@ type DevSettingsEventDefinitions = {
|
||||
|
||||
if (__DEV__) {
|
||||
const emitter = new NativeEventEmitter<DevSettingsEventDefinitions>(
|
||||
NativeDevSettings,
|
||||
// T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior
|
||||
// If you want to use the native module on other platforms, please remove this condition and test its behavior
|
||||
Platform.OS !== 'ios' ? null : NativeDevSettings,
|
||||
);
|
||||
const subscriptions = new Map();
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import type {BlobData} from '../Blob/BlobTypes';
|
||||
import BlobManager from '../Blob/BlobManager';
|
||||
import NativeEventEmitter from '../EventEmitter/NativeEventEmitter';
|
||||
import binaryToBase64 from '../Utilities/binaryToBase64';
|
||||
import Platform from '../Utilities/Platform';
|
||||
import type {EventSubscription} from '../vendor/emitter/EventEmitter';
|
||||
import NativeWebSocketModule from './NativeWebSocketModule';
|
||||
import WebSocketEvent from './WebSocketEvent';
|
||||
@@ -131,7 +132,11 @@ class WebSocket extends (EventTarget(...WEBSOCKET_EVENTS): any) {
|
||||
protocols = null;
|
||||
}
|
||||
|
||||
this._eventEmitter = new NativeEventEmitter(NativeWebSocketModule);
|
||||
this._eventEmitter = new NativeEventEmitter(
|
||||
// T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior
|
||||
// If you want to use the native module on other platforms, please remove this condition and test its behavior
|
||||
Platform.OS !== 'ios' ? null : NativeWebSocketModule,
|
||||
);
|
||||
this._socketId = nextWebSocketId++;
|
||||
this._registerEvents();
|
||||
NativeWebSocketModule.connect(url, protocols, {headers}, this._socketId);
|
||||
|
||||
@@ -15,6 +15,7 @@ jest.setMock('../../BatchedBridge/NativeModules', {
|
||||
WebSocketModule: {
|
||||
connect: () => {},
|
||||
},
|
||||
PlatformConstants: {},
|
||||
});
|
||||
|
||||
const WebSocket = require('../WebSocket');
|
||||
|
||||
Reference in New Issue
Block a user