Skip to content

Commit 068a208

Browse files
Adding native implementation for Dev Loading View for Android (#35743)
Summary: Pull Request resolved: #35743 Changelog: [Android][Added] - For supporting Dev Loading View across multiple platforms, altering the javascript implementation of Loading view of android to also rely on native implementation as iOS instead of Toast, thereby unifying both platforms Reviewed By: rshest Differential Revision: D42258041 fbshipit-source-id: 1be56c1e5696b1024ba09a0aa11da96e0a08f210
1 parent afd954e commit 068a208

File tree

3 files changed

+104
-11
lines changed

3 files changed

+104
-11
lines changed

Libraries/Utilities/LoadingView.android.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,43 @@
88
* @flow strict-local
99
*/
1010

11-
import ToastAndroid from '../Components/ToastAndroid/ToastAndroid';
12-
13-
const TOAST_SHORT_DELAY = 2000;
14-
let isVisible = false;
11+
import processColor from '../StyleSheet/processColor';
12+
import Appearance from './Appearance';
13+
import NativeDevLoadingView from './NativeDevLoadingView';
1514

1615
module.exports = {
1716
showMessage(message: string, type: 'load' | 'refresh') {
18-
if (!isVisible) {
19-
ToastAndroid.show(message, ToastAndroid.SHORT);
20-
isVisible = true;
21-
setTimeout(() => {
22-
isVisible = false;
23-
}, TOAST_SHORT_DELAY);
17+
if (NativeDevLoadingView) {
18+
if (type === 'refresh') {
19+
const backgroundColor = processColor('#2584e8');
20+
const textColor = processColor('#ffffff');
21+
22+
NativeDevLoadingView.showMessage(
23+
message,
24+
typeof textColor === 'number' ? textColor : null,
25+
typeof backgroundColor === 'number' ? backgroundColor : null,
26+
);
27+
} else if (type === 'load') {
28+
let backgroundColor;
29+
let textColor;
30+
31+
if (Appearance.getColorScheme() === 'dark') {
32+
backgroundColor = processColor('#fafafa');
33+
textColor = processColor('#242526');
34+
} else {
35+
backgroundColor = processColor('#404040');
36+
textColor = processColor('#ffffff');
37+
}
38+
39+
NativeDevLoadingView.showMessage(
40+
message,
41+
typeof textColor === 'number' ? textColor : null,
42+
typeof backgroundColor === 'number' ? backgroundColor : null,
43+
);
44+
}
2445
}
2546
},
26-
hide() {},
47+
hide() {
48+
NativeDevLoadingView && NativeDevLoadingView.hide();
49+
},
2750
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_root_target", "react_native_target", "rn_android_library")
2+
3+
rn_android_library(
4+
name = "devloading",
5+
srcs = glob(["**/*.java"]),
6+
autoglob = False,
7+
labels = [
8+
"pfh:ReactNative_CommonInfrastructurePlaceholder",
9+
],
10+
language = "JAVA",
11+
visibility = [
12+
"PUBLIC",
13+
],
14+
deps = [
15+
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
16+
react_native_dep("third-party/java/jsr-305:jsr-305"),
17+
react_native_target("java/com/facebook/react/bridge:bridge"),
18+
react_native_target("java/com/facebook/react/common:common"),
19+
react_native_target("java/com/facebook/react/module/annotations:annotations"),
20+
],
21+
exported_deps = [react_native_root_target(":FBReactNativeSpec")],
22+
)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and 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+
8+
package com.facebook.react.modules.devloading;
9+
10+
import android.util.Log;
11+
import com.facebook.fbreact.specs.NativeDevLoadingViewSpec;
12+
import com.facebook.react.bridge.NativeModule;
13+
import com.facebook.react.bridge.ReactApplicationContext;
14+
import com.facebook.react.bridge.UiThreadUtil;
15+
import com.facebook.react.module.annotations.ReactModule;
16+
17+
/** {@link NativeModule} that allows JS to show dev loading view. */
18+
@ReactModule(name = NativeDevLoadingViewSpec.NAME)
19+
public class DevLoadingModule extends NativeDevLoadingViewSpec {
20+
21+
public DevLoadingModule(ReactApplicationContext reactContext) {
22+
super(reactContext);
23+
}
24+
25+
@Override
26+
public void showMessage(final String message, final Double color, final Double backgroundColor) {
27+
28+
UiThreadUtil.runOnUiThread(
29+
new Runnable() {
30+
@Override
31+
public void run() {
32+
Log.w(NAME, "Showing Message in DevLoadingModule java.");
33+
}
34+
});
35+
}
36+
37+
@Override
38+
public void hide() {
39+
40+
UiThreadUtil.runOnUiThread(
41+
new Runnable() {
42+
@Override
43+
public void run() {
44+
Log.w(NAME, "Hiding Message in DevLoadingModule java.");
45+
}
46+
});
47+
}
48+
}

0 commit comments

Comments
 (0)