Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import java.util.List;
import java.util.Map;

import android.print.PrintAttributes;
import android.print.PrintManager;

public class RNCWebView extends WebView implements LifecycleEventListener {
protected @Nullable
String injectedJS;
Expand Down Expand Up @@ -292,9 +295,9 @@ public void callInjectedJavaScript() {
public void callInjectedJavaScriptBeforeContentLoaded() {
if (getSettings().getJavaScriptEnabled()) {
// This is necessary to support window.print() in the loaded web pages.
evaluateJavascriptWithFallback(
"(function(){window.print=function(){window.ReactNativeWebView.print();};})();"
);
// evaluateJavascriptWithFallback(
// "(function(){window.print=function(){window.ReactNativeWebView.print();};})();"
// );

if (injectedJSBeforeContentLoaded != null &&
!TextUtils.isEmpty(injectedJSBeforeContentLoaded)) {
Expand Down Expand Up @@ -330,6 +333,14 @@ public void run() {
} else {
dispatchEvent(webView, new TopMessageEvent(RNCWebViewWrapper.getReactTagFromWebView(webView), data));
}

if(message.equals("android-print")){
android.print.PrintDocumentAdapter printAdapter = mWebView.createPrintDocumentAdapter("Form");
PrintManager printManager = (PrintManager) reactContext.getSystemService(Context.PRINT_SERVICE);
if (printManager != null) {
printManager.print("Form", printAdapter, new PrintAttributes.Builder().build());
}
}
}
});
} else {
Expand Down
Loading