From ba8f88d1abf6b9edacc79c64396404a070c128a0 Mon Sep 17 00:00:00 2001 From: Christoph Nakazawa Date: Thu, 18 Jul 2019 02:59:15 -0700 Subject: [PATCH] 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 --- .flowconfig | 2 +- .flowconfig.android | 2 +- Libraries/Utilities/HMRClient.js | 10 +++--- Libraries/Utilities/HMRLoadingView.android.js | 36 ------------------- Libraries/Utilities/LoadingView.android.js | 29 +++++++++++++++ ...RLoadingView.ios.js => LoadingView.ios.js} | 23 +++++------- .../{HMRLoadingView.js => LoadingView.js} | 15 +++----- template/_flowconfig | 2 +- 8 files changed, 50 insertions(+), 69 deletions(-) delete mode 100644 Libraries/Utilities/HMRLoadingView.android.js create mode 100644 Libraries/Utilities/LoadingView.android.js rename Libraries/Utilities/{HMRLoadingView.ios.js => LoadingView.ios.js} (61%) rename Libraries/Utilities/{HMRLoadingView.js => LoadingView.js} (61%) diff --git a/.flowconfig b/.flowconfig index d8118f2843..941b687d53 100644 --- a/.flowconfig +++ b/.flowconfig @@ -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/.*/.* diff --git a/.flowconfig.android b/.flowconfig.android index 1e6b97df04..740ddfebe3 100644 --- a/.flowconfig.android +++ b/.flowconfig.android @@ -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/.*/.* diff --git a/Libraries/Utilities/HMRClient.js b/Libraries/Utilities/HMRClient.js index 2574897a57..ca3f38e06d 100644 --- a/Libraries/Utilities/HMRClient.js +++ b/Libraries/Utilities/HMRClient.js @@ -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`); @@ -172,7 +172,7 @@ Error: ${e.message}`; client.on('update-start', () => { if (isFastRefreshActive()) { - HMRLoadingView.showMessage('Refreshing...'); + LoadingView.showMessage('Refreshing...'); } }); @@ -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(); @@ -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.', ); diff --git a/Libraries/Utilities/HMRLoadingView.android.js b/Libraries/Utilities/HMRLoadingView.android.js deleted file mode 100644 index 9daf8e2e44..0000000000 --- a/Libraries/Utilities/HMRLoadingView.android.js +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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'; - -const ToastAndroid = require('../Components/ToastAndroid/ToastAndroid'); - -const TOAST_SHORT_DELAY = 2000; - -class HMRLoadingView { - static _showing: boolean; - - static showMessage(message: string) { - if (HMRLoadingView._showing) { - return; - } - ToastAndroid.show(message, ToastAndroid.SHORT); - HMRLoadingView._showing = true; - setTimeout(() => { - HMRLoadingView._showing = false; - }, TOAST_SHORT_DELAY); - } - - static hide() { - // noop - } -} - -module.exports = HMRLoadingView; diff --git a/Libraries/Utilities/LoadingView.android.js b/Libraries/Utilities/LoadingView.android.js new file mode 100644 index 0000000000..04fc973c31 --- /dev/null +++ b/Libraries/Utilities/LoadingView.android.js @@ -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() {}, +}; diff --git a/Libraries/Utilities/HMRLoadingView.ios.js b/Libraries/Utilities/LoadingView.ios.js similarity index 61% rename from Libraries/Utilities/HMRLoadingView.ios.js rename to Libraries/Utilities/LoadingView.ios.js index 17d20d2db8..caf499aa4d 100644 --- a/Libraries/Utilities/HMRLoadingView.ios.js +++ b/Libraries/Utilities/LoadingView.ios.js @@ -10,12 +10,12 @@ '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. @@ -23,13 +23,8 @@ class HMRLoadingView { processColor('#2584e8'), ); } - } - - static hide() { - if (NativeDevLoadingView != null) { - NativeDevLoadingView.hide(); - } - } -} - -module.exports = HMRLoadingView; + }, + hide() { + NativeDevLoadingView && NativeDevLoadingView.hide(); + }, +}; diff --git a/Libraries/Utilities/HMRLoadingView.js b/Libraries/Utilities/LoadingView.js similarity index 61% rename from Libraries/Utilities/HMRLoadingView.js rename to Libraries/Utilities/LoadingView.js index 13eaa4bb8f..cc14be3be6 100644 --- a/Libraries/Utilities/HMRLoadingView.js +++ b/Libraries/Utilities/LoadingView.js @@ -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() {}, +}; diff --git a/template/_flowconfig b/template/_flowconfig index 01efd9b17b..6857dfab19 100644 --- a/template/_flowconfig +++ b/template/_flowconfig @@ -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/.*/.*