You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Components/Services/BrowserWindowSizeProvider.cs

34 lines
928 B

using Connected.Services;
using Microsoft.JSInterop;
namespace Connected;
public interface IBrowserWindowSizeProvider
{
ValueTask<BrowserWindowSize> GetBrowserWindowSize();
}
/// <summary>
/// This provider calls the JS method resizeListener.getBrowserWindowSize to get the browser window size
/// </summary>
public class BrowserWindowSizeProvider : IBrowserWindowSizeProvider
{
private readonly IJSRuntime _jsRuntime;
/// <summary>
///
/// </summary>
/// <param name="jsRuntime"></param>
public BrowserWindowSizeProvider(IJSRuntime jsRuntime)
{
this._jsRuntime = jsRuntime;
}
/// <summary>
/// Get the current BrowserWindowSize, this includes the Height and Width of the document.
/// </summary>
/// <returns></returns>
public ValueTask<BrowserWindowSize> GetBrowserWindowSize() =>
_jsRuntime.InvokeAsync<BrowserWindowSize>($"mudResizeListener.getBrowserWindowSize");
}