Skip to content

Commit ba8f88d

Browse files
cpojerfacebook-github-bot
authored andcommitted
Rename HMRLoadingView to LoadingView
Summary: This view will be re-used for bundle splitting so I'm changing the name to be more generic as it can be used for informing users of any loading activity. I also cleaned up the files a bit from a class to just an object. Reviewed By: gaearon Differential Revision: D16281367 fbshipit-source-id: 5c2ee7790d29ccba473bd6e90737d2f0581e6291
1 parent 93bebf1 commit ba8f88d

File tree

8 files changed

+50
-69
lines changed

8 files changed

+50
-69
lines changed

.flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
.*/node_modules/warning/.*
2020

2121
; Flow doesn't support platforms
22-
.*/Libraries/Utilities/HMRLoadingView.js
22+
.*/Libraries/Utilities/LoadingView.js
2323

2424
[untyped]
2525
.*/node_modules/@react-native-community/cli/.*/.*

.flowconfig.android

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
.*/node_modules/warning/.*
2020

2121
; Flow doesn't support platforms
22-
.*/Libraries/Utilities/HMRLoadingView.js
22+
.*/Libraries/Utilities/LoadingView.js
2323

2424
[untyped]
2525
.*/node_modules/@react-native-community/cli/.*/.*

Libraries/Utilities/HMRClient.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const HMRClient: HMRClientNativeInterface = {
107107
invariant(!hmrClient, 'Cannot initialize hmrClient twice');
108108

109109
// Moving to top gives errors due to NativeModules not being initialized
110-
const HMRLoadingView = require('./HMRLoadingView');
110+
const LoadingView = require('./LoadingView');
111111

112112
const wsHost = port !== null && port !== '' ? `${host}:${port}` : host;
113113
const client = new MetroHMRClient(`ws://${wsHost}/hot`);
@@ -172,7 +172,7 @@ Error: ${e.message}`;
172172

173173
client.on('update-start', () => {
174174
if (isFastRefreshActive()) {
175-
HMRLoadingView.showMessage('Refreshing...');
175+
LoadingView.showMessage('Refreshing...');
176176
}
177177
});
178178

@@ -183,11 +183,11 @@ Error: ${e.message}`;
183183
});
184184

185185
client.on('update-done', () => {
186-
HMRLoadingView.hide();
186+
LoadingView.hide();
187187
});
188188

189189
client.on('error', data => {
190-
HMRLoadingView.hide();
190+
LoadingView.hide();
191191

192192
if (data.type === 'GraphNotFoundError') {
193193
client.disable();
@@ -212,7 +212,7 @@ Error: ${e.message}`;
212212
});
213213

214214
client.on('close', data => {
215-
HMRLoadingView.hide();
215+
LoadingView.hide();
216216
setHMRUnavailableReason(
217217
'Disconnected from the Metro server. Fast Refresh will be disabled until you reload the application.',
218218
);

Libraries/Utilities/HMRLoadingView.android.js

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
'use strict';
12+
13+
import ToastAndroid from '../Components/ToastAndroid/ToastAndroid';
14+
15+
const TOAST_SHORT_DELAY = 2000;
16+
let isVisible = false;
17+
18+
module.exports = {
19+
showMessage(message: string) {
20+
if (!isVisible) {
21+
ToastAndroid.show(message, ToastAndroid.SHORT);
22+
isVisible = true;
23+
setTimeout(() => {
24+
isVisible = false;
25+
}, TOAST_SHORT_DELAY);
26+
}
27+
},
28+
hide() {},
29+
};

Libraries/Utilities/HMRLoadingView.ios.js renamed to Libraries/Utilities/LoadingView.ios.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,21 @@
1010

1111
'use strict';
1212

13-
const processColor = require('../StyleSheet/processColor');
13+
import processColor from '../StyleSheet/processColor';
1414
import NativeDevLoadingView from './NativeDevLoadingView';
1515

16-
class HMRLoadingView {
17-
static showMessage(message: string) {
18-
if (NativeDevLoadingView != null) {
16+
module.exports = {
17+
showMessage(message: string) {
18+
if (NativeDevLoadingView) {
1919
NativeDevLoadingView.showMessage(
2020
message,
2121
// Use same colors as iOS "Personal Hotspot" bar.
2222
processColor('#ffffff'),
2323
processColor('#2584e8'),
2424
);
2525
}
26-
}
27-
28-
static hide() {
29-
if (NativeDevLoadingView != null) {
30-
NativeDevLoadingView.hide();
31-
}
32-
}
33-
}
34-
35-
module.exports = HMRLoadingView;
26+
},
27+
hide() {
28+
NativeDevLoadingView && NativeDevLoadingView.hide();
29+
},
30+
};

Libraries/Utilities/HMRLoadingView.js renamed to Libraries/Utilities/LoadingView.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@
1010

1111
'use strict';
1212

13-
class HMRLoadingView {
14-
static showMessage(message: string) {
15-
// noop
16-
}
17-
18-
static hide() {
19-
// noop
20-
}
21-
}
22-
23-
module.exports = HMRLoadingView;
13+
module.exports = {
14+
showMessage(message: string) {},
15+
hide() {},
16+
};

template/_flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ node_modules/react-native/Libraries/polyfills/.*
1313
node_modules/warning/.*
1414

1515
; Flow doesn't support platforms
16-
.*/Libraries/Utilities/HMRLoadingView.js
16+
.*/Libraries/Utilities/LoadingView.js
1717

1818
[untyped]
1919
.*/node_modules/@react-native-community/cli/.*/.*

0 commit comments

Comments
 (0)