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 (#35773)

Summary:
Pull Request resolved: #35773

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: 38749cdbc11208b81a6199467bac00cbc1850c92
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Jan 4, 2023
1 parent f70a2f6 commit 9f6b532
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 9f6b532

Please sign in to comment.