Skip to content

Commit

Permalink
Changing the Loading View of Android to rely on the native implementa…
Browse files Browse the repository at this point in the history
…tion instead of Toast

Summary:
Changelog:
[Android][Added] - For supporting Dev Loading View across multiple platforms, changing the Loading View of Android to rely on the native implementation instead of Toast while keeping backwards comptability.

Reviewed By: rshest

Differential Revision: D42286466

fbshipit-source-id: 3f9ca35d2a22a91e2d0f21e1025087235f3f584d
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Jan 4, 2023
1 parent 0c53420 commit 82bb3fb
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions Libraries/Utilities/LoadingView.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,46 @@
*/

import ToastAndroid from '../Components/ToastAndroid/ToastAndroid';
import processColor from '../StyleSheet/processColor';
import Appearance from './Appearance';
import NativeDevLoadingView from './NativeDevLoadingView';

const TOAST_SHORT_DELAY = 2000;
let isVisible = false;

module.exports = {
showMessage(message: string, type: 'load' | 'refresh') {
if (!isVisible) {
if (NativeDevLoadingView) {
let backgroundColor;
let textColor;

if (type === 'refresh') {
backgroundColor = processColor('#2584e8');
textColor = processColor('#ffffff');
} else if (type === 'load') {
if (Appearance.getColorScheme() === 'dark') {
backgroundColor = processColor('#fafafa');
textColor = processColor('#242526');
} else {
backgroundColor = processColor('#404040');
textColor = processColor('#ffffff');
}
}

NativeDevLoadingView.showMessage(
message,
typeof textColor === 'number' ? textColor : null,
typeof backgroundColor === 'number' ? backgroundColor : null,
);
} else if (!isVisible) {
ToastAndroid.show(message, ToastAndroid.SHORT);
isVisible = true;
setTimeout(() => {
isVisible = false;
}, TOAST_SHORT_DELAY);
}
},
hide() {},
hide() {
NativeDevLoadingView && NativeDevLoadingView.hide();
},
};

0 comments on commit 82bb3fb

Please sign in to comment.