Skip to content

Commit c2b67f9

Browse files
committed
Sample interactive render mode
1 parent 90c7d67 commit c2b67f9

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/Components/Components/src/ComponentBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace Microsoft.AspNetCore.Components;
2323
public abstract class ComponentBase : IComponent, IHandleEvent, IHandleAfterRender
2424
{
2525
private readonly RenderFragment _renderFragment;
26+
private IComponentRenderMode? _interactiveRenderMode;
2627
private RenderHandle _renderHandle;
2728
private bool _initialized;
2829
private bool _hasNeverRendered = true;
@@ -47,6 +48,11 @@ public ComponentBase()
4748
/// </summary>
4849
protected ComponentPlatform Platform => _renderHandle.Platform;
4950

51+
/// <summary>
52+
/// Gets the <see cref="IComponentRenderMode"/> the component is rendering or will render in when it becomes interactive.
53+
/// </summary>
54+
protected IComponentRenderMode? InteractiveRenderMode => _interactiveRenderMode ??= _renderHandle.GetInteractiveRenderMode();
55+
5056
/// <summary>
5157
/// Renders the component to the supplied <see cref="RenderTreeBuilder"/>.
5258
/// </summary>

src/Components/Components/src/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Components.ComponentBase.InteractiveRenderMode.get -> Microsoft.AspNetCore.Components.IComponentRenderMode?
23
Microsoft.AspNetCore.Components.ComponentBase.Platform.get -> Microsoft.AspNetCore.Components.RenderTree.ComponentPlatform!
34
Microsoft.AspNetCore.Components.ExcludeFromInteractiveRoutingAttribute
45
Microsoft.AspNetCore.Components.ExcludeFromInteractiveRoutingAttribute.ExcludeFromInteractiveRoutingAttribute() -> void

src/Components/Components/src/RenderHandle.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ public Dispatcher Dispatcher
5656
/// </summary>
5757
public ComponentPlatform Platform => _renderer?.ComponentPlatform ?? throw new InvalidOperationException("No renderer has been initialized.");
5858

59+
internal IComponentRenderMode? GetInteractiveRenderMode()
60+
{
61+
if (_renderer == null)
62+
{
63+
throw new InvalidOperationException("No renderer has been initialized.");
64+
}
65+
66+
return _renderer.ComponentPlatform.RenderMode ?? _renderer.GetComponentRenderMode(_componentId);
67+
}
68+
5969
/// <summary>
6070
/// Notifies the renderer that the component should be rendered.
6171
/// </summary>

src/Components/Components/src/RenderTree/Renderer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ protected ComponentState GetComponentState(int componentId)
142142
protected internal virtual IComponentRenderMode? GetComponentRenderMode(IComponent component)
143143
=> null;
144144

145+
internal IComponentRenderMode? GetComponentRenderMode(int componentId)
146+
=> GetComponentRenderMode(GetRequiredComponentState(componentId).Component);
147+
145148
/// <summary>
146149
/// Resolves the component state for a given <see cref="IComponent"/> instance.
147150
/// </summary>

0 commit comments

Comments
 (0)