mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 12:03:28 +08:00
CB-6761 Fix native->JS bridge ceasing to fire when page changes and online is set to false and the JS loads quickly
This commit is contained in:
parent
6f21a96238
commit
445ddd89fb
@ -308,23 +308,28 @@ public class NativeToJsMessageQueue {
|
|||||||
/** Uses online/offline events to tell the JS when to poll for messages. */
|
/** Uses online/offline events to tell the JS when to poll for messages. */
|
||||||
private class OnlineEventsBridgeMode extends BridgeMode {
|
private class OnlineEventsBridgeMode extends BridgeMode {
|
||||||
private boolean online;
|
private boolean online;
|
||||||
final Runnable runnable = new Runnable() {
|
private boolean ignoreNextFlush;
|
||||||
|
|
||||||
|
final Runnable toggleNetworkRunnable = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!queue.isEmpty()) {
|
if (!queue.isEmpty()) {
|
||||||
|
ignoreNextFlush = false;
|
||||||
webView.setNetworkAvailable(online);
|
webView.setNetworkAvailable(online);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@Override void reset() {
|
@Override void reset() {
|
||||||
online = false;
|
online = false;
|
||||||
|
// If the following call triggers a notifyOfFlush, then ignore it.
|
||||||
|
ignoreNextFlush = true;
|
||||||
webView.setNetworkAvailable(true);
|
webView.setNetworkAvailable(true);
|
||||||
}
|
}
|
||||||
@Override void onNativeToJsMessageAvailable() {
|
@Override void onNativeToJsMessageAvailable() {
|
||||||
cordova.getActivity().runOnUiThread(runnable);
|
cordova.getActivity().runOnUiThread(toggleNetworkRunnable);
|
||||||
}
|
}
|
||||||
// Track when online/offline events are fired so that we don't fire excess events.
|
// Track when online/offline events are fired so that we don't fire excess events.
|
||||||
@Override void notifyOfFlush(boolean fromOnlineEvent) {
|
@Override void notifyOfFlush(boolean fromOnlineEvent) {
|
||||||
if (fromOnlineEvent) {
|
if (fromOnlineEvent && !ignoreNextFlush) {
|
||||||
online = !online;
|
online = !online;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user