Skip to content

Commit

Permalink
[RN Mobile] Ube cannot view or interact with the classic block on jet…
Browse files Browse the repository at this point in the history
…pack sites (#26168)
  • Loading branch information
marecar3 authored and ceyhun committed Oct 16, 2020
1 parent 5db9883 commit e1cbcf7
Showing 1 changed file with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand Down Expand Up @@ -48,6 +49,23 @@ public class GutenbergWebViewActivity extends AppCompatActivity {
private boolean mIsGutenbergReady;
private AtomicBoolean mIsWebPageLoaded = new AtomicBoolean(false);
private AtomicBoolean mIsBlockContentInserted = new AtomicBoolean(false);
private final Handler mWebPageLoadedHandler = new Handler();
private final Runnable mWebPageLoadedRunnable = new Runnable() {
@Override public void run() {
if (!mIsWebPageLoaded.getAndSet(true)) {
mProgressBar.setVisibility(View.GONE);
// We want to insert block content
// only if gutenberg is ready
if (mIsGutenbergReady) {
final Handler handler = new Handler();
handler.postDelayed(() -> {
// Insert block content
insertBlockScript();
}, 200);
}
}
}
};

@SuppressLint("SetJavaScriptEnabled")
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -77,21 +95,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
if (progress == 100 && !mIsWebPageLoaded.getAndSet(true)) {
// We want to insert block content
// only if gutenberg is ready
if (mIsGutenbergReady) {
mProgressBar.setVisibility(View.GONE);
final Handler handler = new Handler();
handler.postDelayed(() -> {
// Insert block content
insertBlockScript();
}, 200);
}
}
else {
if (progress < 100) {
mIsWebPageLoaded.compareAndSet(true, false);
if (progress == 100) {
mWebPageLoadedHandler.removeCallbacks(mWebPageLoadedRunnable);
mWebPageLoadedHandler.postDelayed(mWebPageLoadedRunnable, 1500);
} else {
mIsWebPageLoaded.compareAndSet(true, false);
if (mProgressBar.getVisibility() == View.GONE) {
mProgressBar.setVisibility(View.VISIBLE);
}
mProgressBar.setProgress(progress);
}
Expand Down Expand Up @@ -351,6 +361,12 @@ public void finish() {
super.finish();
}

@Override
protected void onDestroy() {
mWebPageLoadedHandler.removeCallbacks(mWebPageLoadedRunnable);
super.onDestroy();
}

public class WPWebKit {
@JavascriptInterface
public void postMessage(String content) {
Expand Down

0 comments on commit e1cbcf7

Please sign in to comment.