Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HybridWebView update #540

Merged
merged 3 commits into from
Nov 14, 2024
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 @@ -10,7 +10,7 @@ public partial class MainPage : ContentPage
public MainPage()
{
InitializeComponent();
hybridWebView.SetInvokeJavaScriptTarget<DotNetMethods>(new DotNetMethods(this));
hybridWebView.SetInvokeJavaScriptTarget(this);
}

private void OnSendMessageButtonClicked(object sender, EventArgs e)
Expand Down Expand Up @@ -61,6 +61,32 @@ private void hybridWebView_RawMessageReceived(object sender, HybridWebViewRawMes
Dispatcher.Dispatch(() => editor.Text += Environment.NewLine + e.Message);
}

public void DoSyncWork()
{
Debug.WriteLine("DoSyncWork");
}

public void DoSyncWorkParams(int i, string s)
{
Debug.WriteLine($"DoSyncWorkParams: {i}, {s}");
}

public string DoSyncWorkReturn()
{
Debug.WriteLine("DoSyncWorkReturn");
return "Hello from C#!";
}

public SyncReturn DoSyncWorkParamsReturn(int i, string s)
{
Debug.WriteLine($"DoSyncWorkParamReturn: {i}, {s}");
return new SyncReturn
{
Message = "Hello from C#!" + s,
Value = i
};
}

public class ComputationResult
{
public double result { get; set; }
Expand All @@ -78,42 +104,6 @@ internal partial class HybridSampleJSContext : JsonSerializerContext
// for trimmed builds.
}

private class DotNetMethods
{
MainPage _mainPage;

public DotNetMethods(MainPage mainPage)
{
_mainPage = mainPage;
}

public void DoSyncWork()
{
Debug.WriteLine("DoSyncWork");
}

public void DoSyncWorkParams(int i, string s)
{
Debug.WriteLine($"DoSyncWorkParams: {i}, {s}");
}

public string DoSyncWorkReturn()
{
Debug.WriteLine("DoSyncWorkReturn");
return "Hello from C#!";
}

public SyncReturn DoSyncWorkParamsReturn(int i, string s)
{
Debug.WriteLine($"DoSyncWorkParamReturn: {i}, {s}");
return new SyncReturn
{
Message = "Hello from C#!" + s,
Value = i
};
}
}

public class SyncReturn
{
public string? Message { get; set; }
Expand Down
Loading