@@ -19,7 +19,7 @@ public class PaystackWebViewRenderer : ViewRenderer<PaystackWebView, Android.Web
19
19
private const string CallBackJavaScriptFunction = "function invokeCSharpAction(data){jsBridge.invokeCallbackAction(data);}" ;
20
20
private const string CloseJavaScriptFunction = "function invokeCSharpCloseAction(){jsBridge.invokeCloseAction();}" ;
21
21
private Context _context ;
22
-
22
+
23
23
public PaystackWebViewRenderer ( Context context ) : base ( context )
24
24
{
25
25
_context = context ;
@@ -46,13 +46,17 @@ protected override void OnElementChanged(ElementChangedEventArgs<PaystackWebView
46
46
var webviewElement = Element ;
47
47
Control . AddJavascriptInterface ( new JSBridge ( this , _context ) , "jsBridge" ) ;
48
48
string content = LoadHtmlString ( ) ;
49
- Control . SetWebViewClient ( new CustomWebViewClient ( webviewElement . Data ) ) ;
49
+ var InjectJsAction = new Action ( ( ) =>
50
+ {
51
+ InjectJS ( CallBackJavaScriptFunction ) ;
52
+ InjectJS ( CloseJavaScriptFunction ) ;
53
+ } ) ;
54
+ Control . SetWebViewClient ( new CustomWebViewClient ( webviewElement . Data , InjectJsAction ) ) ;
50
55
// Control.LoadUrl("file:///android_asset/paystack.html");
51
56
52
57
53
58
Control . LoadDataWithBaseURL ( "" , content , "text/html" , "UTF-8" , null ) ;
54
- InjectJS ( CallBackJavaScriptFunction ) ;
55
- InjectJS ( CloseJavaScriptFunction ) ;
59
+
56
60
}
57
61
}
58
62
@@ -115,15 +119,18 @@ internal string LoadHtmlString()
115
119
internal class CustomWebViewClient : WebViewClient
116
120
{
117
121
private string Record = "" ;
118
- public CustomWebViewClient ( string record )
122
+ public Action InjectJsAction = null ;
123
+ public CustomWebViewClient ( string record , Action injectJsAction )
119
124
{
120
125
Record = record ;
126
+ injectJsAction = injectJsAction ;
121
127
}
122
128
public override void OnPageFinished ( Android . Webkit . WebView view , string url )
123
129
{
124
130
base . OnPageFinished ( view , url ) ;
125
131
126
132
view . LoadUrl ( string . Format ( "javascript:payWithPaystack({0})" , Record ) ) ;
133
+ InjectJsAction ? . Invoke ( ) ;
127
134
}
128
135
public override void OnPageStarted ( Android . Webkit . WebView view , string url , Bitmap favicon )
129
136
{
0 commit comments