Skip to content

Commit 38cfa93

Browse files
rubennortefacebook-github-bot
authored andcommittedApr 12, 2021
Migrate remaining modules using NativeEventEmitter to only pass the native module on iOS
Summary: Changelog: [Internal] Reviewed By: fred2028 Differential Revision: D27501270 fbshipit-source-id: 1d447017e862baf834310650778f2abbff50945c
1 parent 87517ae commit 38cfa93

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed
 

‎Libraries/Components/StatusBar/StatusBarIOS.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import NativeEventEmitter from '../../EventEmitter/NativeEventEmitter';
1212
import NativeStatusBarManagerIOS from './NativeStatusBarManagerIOS';
13+
import Platform from '../../Utilities/Platform';
1314

1415
type StatusBarFrameChangeEvent = {
1516
frame: {
@@ -30,4 +31,8 @@ type StatusBarIOSEventDefinitions = {
3031
*/
3132
class StatusBarIOS extends NativeEventEmitter<StatusBarIOSEventDefinitions> {}
3233

33-
module.exports = (new StatusBarIOS(NativeStatusBarManagerIOS): StatusBarIOS);
34+
module.exports = (new StatusBarIOS(
35+
// 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
36+
// If you want to use the native module on other platforms, please remove this condition and test its behavior
37+
Platform.OS !== 'ios' ? null : NativeStatusBarManagerIOS,
38+
): StatusBarIOS);

‎Libraries/Network/RCTNetworking.android.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import NativeEventEmitter from '../EventEmitter/NativeEventEmitter';
1414
import NativeNetworkingAndroid from './NativeNetworkingAndroid';
1515
import convertRequestBody from './convertRequestBody';
1616
import type {RequestBody} from './convertRequestBody';
17+
import Platform from '../Utilities/Platform';
1718

1819
type Header = [string, string];
1920

@@ -39,7 +40,11 @@ function generateRequestId(): number {
3940
// FIXME: use typed events
4041
class RCTNetworking extends NativeEventEmitter<$FlowFixMe> {
4142
constructor() {
42-
super(NativeNetworkingAndroid);
43+
super(
44+
// 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
45+
// If you want to use the native module on other platforms, please remove this condition and test its behavior
46+
Platform.OS !== 'ios' ? null : NativeNetworkingAndroid,
47+
);
4348
}
4449

4550
sendRequest(

‎Libraries/WebSocket/WebSocketInterceptor.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import NativeEventEmitter from '../EventEmitter/NativeEventEmitter';
1111
import NativeWebSocketModule from './NativeWebSocketModule';
12+
import Platform from '../Utilities/Platform';
1213
import base64 from 'base64-js';
1314

1415
const originalRCTWebSocketConnect = NativeWebSocketModule.connect;
@@ -131,7 +132,11 @@ const WebSocketInterceptor = {
131132
if (isInterceptorEnabled) {
132133
return;
133134
}
134-
eventEmitter = new NativeEventEmitter(NativeWebSocketModule);
135+
eventEmitter = new NativeEventEmitter(
136+
// 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
137+
// If you want to use the native module on other platforms, please remove this condition and test its behavior
138+
Platform.OS !== 'ios' ? null : NativeWebSocketModule,
139+
);
135140
WebSocketInterceptor._registerEvents();
136141

137142
// Override `connect` method for all RCTWebSocketModule requests

0 commit comments

Comments
 (0)