Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Libraries/BugReporting/BugReporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const RCTDeviceEventEmitter = require('../EventEmitter/RCTDeviceEventEmitter');
const infoLog = require('../Utilities/infoLog');

import type EmitterSubscription from '../vendor/emitter/EmitterSubscription';
import NativeRedBox from '../NativeModules/specs/NativeRedBox';

type ExtraData = {[key: string]: string};
type SourceCallback = () => string;
Expand Down Expand Up @@ -127,10 +128,9 @@ class BugReporting {
BugReportingNativeModule.setExtraData &&
BugReportingNativeModule.setExtraData(extraData, fileData);

const RedBoxNativeModule = require('../BatchedBridge/NativeModules').RedBox;
RedBoxNativeModule &&
RedBoxNativeModule.setExtraData &&
RedBoxNativeModule.setExtraData(extraData, 'From BugReporting.js');
if (NativeRedBox != null && NativeRedBox.setExtraData != null) {
NativeRedBox.setExtraData(extraData, 'From BugReporting.js');
}

return {extras: extraData, files: fileData};
}
Expand Down
24 changes: 24 additions & 0 deletions Libraries/NativeModules/specs/NativeRedBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/

'use strict';

import type {TurboModule} from 'RCTExport';
import * as TurboModuleRegistry from 'TurboModuleRegistry';
import {Platform} from 'react-native';

export interface Spec extends TurboModule {
+setExtraData: (extraData: Object, identifier: string) => void;
+dismiss: () => void;
}

export default (Platform.OS === 'ios'
? TurboModuleRegistry.getEnforcing<Spec>('RedBox')
: null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use undefined here instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm good question, I didn't see anything about using it specifically. But it would be nice to have a consensus.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw some of the specific platforms PRs using undefined and others using null.
I don't have a strong opinion on that, but my preference is to go with undefined what denotes that this Native Module "was not defined" for this platform.

Anyway, I can update my PRs if we decide to go with null.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should actually be using get not get enforcing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll update it before I import/land to FB

11 changes: 8 additions & 3 deletions Libraries/Utilities/HMRClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const invariant = require('invariant');

const MetroHMRClient = require('metro/src/lib/bundle-modules/HMRClient');

import NativeRedBox from '../NativeModules/specs/NativeRedBox';

/**
* HMR Client that receives from the server HMR updates and propagates them
* runtime to reflects those changes.
Expand Down Expand Up @@ -72,9 +74,12 @@ Error: ${e.message}`;
});

hmrClient.on('update', () => {
if (Platform.OS === 'ios') {
const RCTRedBox = require('../BatchedBridge/NativeModules').RedBox;
RCTRedBox && RCTRedBox.dismiss && RCTRedBox.dismiss();
if (
Platform.OS === 'ios' &&
NativeRedBox != null &&
NativeRedBox.dismiss != null
) {
NativeRedBox.dismiss();
} else {
const RCTExceptionsManager = require('../BatchedBridge/NativeModules')
.ExceptionsManager;
Expand Down