File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
android/src/main/java/com/reactnativecommunity/webview Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 4040import java .util .List ;
4141import java .util .Map ;
4242
43+ import android .print .PrintAttributes ;
44+ import android .print .PrintManager ;
45+
4346public class RNCWebView extends WebView implements LifecycleEventListener {
4447 protected @ Nullable
4548 String injectedJS ;
@@ -292,9 +295,9 @@ public void callInjectedJavaScript() {
292295 public void callInjectedJavaScriptBeforeContentLoaded () {
293296 if (getSettings ().getJavaScriptEnabled ()) {
294297 // This is necessary to support window.print() in the loaded web pages.
295- evaluateJavascriptWithFallback (
296- "(function(){window.print=function(){window.ReactNativeWebView.print();};})();"
297- );
298+ // evaluateJavascriptWithFallback(
299+ // "(function(){window.print=function(){window.ReactNativeWebView.print();};})();"
300+ // );
298301
299302 if (injectedJSBeforeContentLoaded != null &&
300303 !TextUtils .isEmpty (injectedJSBeforeContentLoaded )) {
@@ -330,6 +333,14 @@ public void run() {
330333 } else {
331334 dispatchEvent (webView , new TopMessageEvent (RNCWebViewWrapper .getReactTagFromWebView (webView ), data ));
332335 }
336+
337+ if (message .equals ("android-print" )){
338+ android .print .PrintDocumentAdapter printAdapter = mWebView .createPrintDocumentAdapter ("Form" );
339+ PrintManager printManager = (PrintManager ) reactContext .getSystemService (Context .PRINT_SERVICE );
340+ if (printManager != null ) {
341+ printManager .print ("Form" , printAdapter , new PrintAttributes .Builder ().build ());
342+ }
343+ }
333344 }
334345 });
335346 } else {
You can’t perform that action at this time.
0 commit comments