Interface IBrowserViewportService
- Namespace
- MudBlazor
- Assembly
- MudBlazor.dll
Represents a service that serves to listen to browser window size changes and breakpoints.
public interface IBrowserViewportService : IAsyncDisposable
- Inherited Members
- Extension Methods
Properties
ResizeOptions
Gets the current resize options.
ResizeOptions ResizeOptions { get; }
Property Value
Methods
GetCurrentBreakpointAsync()
Get the current breakpoint
Task<Breakpoint> GetCurrentBreakpointAsync()
Returns
- Task<Breakpoint>
A task representing the current breakpoint
GetCurrentBrowserWindowSizeAsync()
Get the current size of the window
Task<BrowserWindowSize> GetCurrentBrowserWindowSizeAsync()
Returns
- Task<BrowserWindowSize>
A task representing the current browser size
IsBreakpointWithinReferenceSizeAsync(Breakpoint, Breakpoint)
Check if the current breakpoint fits within the reference size
Task<bool> IsBreakpointWithinReferenceSizeAsync(Breakpoint breakpoint, Breakpoint reference)
Parameters
breakpoint
BreakpointThe breakpoint to check
reference
Breakpoint
Returns
- Task<bool>
A task representing whether the media size meets the criteria. Returns
true
if the media size meets the criteria; otherwise, returnsfalse
. For example, if the reference size is Sm and the breakpoint is set to SmAndDown, this method will returntrue
.
IsBreakpointWithinWindowSizeAsync(Breakpoint)
Check if the current breakpoint fits within the current window size
Task<bool> IsBreakpointWithinWindowSizeAsync(Breakpoint breakpoint)
Parameters
breakpoint
BreakpointThe breakpoint to check.
Returns
- Task<bool>
A task representing whether the media size meets the criteria. Returns
true
if the media size meets the criteria; otherwise, returnsfalse
. For example, if the current window size is Sm and the breakpoint is set to SmAndDown, this method will returntrue
.
IsMediaQueryMatchAsync(string)
Matches if the document currently matches the media query, or false if not.
Task<bool> IsMediaQueryMatchAsync(string mediaQuery)
Parameters
mediaQuery
stringA string specifying the media query.
Returns
- Task<bool>
A task representing a boolean value that is
true
if the document currently matches the media query; otherwise, it'sfalse
.
SubscribeAsync(IBrowserViewportObserver, bool)
Subscribes an observer to receive notifications of browser window size changes and breakpoints.
Task SubscribeAsync(IBrowserViewportObserver observer, bool fireImmediately = true)
Parameters
observer
IBrowserViewportObserverThe observer to subscribe.
fireImmediately
boolIndicates whether the event will fire immediately with the current BrowserWindowSize and Breakpoint information without waiting for changes. When set to
true
, the event will be fired immediately. When set tofalse
, it will wait for the service to observe any changes before firing the event. The event NotifyBrowserViewportChangeAsync(BrowserViewportEventArgs) won't fire if such Id already exist, for example when you re-subscribe.
Returns
- Task
A task representing the asynchronous operation.
SubscribeAsync(Guid, Action<BrowserViewportEventArgs>, ResizeOptions?, bool)
Subscribes a lambda Action<T> with a unique ID to receive notifications of browser window size changes and breakpoints.
Task SubscribeAsync(Guid observerId, Action<BrowserViewportEventArgs> lambda, ResizeOptions? options = null, bool fireImmediately = true)
Parameters
observerId
GuidThe unique ID associated with the observer. Use this ID to later UnsubscribeAsync(Guid).
lambda
Action<BrowserViewportEventArgs>The lambda function to subscribe.
options
ResizeOptionsThe resize options for the observer. When set to null, the global options provided during AddMudServices/AddMudBlazorResizeListener will be used. When specific options are provided, they will be used to observe the changes. The Action<T> won't be invoked if such Id already exist, for example when you re-subscribe. After you pass the options, modifying the instance won't have any effect, including re-subscription, as C# and JS side doesn't support this, you need to UnsubscribeAsync(Guid) and subscribe again.
fireImmediately
boolIndicates whether the event will fire immediately with the current BrowserWindowSize and Breakpoint information without waiting for changes. When set to
true
, the event will be fired immediately. When set tofalse
, it will wait for the service to observe any changes before firing the event.
Returns
- Task
A task representing the asynchronous operation.
SubscribeAsync(Guid, Func<BrowserViewportEventArgs, Task>, ResizeOptions?, bool)
Subscribes a lambda Func<T, TResult> with a unique ID to receive notifications of browser window size changes and breakpoints.
Task SubscribeAsync(Guid observerId, Func<BrowserViewportEventArgs, Task> lambda, ResizeOptions? options = null, bool fireImmediately = true)
Parameters
observerId
GuidThe unique ID associated with the observer. Use this ID to later UnsubscribeAsync(Guid).
lambda
Func<BrowserViewportEventArgs, Task>The lambda function to subscribe.
options
ResizeOptionsThe resize options for the observer. When set to null, the global options provided during AddMudServices/AddMudBlazorResizeListener will be used. When specific options are provided, they will be used to observe the changes. The Func<T, TResult> won't be invoked if such Id already exist, for example when you re-subscribe. After you pass the options, modifying the instance won't have any effect, including re-subscription, as C# and JS side doesn't support this, you need to UnsubscribeAsync(Guid) and subscribe again.
fireImmediately
boolIndicates whether the event will fire immediately with the current BrowserWindowSize and Breakpoint information without waiting for changes. When set to
true
, the event will be fired immediately. When set tofalse
, it will wait for the service to observe any changes before firing the event.
Returns
- Task
A task representing the asynchronous operation.
UnsubscribeAsync(IBrowserViewportObserver)
Unsubscribes an observer from receiving notifications.
Task UnsubscribeAsync(IBrowserViewportObserver observer)
Parameters
observer
IBrowserViewportObserverThe observer to unsubscribe.
Returns
- Task
A task representing the asynchronous operation.
UnsubscribeAsync(Guid)
Unsubscribes with the specified ID from receiving notifications.
Task UnsubscribeAsync(Guid observerId)
Parameters
observerId
GuidThe unique ID associated with the observer to unsubscribe.
Returns
- Task
A task representing the asynchronous operation.