You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary:
This diff adds a new `unstable_enableLogBox` function to opt-into the new LogBox experience. If LogBox is not enabled early enough, we show an error with instructions.
With this, LogBox can be enabled with:
```
require('react-native').unstable_enableLogBox();
```
Changelog: [General] [Adds] unstable_enableLogBox
Reviewed By: zackargyle, rubennorte
Differential Revision: D18808940
fbshipit-source-id: 4b0234ddc4d1646515bf63110d5b02133780512e
// in order to access the component stacks appended by React DevTools.
55
53
const{error, warn}=console;
56
54
leterrorImpl=error;
57
55
letwarnImpl=warn;
56
+
let_isLogBoxEnabled=false;
57
+
let_isInstalled=false;
58
58
(console: any).error=function(...args){
59
59
errorImpl(...args);
60
60
};
@@ -70,6 +70,11 @@ if (__DEV__) {
70
70
}
71
71
72
72
staticinstall(): void{
73
+
_isInstalled =true;
74
+
if(_isLogBoxEnabled){
75
+
LogBox.install();
76
+
return;
77
+
}
73
78
errorImpl=function(...args){
74
79
error.call(console, ...args);
75
80
// Show YellowBox for the `warning` module.
@@ -102,46 +107,39 @@ if (__DEV__) {
102
107
}
103
108
104
109
staticuninstall(): void{
110
+
if(_isLogBoxEnabled){
111
+
LogBox.uninstall();
112
+
return;
113
+
}
114
+
_isInstalled=false;
105
115
errorImpl=error;
106
116
warnImpl=warn;
107
117
delete(console: any).disableYellowBox;
108
118
}
109
119
110
-
_subscription: ?Subscription;
111
-
112
-
state={
113
-
registry: null,
114
-
};
120
+
static__unstable_enableLogBox(): void{
121
+
if(_isInstalled){
122
+
thrownewError(
123
+
'LogBox must be enabled before AppContainer is required so that it can properly wrap the console methods.\n\nPlease enable LogBox earlier in your app.\n\n',
124
+
);
125
+
}
126
+
_isLogBoxEnabled=true;
115
127
116
-
render(): React.Node{
117
-
// TODO: Ignore warnings that fire when rendering `YellowBox` itself.
118
-
returnthis.state.registry==null ? null : (
119
-
<YellowBoxList
120
-
onDismiss={this._handleDismiss}
121
-
onDismissAll={this._handleDismissAll}
122
-
registry={this.state.registry}
123
-
/>
124
-
);
128
+
// TODO: Temporary hack to prevent cycles with the ExceptionManager.
'LogBox must be enabled before AppContainer is required so that it can properly wrap the console methods.\n\nPlease enable LogBox earlier in your app.\n\n',
114
+
);
115
+
});
116
+
117
+
it('should render YellowBoxContainer by default',()=>{
118
+
constoutput=render.shallowRender(<YellowBox/>);
119
+
120
+
expect(output).toMatchSnapshot();
121
+
});
122
+
123
+
it('should render LogBoxNotificationContainer when LogBox is enabled',()=>{
0 commit comments