mirror of
https://github.com/status-im/react-native-webview.git
synced 2025-02-23 17:28:37 +00:00
WIP: WebView extraction - Rename android from RNC to RCT
This commit is contained in:
parent
922151ec42
commit
642620dd98
@ -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.
|
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
|
### Contributor Notes
|
||||||
|
|
||||||
* I've removed all PropTypes for now. Instead, we'll be moving toward Flow or TypeScript at some later date
|
* I've removed all PropTypes for now. Instead, we'll be moving toward Flow or TypeScript at some later date
|
||||||
|
@ -83,10 +83,10 @@ import org.json.JSONObject;
|
|||||||
* - canGoBack - boolean, whether there is anything on a history stack to go back
|
* - canGoBack - boolean, whether there is anything on a history stack to go back
|
||||||
* - canGoForward - boolean, whether it is possible to request GO_FORWARD command
|
* - canGoForward - boolean, whether it is possible to request GO_FORWARD command
|
||||||
*/
|
*/
|
||||||
@ReactModule(name = RNCWebViewManager.REACT_CLASS)
|
@ReactModule(name = RCTWebViewManager.REACT_CLASS)
|
||||||
public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
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_ENCODING = "UTF-8";
|
||||||
protected static final String HTML_MIME_TYPE = "text/html";
|
protected static final String HTML_MIME_TYPE = "text/html";
|
||||||
@ -108,7 +108,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
protected WebViewConfig mWebViewConfig;
|
protected WebViewConfig mWebViewConfig;
|
||||||
protected @Nullable WebView.PictureListener mPictureListener;
|
protected @Nullable WebView.PictureListener mPictureListener;
|
||||||
|
|
||||||
protected static class RNCWebViewClient extends WebViewClient {
|
protected static class RCTWebViewClient extends WebViewClient {
|
||||||
|
|
||||||
protected boolean mLastLoadFailed = false;
|
protected boolean mLastLoadFailed = false;
|
||||||
protected @Nullable ReadableArray mUrlPrefixesForDefaultIntent;
|
protected @Nullable ReadableArray mUrlPrefixesForDefaultIntent;
|
||||||
@ -119,7 +119,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
super.onPageFinished(webView, url);
|
super.onPageFinished(webView, url);
|
||||||
|
|
||||||
if (!mLastLoadFailed) {
|
if (!mLastLoadFailed) {
|
||||||
RNCWebView reactWebView = (RNCWebView) webView;
|
RCTWebView reactWebView = (RCTWebView) webView;
|
||||||
reactWebView.callInjectedJavaScript();
|
reactWebView.callInjectedJavaScript();
|
||||||
reactWebView.linkBridge();
|
reactWebView.linkBridge();
|
||||||
emitFinishEvent(webView, url);
|
emitFinishEvent(webView, url);
|
||||||
@ -242,15 +242,15 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
* Subclass of {@link WebView} that implements {@link LifecycleEventListener} interface in order
|
* 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
|
* 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 @Nullable String injectedJS;
|
||||||
protected boolean messagingEnabled = false;
|
protected boolean messagingEnabled = false;
|
||||||
protected @Nullable RNCWebViewClient mRNCWebViewClient;
|
protected @Nullable RCTWebViewClient mRCTWebViewClient;
|
||||||
|
|
||||||
protected class RNCWebViewBridge {
|
protected class RCTWebViewBridge {
|
||||||
RNCWebView mContext;
|
RCTWebView mContext;
|
||||||
|
|
||||||
RNCWebViewBridge(RNCWebView c) {
|
RCTWebViewBridge(RCTWebView c) {
|
||||||
mContext = c;
|
mContext = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
* Reactive Native needed for access to ReactNative internal system functionality
|
* Reactive Native needed for access to ReactNative internal system functionality
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public RNCWebView(ThemedReactContext reactContext) {
|
public RCTWebView(ThemedReactContext reactContext) {
|
||||||
super(reactContext);
|
super(reactContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,19 +289,19 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
@Override
|
@Override
|
||||||
public void setWebViewClient(WebViewClient client) {
|
public void setWebViewClient(WebViewClient client) {
|
||||||
super.setWebViewClient(client);
|
super.setWebViewClient(client);
|
||||||
mRNCWebViewClient = (RNCWebViewClient)client;
|
mRCTWebViewClient = (RCTWebViewClient)client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable RNCWebViewClient getRNCWebViewClient() {
|
public @Nullable RCTWebViewClient getRCTWebViewClient() {
|
||||||
return mRNCWebViewClient;
|
return mRCTWebViewClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInjectedJavaScript(@Nullable String js) {
|
public void setInjectedJavaScript(@Nullable String js) {
|
||||||
injectedJS = js;
|
injectedJS = js;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RNCWebViewBridge createRNCWebViewBridge(RNCWebView webView) {
|
protected RCTWebViewBridge createRCTWebViewBridge(RCTWebView webView) {
|
||||||
return new RNCWebViewBridge(webView);
|
return new RCTWebViewBridge(webView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessagingEnabled(boolean enabled) {
|
public void setMessagingEnabled(boolean enabled) {
|
||||||
@ -311,7 +311,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
|
|
||||||
messagingEnabled = enabled;
|
messagingEnabled = enabled;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
addJavascriptInterface(createRNCWebViewBridge(this), BRIDGE_NAME);
|
addJavascriptInterface(createRCTWebViewBridge(this), BRIDGE_NAME);
|
||||||
linkBridge();
|
linkBridge();
|
||||||
} else {
|
} else {
|
||||||
removeJavascriptInterface(BRIDGE_NAME);
|
removeJavascriptInterface(BRIDGE_NAME);
|
||||||
@ -360,14 +360,14 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RNCWebViewManager() {
|
public RCTWebViewManager() {
|
||||||
mWebViewConfig = new WebViewConfig() {
|
mWebViewConfig = new WebViewConfig() {
|
||||||
public void configWebView(WebView webView) {
|
public void configWebView(WebView webView) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public RNCWebViewManager(WebViewConfig webViewConfig) {
|
public RCTWebViewManager(WebViewConfig webViewConfig) {
|
||||||
mWebViewConfig = webViewConfig;
|
mWebViewConfig = webViewConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,14 +376,14 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
return REACT_CLASS;
|
return REACT_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RNCWebView createRNCWebViewInstance(ThemedReactContext reactContext) {
|
protected RCTWebView createRCTWebViewInstance(ThemedReactContext reactContext) {
|
||||||
return new RNCWebView(reactContext);
|
return new RCTWebView(reactContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
protected WebView createViewInstance(ThemedReactContext reactContext) {
|
protected WebView createViewInstance(ThemedReactContext reactContext) {
|
||||||
RNCWebView webView = createRNCWebViewInstance(reactContext);
|
RCTWebView webView = createRCTWebViewInstance(reactContext);
|
||||||
webView.setWebChromeClient(new WebChromeClient() {
|
webView.setWebChromeClient(new WebChromeClient() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onConsoleMessage(ConsoleMessage message) {
|
public boolean onConsoleMessage(ConsoleMessage message) {
|
||||||
@ -474,12 +474,12 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
|
|
||||||
@ReactProp(name = "injectedJavaScript")
|
@ReactProp(name = "injectedJavaScript")
|
||||||
public void setInjectedJavaScript(WebView view, @Nullable String injectedJavaScript) {
|
public void setInjectedJavaScript(WebView view, @Nullable String injectedJavaScript) {
|
||||||
((RNCWebView) view).setInjectedJavaScript(injectedJavaScript);
|
((RCTWebView) view).setInjectedJavaScript(injectedJavaScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactProp(name = "messagingEnabled")
|
@ReactProp(name = "messagingEnabled")
|
||||||
public void setMessagingEnabled(WebView view, boolean enabled) {
|
public void setMessagingEnabled(WebView view, boolean enabled) {
|
||||||
((RNCWebView) view).setMessagingEnabled(enabled);
|
((RCTWebView) view).setMessagingEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactProp(name = "source")
|
@ReactProp(name = "source")
|
||||||
@ -568,7 +568,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
public void setUrlPrefixesForDefaultIntent(
|
public void setUrlPrefixesForDefaultIntent(
|
||||||
WebView view,
|
WebView view,
|
||||||
@Nullable ReadableArray urlPrefixesForDefaultIntent) {
|
@Nullable ReadableArray urlPrefixesForDefaultIntent) {
|
||||||
RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
|
RCTWebViewClient client = ((RCTWebView) view).getRCTWebViewClient();
|
||||||
if (client != null && urlPrefixesForDefaultIntent != null) {
|
if (client != null && urlPrefixesForDefaultIntent != null) {
|
||||||
client.setUrlPrefixesForDefaultIntent(urlPrefixesForDefaultIntent);
|
client.setUrlPrefixesForDefaultIntent(urlPrefixesForDefaultIntent);
|
||||||
}
|
}
|
||||||
@ -585,7 +585,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
public void setOriginWhitelist(
|
public void setOriginWhitelist(
|
||||||
WebView view,
|
WebView view,
|
||||||
@Nullable ReadableArray originWhitelist) {
|
@Nullable ReadableArray originWhitelist) {
|
||||||
RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
|
RCTWebViewClient client = ((RCTWebView) view).getRCTWebViewClient();
|
||||||
if (client != null && originWhitelist != null) {
|
if (client != null && originWhitelist != null) {
|
||||||
List<Pattern> whiteList = new LinkedList<>();
|
List<Pattern> whiteList = new LinkedList<>();
|
||||||
for (int i = 0 ; i < originWhitelist.size() ; i++) {
|
for (int i = 0 ; i < originWhitelist.size() ; i++) {
|
||||||
@ -598,7 +598,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
@Override
|
@Override
|
||||||
protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
|
protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
|
||||||
// Do not register default touch emitter and let WebView implementation handle touches
|
// Do not register default touch emitter and let WebView implementation handle touches
|
||||||
view.setWebViewClient(new RNCWebViewClient());
|
view.setWebViewClient(new RCTWebViewClient());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -656,8 +656,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
@Override
|
@Override
|
||||||
public void onDropViewInstance(WebView webView) {
|
public void onDropViewInstance(WebView webView) {
|
||||||
super.onDropViewInstance(webView);
|
super.onDropViewInstance(webView);
|
||||||
((ThemedReactContext) webView.getContext()).removeLifecycleEventListener((RNCWebView) webView);
|
((ThemedReactContext) webView.getContext()).removeLifecycleEventListener((RCTWebView) webView);
|
||||||
((RNCWebView) webView).cleanupCallbacksAndDestroy();
|
((RCTWebView) webView).cleanupCallbacksAndDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected WebView.PictureListener getPictureListener() {
|
protected WebView.PictureListener getPictureListener() {
|
@ -6,17 +6,17 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|||||||
import com.facebook.react.bridge.ReactMethod;
|
import com.facebook.react.bridge.ReactMethod;
|
||||||
import com.facebook.react.bridge.Callback;
|
import com.facebook.react.bridge.Callback;
|
||||||
|
|
||||||
public class RNCWebViewModule extends ReactContextBaseJavaModule {
|
public class RCTWebViewModule extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
private final ReactApplicationContext reactContext;
|
private final ReactApplicationContext reactContext;
|
||||||
|
|
||||||
public RNCWebViewModule(ReactApplicationContext reactContext) {
|
public RCTWebViewModule(ReactApplicationContext reactContext) {
|
||||||
super(reactContext);
|
super(reactContext);
|
||||||
this.reactContext = reactContext;
|
this.reactContext = reactContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "RNCWebView";
|
return "RCTWebView";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,10 +10,10 @@ import com.facebook.react.bridge.NativeModule;
|
|||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.uimanager.ViewManager;
|
import com.facebook.react.uimanager.ViewManager;
|
||||||
import com.facebook.react.bridge.JavaScriptModule;
|
import com.facebook.react.bridge.JavaScriptModule;
|
||||||
public class RNCWebViewPackage implements ReactPackage {
|
public class RCTWebViewPackage implements ReactPackage {
|
||||||
@Override
|
@Override
|
||||||
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
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
|
// Deprecated from RN 0.47
|
||||||
@ -23,7 +23,7 @@ public class RNCWebViewPackage implements ReactPackage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
||||||
RNCWebViewManager viewManager = new RNCWebViewManager();
|
RCTWebViewManager viewManager = new RCTWebViewManager();
|
||||||
return Arrays.<ViewManager>asList(viewManager);
|
return Arrays.<ViewManager>asList(viewManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ import android.webkit.WebView;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement this interface in order to config your {@link WebView}. An instance of that
|
* 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 {
|
public interface WebViewConfig {
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ import WebViewShared from './WebViewShared';
|
|||||||
|
|
||||||
const resolveAssetSource = Image.resolveAssetSource;
|
const resolveAssetSource = Image.resolveAssetSource;
|
||||||
|
|
||||||
const RNC_WEBVIEW_REF = 'webview';
|
const RCT_WEBVIEW_REF = 'webview';
|
||||||
|
|
||||||
const WebViewState = keyMirror({
|
const WebViewState = keyMirror({
|
||||||
IDLE: null,
|
IDLE: null,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user