赞
踩
- public class ReactWebViewManager extends SimpleViewManager<WebView>{
- public static final String REACT_CLASS = "MyWebView";
-
- @Override
- public String getName() {
- return REACT_CLASS;
- }
-
- @Override
- protected WebView createViewInstance(ThemedReactContext reactContext) {
- WebView webView= new WebView(reactContext);
- webView.setWebViewClient(new WebViewClient(){
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- view.loadUrl(url);
- return true;
- }
- });
- return webView;
- }
-
-
- @ReactProp(name = "url")
- public void setUrl(WebView view,@Nullable String url) {
- Log.e("TAG", "setUrl");
- view.loadUrl(url);
- }
- @ReactProp(name = "html")
- public void setHtml(WebView view,@Nullable String html) {
- Log.e("TAG", "setHtml");
- view.loadData(html, "text/html; charset=utf-8", "UTF-8");
- }
- }
2.创建一个把ReactPackage的子类,把这个视图管理类注册到应用程序包的createViewManagers里;
- public class AppReactPackage implements ReactPackage{
- ...... ......
- @Override
- public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
- return Arrays.<ViewManager>asList(
- new ReactWebViewManager(),new ReactRTCWebViewManager());
- }
- }
3.在MainActivity中的getPackages方法中添加ReactPackage的子类
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。