Skip to content

Commit

Permalink
chore: rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
luancurti committed Jan 21, 2020
1 parent a466c0f commit 5e2b479
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 96 deletions.
4 changes: 2 additions & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactnativecommunity.webview">
package="com.reactnativecommunity.wkwebview">

<application>
<provider
android:name=".RNCWebViewFileProvider"
android:name=".RNCWKWebViewFileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.reactnativecommunity.webview;
package com.reactnativecommunity.wkwebview;

import androidx.core.content.FileProvider;

Expand All @@ -7,7 +7,7 @@
* <p>
* See https://developer.android.com/guide/topics/manifest/provider-element.html for details.
*/
public class RNCWebViewFileProvider extends FileProvider {
public class RNCWKWebViewFileProvider extends FileProvider {

// This class intentionally left blank.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.reactnativecommunity.webview;
package com.reactnativecommunity.wkwebview;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
Expand Down Expand Up @@ -57,13 +57,13 @@
import com.facebook.react.uimanager.events.ContentSizeChangeEvent;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.reactnativecommunity.webview.events.TopLoadingErrorEvent;
import com.reactnativecommunity.webview.events.TopHttpErrorEvent;
import com.reactnativecommunity.webview.events.TopLoadingFinishEvent;
import com.reactnativecommunity.webview.events.TopLoadingProgressEvent;
import com.reactnativecommunity.webview.events.TopLoadingStartEvent;
import com.reactnativecommunity.webview.events.TopMessageEvent;
import com.reactnativecommunity.webview.events.TopShouldStartLoadWithRequestEvent;
import com.reactnativecommunity.wkwebview.events.TopLoadingErrorEvent;
import com.reactnativecommunity.wkwebview.events.TopHttpErrorEvent;
import com.reactnativecommunity.wkwebview.events.TopLoadingFinishEvent;
import com.reactnativecommunity.wkwebview.events.TopLoadingProgressEvent;
import com.reactnativecommunity.wkwebview.events.TopLoadingStartEvent;
import com.reactnativecommunity.wkwebview.events.TopMessageEvent;
import com.reactnativecommunity.wkwebview.events.TopShouldStartLoadWithRequestEvent;

import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -103,8 +103,8 @@
* - canGoBack - boolean, whether there is anything on a history stack to go back
* - canGoForward - boolean, whether it is possible to request GO_FORWARD command
*/
@ReactModule(name = RNCWebViewManager.REACT_CLASS)
public class RNCWebViewManager extends SimpleViewManager<WebView> {
@ReactModule(name = RNCWKWebViewManager.REACT_CLASS)
public class RNCWKWebViewManager extends SimpleViewManager<WebView> {

public static String activeUrl = null;
public static final int COMMAND_GO_BACK = 1;
Expand All @@ -121,7 +121,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
public static final int COMMAND_CLEAR_CACHE = 1001;
public static final int COMMAND_CLEAR_HISTORY = 1002;

protected static final String REACT_CLASS = "RNCWebView";
protected static final String REACT_CLASS = "RNCWKWebView";
protected static final String HTML_ENCODING = "UTF-8";
protected static final String HTML_MIME_TYPE = "text/html";
protected static final String JAVASCRIPT_INTERFACE = "ReactNativeWebView";
Expand All @@ -136,14 +136,14 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
protected @Nullable String mUserAgent = null;
protected @Nullable String mUserAgentWithApplicationName = null;

public RNCWebViewManager() {
public RNCWKWebViewManager() {
mWebViewConfig = new WebViewConfig() {
public void configWebView(WebView webView) {
}
};
}

public RNCWebViewManager(WebViewConfig webViewConfig) {
public RNCWKWebViewManager(WebViewConfig webViewConfig) {
mWebViewConfig = webViewConfig;
}

Expand All @@ -159,14 +159,14 @@ public String getName() {
return REACT_CLASS;
}

protected RNCWebView createRNCWebViewInstance(ThemedReactContext reactContext) {
return new RNCWebView(reactContext);
protected RNCWKWebview createRNCWKWebviewInstance(ThemedReactContext reactContext) {
return new RNCWKWebview(reactContext);
}

@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected WebView createViewInstance(ThemedReactContext reactContext) {
RNCWebView webView = createRNCWebViewInstance(reactContext);
RNCWKWebview webView = createRNCWKWebviewInstance(reactContext);
setupWebChromeClient(reactContext, webView);
reactContext.addLifecycleEventListener(webView);
mWebViewConfig.configWebView(webView);
Expand Down Expand Up @@ -194,7 +194,7 @@ protected WebView createViewInstance(ThemedReactContext reactContext) {

webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
RNCWebViewModule module = getModule(reactContext);
RNCWKWebViewModule module = getModule(reactContext);

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));

Expand Down Expand Up @@ -389,12 +389,12 @@ public void setSaveFormDataDisabled(WebView view, boolean disable) {

@ReactProp(name = "injectedJavaScript")
public void setInjectedJavaScript(WebView view, @Nullable String injectedJavaScript) {
((RNCWebView) view).setInjectedJavaScript(injectedJavaScript);
((RNCWKWebview) view).setInjectedJavaScript(injectedJavaScript);
}

@ReactProp(name = "messagingEnabled")
public void setMessagingEnabled(WebView view, boolean enabled) {
((RNCWebView) view).setMessagingEnabled(enabled);
((RNCWKWebview) view).setMessagingEnabled(enabled);
}

@ReactProp(name = "incognito")
Expand Down Expand Up @@ -476,7 +476,7 @@ public void setSource(WebView view, @Nullable ReadableMap source) {

@ReactProp(name = "onContentSizeChange")
public void setOnContentSizeChange(WebView view, boolean sendContentSizeChangeEvents) {
((RNCWebView) view).setSendContentSizeChangeEvents(sendContentSizeChangeEvents);
((RNCWKWebview) view).setSendContentSizeChangeEvents(sendContentSizeChangeEvents);
}

@ReactProp(name = "mixedContentMode")
Expand All @@ -496,7 +496,7 @@ public void setMixedContentMode(WebView view, @Nullable String mixedContentMode)
public void setUrlPrefixesForDefaultIntent(
WebView view,
@Nullable ReadableArray urlPrefixesForDefaultIntent) {
RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
RNCWKWebviewClient client = ((RNCWKWebview) view).getRNCWKWebviewClient();
if (client != null && urlPrefixesForDefaultIntent != null) {
client.setUrlPrefixesForDefaultIntent(urlPrefixesForDefaultIntent);
}
Expand Down Expand Up @@ -526,13 +526,13 @@ public void setGeolocationEnabled(

@ReactProp(name = "onScroll")
public void setOnScroll(WebView view, boolean hasScrollEvent) {
((RNCWebView) view).setHasScrollEvent(hasScrollEvent);
((RNCWKWebview) view).setHasScrollEvent(hasScrollEvent);
}

@Override
protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
// Do not register default touch emitter and let WebView implementation handle touches
view.setWebViewClient(new RNCWebViewClient());
view.setWebViewClient(new RNCWKWebviewClient());
}

@Override
Expand Down Expand Up @@ -583,7 +583,7 @@ public void receiveCommand(WebView root, int commandId, @Nullable ReadableArray
break;
case COMMAND_POST_MESSAGE:
try {
RNCWebView reactWebView = (RNCWebView) root;
RNCWKWebview reactWebView = (RNCWKWebview) root;
JSONObject eventInitDict = new JSONObject();
eventInitDict.put("data", args.getString(0));
reactWebView.evaluateJavascriptWithFallback("(function () {" +
Expand All @@ -602,7 +602,7 @@ public void receiveCommand(WebView root, int commandId, @Nullable ReadableArray
}
break;
case COMMAND_INJECT_JAVASCRIPT:
RNCWebView reactWebView = (RNCWebView) root;
RNCWKWebview reactWebView = (RNCWKWebview) root;
reactWebView.evaluateJavascriptWithFallback(args.getString(0));
break;
case COMMAND_LOAD_URL:
Expand Down Expand Up @@ -630,12 +630,12 @@ public void receiveCommand(WebView root, int commandId, @Nullable ReadableArray
@Override
public void onDropViewInstance(WebView webView) {
super.onDropViewInstance(webView);
((ThemedReactContext) webView.getContext()).removeLifecycleEventListener((RNCWebView) webView);
((RNCWebView) webView).cleanupCallbacksAndDestroy();
((ThemedReactContext) webView.getContext()).removeLifecycleEventListener((RNCWKWebview) webView);
((RNCWKWebview) webView).cleanupCallbacksAndDestroy();
}

public static RNCWebViewModule getModule(ReactContext reactContext) {
return reactContext.getNativeModule(RNCWebViewModule.class);
public static RNCWKWebViewModule getModule(ReactContext reactContext) {
return reactContext.getNativeModule(RNCWKWebViewModule.class);
}

protected void setupWebChromeClient(ReactContext reactContext, WebView webView) {
Expand Down Expand Up @@ -709,7 +709,7 @@ public Bitmap getDefaultVideoPoster() {
}
}

protected static class RNCWebViewClient extends WebViewClient {
protected static class RNCWKWebviewClient extends WebViewClient {

protected boolean mLastLoadFailed = false;
protected @Nullable
Expand All @@ -720,7 +720,7 @@ public void onPageFinished(WebView webView, String url) {
super.onPageFinished(webView, url);

if (!mLastLoadFailed) {
RNCWebView reactWebView = (RNCWebView) webView;
RNCWKWebview reactWebView = (RNCWKWebview) webView;

reactWebView.callInjectedJavaScript();

Expand Down Expand Up @@ -968,12 +968,12 @@ protected ViewGroup getRootView() {
* Subclass of {@link WebView} that implements {@link LifecycleEventListener} interface in order
* to call {@link WebView#destroy} on activity destroy event and also to clear the client
*/
protected static class RNCWebView extends WebView implements LifecycleEventListener {
protected static class RNCWKWebview extends WebView implements LifecycleEventListener {
protected @Nullable
String injectedJS;
protected boolean messagingEnabled = false;
protected @Nullable
RNCWebViewClient mRNCWebViewClient;
RNCWKWebviewClient mRNCWKWebviewClient;
protected boolean sendContentSizeChangeEvents = false;
private OnScrollDispatchHelper mOnScrollDispatchHelper;
protected boolean hasScrollEvent = false;
Expand All @@ -984,7 +984,7 @@ protected static class RNCWebView extends WebView implements LifecycleEventListe
* Activity Context is required for creation of dialogs internally by WebView
* Reactive Native needed for access to ReactNative internal system functionality
*/
public RNCWebView(ThemedReactContext reactContext) {
public RNCWKWebview(ThemedReactContext reactContext) {
super(reactContext);
}

Expand Down Expand Up @@ -1030,22 +1030,22 @@ protected void onSizeChanged(int w, int h, int ow, int oh) {
@Override
public void setWebViewClient(WebViewClient client) {
super.setWebViewClient(client);
if (client instanceof RNCWebViewClient) {
mRNCWebViewClient = (RNCWebViewClient) client;
if (client instanceof RNCWKWebviewClient) {
mRNCWKWebviewClient = (RNCWKWebviewClient) client;
}
}

public @Nullable
RNCWebViewClient getRNCWebViewClient() {
return mRNCWebViewClient;
RNCWKWebviewClient getRNCWKWebviewClient() {
return mRNCWKWebviewClient;
}

public void setInjectedJavaScript(@Nullable String js) {
injectedJS = js;
}

protected RNCWebViewBridge createRNCWebViewBridge(RNCWebView webView) {
return new RNCWebViewBridge(webView);
protected RNCWKWebviewBridge createRNCWKWebviewBridge(RNCWKWebview webView) {
return new RNCWKWebviewBridge(webView);
}

@SuppressLint("AddJavascriptInterface")
Expand All @@ -1057,7 +1057,7 @@ public void setMessagingEnabled(boolean enabled) {
messagingEnabled = enabled;

if (enabled) {
addJavascriptInterface(createRNCWebViewBridge(this), JAVASCRIPT_INTERFACE);
addJavascriptInterface(createRNCWKWebviewBridge(this), JAVASCRIPT_INTERFACE);
} else {
removeJavascriptInterface(JAVASCRIPT_INTERFACE);
}
Expand Down Expand Up @@ -1086,15 +1086,15 @@ public void callInjectedJavaScript() {
}

public void onMessage(String message) {
if (mRNCWebViewClient != null) {
if (mRNCWKWebviewClient != null) {
WebView webView = this;
webView.post(new Runnable() {
@Override
public void run() {
if (mRNCWebViewClient == null) {
if (mRNCWKWebviewClient == null) {
return;
}
WritableMap data = mRNCWebViewClient.createWebViewEvent(webView, webView.getUrl());
WritableMap data = mRNCWKWebviewClient.createWebViewEvent(webView, webView.getUrl());
data.putString("data", message);
dispatchEvent(webView, new TopMessageEvent(webView.getId(), data));
}
Expand Down Expand Up @@ -1139,10 +1139,10 @@ protected void cleanupCallbacksAndDestroy() {
destroy();
}

protected class RNCWebViewBridge {
RNCWebView mContext;
protected class RNCWKWebviewBridge {
RNCWKWebview mContext;

RNCWebViewBridge(RNCWebView c) {
RNCWKWebviewBridge(RNCWKWebview c) {
mContext = c;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.reactnativecommunity.webview;
package com.reactnativecommunity.wkwebview;

import android.Manifest;
import android.app.Activity;
Expand Down Expand Up @@ -35,9 +35,9 @@

import static android.app.Activity.RESULT_OK;

@ReactModule(name = RNCWebViewModule.MODULE_NAME)
public class RNCWebViewModule extends ReactContextBaseJavaModule implements ActivityEventListener {
public static final String MODULE_NAME = "RNCWebView";
@ReactModule(name = RNCWKWebViewModule.MODULE_NAME)
public class RNCWKWebViewModule extends ReactContextBaseJavaModule implements ActivityEventListener {
public static final String MODULE_NAME = "RNCWKWebView";
private static final int PICKER = 1;
private static final int PICKER_LEGACY = 3;
private static final int FILE_DOWNLOAD_PERMISSION_REQUEST = 1;
Expand Down Expand Up @@ -66,7 +66,7 @@ public boolean onRequestPermissionsResult(int requestCode, String[] permissions,
}
};

public RNCWebViewModule(ReactApplicationContext reactContext) {
public RNCWKWebViewModule(ReactApplicationContext reactContext) {
super(reactContext);
reactContext.addActivityEventListener(this);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ public void startPhotoPickerIntent(ValueCallback<Uri> filePathCallback, String a
if (chooserIntent.resolveActivity(getCurrentActivity().getPackageManager()) != null) {
getCurrentActivity().startActivityForResult(chooserIntent, PICKER_LEGACY);
} else {
Log.w("RNCWebViewModule", "there is no Activity to handle this Intent");
Log.w("RNCWKWebViewModule", "there is no Activity to handle this Intent");
}
}

Expand All @@ -196,7 +196,7 @@ public boolean startPhotoPickerIntent(final ValueCallback<Uri[]> callback, final
if (chooserIntent.resolveActivity(getCurrentActivity().getPackageManager()) != null) {
getCurrentActivity().startActivityForResult(chooserIntent, PICKER);
} else {
Log.w("RNCWebViewModule", "there is no Activity to handle this Intent");
Log.w("RNCWKWebViewModule", "there is no Activity to handle this Intent");
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.reactnativecommunity.webview;
package com.reactnativecommunity.wkwebview;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
Expand All @@ -9,19 +9,14 @@
import java.util.Collections;
import java.util.List;

public class RNCWebViewPackage implements ReactPackage {
public class RNCWKWebViewPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Collections.singletonList(new RNCWebViewModule(reactContext));
}

// Deprecated from RN 0.47
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
return Collections.singletonList(new RNCWKWebViewModule(reactContext));
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.singletonList(new RNCWebViewManager());
return Collections.singletonList(new RNCWKWebViewManager());
}
}
Loading

0 comments on commit 5e2b479

Please sign in to comment.