Skip to content

Commit

Permalink
Rename HMRLoadingView to LoadingView
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cpojer authored and facebook-github-bot committed Jul 18, 2019
1 parent 93bebf1 commit ba8f88d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
.*/node_modules/warning/.*

; Flow doesn't support platforms
.*/Libraries/Utilities/HMRLoadingView.js
.*/Libraries/Utilities/LoadingView.js

[untyped]
.*/node_modules/@react-native-community/cli/.*/.*
Expand Down
2 changes: 1 addition & 1 deletion .flowconfig.android
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
.*/node_modules/warning/.*

; Flow doesn't support platforms
.*/Libraries/Utilities/HMRLoadingView.js
.*/Libraries/Utilities/LoadingView.js

[untyped]
.*/node_modules/@react-native-community/cli/.*/.*
Expand Down
10 changes: 5 additions & 5 deletions Libraries/Utilities/HMRClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const HMRClient: HMRClientNativeInterface = {
invariant(!hmrClient, 'Cannot initialize hmrClient twice');

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

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

client.on('update-start', () => {
if (isFastRefreshActive()) {
HMRLoadingView.showMessage('Refreshing...');
LoadingView.showMessage('Refreshing...');
}
});

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

client.on('update-done', () => {
HMRLoadingView.hide();
LoadingView.hide();
});

client.on('error', data => {
HMRLoadingView.hide();
LoadingView.hide();

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

client.on('close', data => {
HMRLoadingView.hide();
LoadingView.hide();
setHMRUnavailableReason(
'Disconnected from the Metro server. Fast Refresh will be disabled until you reload the application.',
);
Expand Down
36 changes: 0 additions & 36 deletions Libraries/Utilities/HMRLoadingView.android.js

This file was deleted.

29 changes: 29 additions & 0 deletions Libraries/Utilities/LoadingView.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 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.
*
* @format
* @flow
*/

'use strict';

import ToastAndroid from '../Components/ToastAndroid/ToastAndroid';

const TOAST_SHORT_DELAY = 2000;
let isVisible = false;

module.exports = {
showMessage(message: string) {
if (!isVisible) {
ToastAndroid.show(message, ToastAndroid.SHORT);
isVisible = true;
setTimeout(() => {
isVisible = false;
}, TOAST_SHORT_DELAY);
}
},
hide() {},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,21 @@

'use strict';

const processColor = require('../StyleSheet/processColor');
import processColor from '../StyleSheet/processColor';
import NativeDevLoadingView from './NativeDevLoadingView';

class HMRLoadingView {
static showMessage(message: string) {
if (NativeDevLoadingView != null) {
module.exports = {
showMessage(message: string) {
if (NativeDevLoadingView) {
NativeDevLoadingView.showMessage(
message,
// Use same colors as iOS "Personal Hotspot" bar.
processColor('#ffffff'),
processColor('#2584e8'),
);
}
}

static hide() {
if (NativeDevLoadingView != null) {
NativeDevLoadingView.hide();
}
}
}

module.exports = HMRLoadingView;
},
hide() {
NativeDevLoadingView && NativeDevLoadingView.hide();
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@

'use strict';

class HMRLoadingView {
static showMessage(message: string) {
// noop
}

static hide() {
// noop
}
}

module.exports = HMRLoadingView;
module.exports = {
showMessage(message: string) {},
hide() {},
};
2 changes: 1 addition & 1 deletion template/_flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ node_modules/react-native/Libraries/polyfills/.*
node_modules/warning/.*

; Flow doesn't support platforms
.*/Libraries/Utilities/HMRLoadingView.js
.*/Libraries/Utilities/LoadingView.js

[untyped]
.*/node_modules/@react-native-community/cli/.*/.*
Expand Down

0 comments on commit ba8f88d

Please sign in to comment.