WIP: WebView extraction - Rename android from RNC to RCT

This commit is contained in:
Jamon Holmgren 2018-09-08 17:01:05 -07:00
parent 922151ec42
commit 642620dd98
6 changed files with 37 additions and 41 deletions

View File

@ -45,10 +45,6 @@ Additional properties are supported and will be added here; for now, refer to th
Simply install React Native WebView and then use it in place of the core WebView. Their APIs are currently identical.
## Contributing
_Guide coming soon_
### Contributor Notes
* I've removed all PropTypes for now. Instead, we'll be moving toward Flow or TypeScript at some later date

View File

@ -83,10 +83,10 @@ import org.json.JSONObject;
* - 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 = RCTWebViewManager.REACT_CLASS)
public class RCTWebViewManager extends SimpleViewManager<WebView> {
protected static final String REACT_CLASS = "RNCWebView";
protected static final String REACT_CLASS = "RCTWebView";
protected static final String HTML_ENCODING = "UTF-8";
protected static final String HTML_MIME_TYPE = "text/html";
@ -108,7 +108,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
protected WebViewConfig mWebViewConfig;
protected @Nullable WebView.PictureListener mPictureListener;
protected static class RNCWebViewClient extends WebViewClient {
protected static class RCTWebViewClient extends WebViewClient {
protected boolean mLastLoadFailed = false;
protected @Nullable ReadableArray mUrlPrefixesForDefaultIntent;
@ -119,7 +119,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
super.onPageFinished(webView, url);
if (!mLastLoadFailed) {
RNCWebView reactWebView = (RNCWebView) webView;
RCTWebView reactWebView = (RCTWebView) webView;
reactWebView.callInjectedJavaScript();
reactWebView.linkBridge();
emitFinishEvent(webView, url);
@ -242,15 +242,15 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
* 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 RCTWebView extends WebView implements LifecycleEventListener {
protected @Nullable String injectedJS;
protected boolean messagingEnabled = false;
protected @Nullable RNCWebViewClient mRNCWebViewClient;
protected @Nullable RCTWebViewClient mRCTWebViewClient;
protected class RNCWebViewBridge {
RNCWebView mContext;
protected class RCTWebViewBridge {
RCTWebView mContext;
RNCWebViewBridge(RNCWebView c) {
RCTWebViewBridge(RCTWebView c) {
mContext = c;
}
@ -267,7 +267,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
* Reactive Native needed for access to ReactNative internal system functionality
*
*/
public RNCWebView(ThemedReactContext reactContext) {
public RCTWebView(ThemedReactContext reactContext) {
super(reactContext);
}
@ -289,19 +289,19 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@Override
public void setWebViewClient(WebViewClient client) {
super.setWebViewClient(client);
mRNCWebViewClient = (RNCWebViewClient)client;
mRCTWebViewClient = (RCTWebViewClient)client;
}
public @Nullable RNCWebViewClient getRNCWebViewClient() {
return mRNCWebViewClient;
public @Nullable RCTWebViewClient getRCTWebViewClient() {
return mRCTWebViewClient;
}
public void setInjectedJavaScript(@Nullable String js) {
injectedJS = js;
}
protected RNCWebViewBridge createRNCWebViewBridge(RNCWebView webView) {
return new RNCWebViewBridge(webView);
protected RCTWebViewBridge createRCTWebViewBridge(RCTWebView webView) {
return new RCTWebViewBridge(webView);
}
public void setMessagingEnabled(boolean enabled) {
@ -311,7 +311,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
messagingEnabled = enabled;
if (enabled) {
addJavascriptInterface(createRNCWebViewBridge(this), BRIDGE_NAME);
addJavascriptInterface(createRCTWebViewBridge(this), BRIDGE_NAME);
linkBridge();
} else {
removeJavascriptInterface(BRIDGE_NAME);
@ -360,14 +360,14 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
}
}
public RNCWebViewManager() {
public RCTWebViewManager() {
mWebViewConfig = new WebViewConfig() {
public void configWebView(WebView webView) {
}
};
}
public RNCWebViewManager(WebViewConfig webViewConfig) {
public RCTWebViewManager(WebViewConfig webViewConfig) {
mWebViewConfig = webViewConfig;
}
@ -376,14 +376,14 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
return REACT_CLASS;
}
protected RNCWebView createRNCWebViewInstance(ThemedReactContext reactContext) {
return new RNCWebView(reactContext);
protected RCTWebView createRCTWebViewInstance(ThemedReactContext reactContext) {
return new RCTWebView(reactContext);
}
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected WebView createViewInstance(ThemedReactContext reactContext) {
RNCWebView webView = createRNCWebViewInstance(reactContext);
RCTWebView webView = createRCTWebViewInstance(reactContext);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onConsoleMessage(ConsoleMessage message) {
@ -474,12 +474,12 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@ReactProp(name = "injectedJavaScript")
public void setInjectedJavaScript(WebView view, @Nullable String injectedJavaScript) {
((RNCWebView) view).setInjectedJavaScript(injectedJavaScript);
((RCTWebView) view).setInjectedJavaScript(injectedJavaScript);
}
@ReactProp(name = "messagingEnabled")
public void setMessagingEnabled(WebView view, boolean enabled) {
((RNCWebView) view).setMessagingEnabled(enabled);
((RCTWebView) view).setMessagingEnabled(enabled);
}
@ReactProp(name = "source")
@ -568,7 +568,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
public void setUrlPrefixesForDefaultIntent(
WebView view,
@Nullable ReadableArray urlPrefixesForDefaultIntent) {
RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
RCTWebViewClient client = ((RCTWebView) view).getRCTWebViewClient();
if (client != null && urlPrefixesForDefaultIntent != null) {
client.setUrlPrefixesForDefaultIntent(urlPrefixesForDefaultIntent);
}
@ -585,7 +585,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
public void setOriginWhitelist(
WebView view,
@Nullable ReadableArray originWhitelist) {
RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
RCTWebViewClient client = ((RCTWebView) view).getRCTWebViewClient();
if (client != null && originWhitelist != null) {
List<Pattern> whiteList = new LinkedList<>();
for (int i = 0 ; i < originWhitelist.size() ; i++) {
@ -598,7 +598,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@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 RCTWebViewClient());
}
@Override
@ -656,8 +656,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@Override
public void onDropViewInstance(WebView webView) {
super.onDropViewInstance(webView);
((ThemedReactContext) webView.getContext()).removeLifecycleEventListener((RNCWebView) webView);
((RNCWebView) webView).cleanupCallbacksAndDestroy();
((ThemedReactContext) webView.getContext()).removeLifecycleEventListener((RCTWebView) webView);
((RCTWebView) webView).cleanupCallbacksAndDestroy();
}
protected WebView.PictureListener getPictureListener() {

View File

@ -6,17 +6,17 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
public class RNCWebViewModule extends ReactContextBaseJavaModule {
public class RCTWebViewModule extends ReactContextBaseJavaModule {
private final ReactApplicationContext reactContext;
public RNCWebViewModule(ReactApplicationContext reactContext) {
public RCTWebViewModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}
@Override
public String getName() {
return "RNCWebView";
return "RCTWebView";
}
}

View File

@ -10,10 +10,10 @@ import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.JavaScriptModule;
public class RNCWebViewPackage implements ReactPackage {
public class RCTWebViewPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new RNCWebViewModule(reactContext));
return Arrays.<NativeModule>asList(new RCTWebViewModule(reactContext));
}
// Deprecated from RN 0.47
@ -23,7 +23,7 @@ public class RNCWebViewPackage implements ReactPackage {
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
RNCWebViewManager viewManager = new RNCWebViewManager();
RCTWebViewManager viewManager = new RCTWebViewManager();
return Arrays.<ViewManager>asList(viewManager);
}
}

View File

@ -4,7 +4,7 @@ import android.webkit.WebView;
/**
* Implement this interface in order to config your {@link WebView}. An instance of that
* implementation will have to be given as a constructor argument to {@link RNCWebViewManager}.
* implementation will have to be given as a constructor argument to {@link RCTWebViewManager}.
*/
public interface WebViewConfig {

View File

@ -27,7 +27,7 @@ import WebViewShared from './WebViewShared';
const resolveAssetSource = Image.resolveAssetSource;
const RNC_WEBVIEW_REF = 'webview';
const RCT_WEBVIEW_REF = 'webview';
const WebViewState = keyMirror({
IDLE: null,