Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<!-- Please see https://github.com/OutSystems/reactview?tab=readme-ov-file#versioning for versioning rules -->
<Version>5.120.3</Version>
<Version>5.120.4</Version>
<Authors>OutSystems</Authors>
<Product>ReactView</Product>
<Copyright>Copyright © OutSystems 2023</Copyright>
Expand Down
15 changes: 15 additions & 0 deletions ReactViewControl/ReactViewRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal partial class ReactViewRender : IChildViewHost, IDisposable {

private Dictionary<string, FrameInfo> Frames { get; } = new Dictionary<string, FrameInfo>();
private Dictionary<string, WeakReference<FrameInfo>> RecoverableFrames { get; } = new Dictionary<string, WeakReference<FrameInfo>>();
private Dictionary<string, WeakReference<IViewModule>> ChildViewModules { get; } = new Dictionary<string, WeakReference<IViewModule>>();

private ExtendedWebView WebView { get; }
private Assembly UserCallingAssembly { get; }
Expand Down Expand Up @@ -205,6 +206,7 @@ private void OnWebViewJavascriptContextReleased(string frameName) {

Frames.Clear();
Frames.Add(mainFrame.Name, mainFrame);
ChildViewModules.Clear();
var previousComponentReady = mainFrame.IsComponentReadyToLoad;
mainFrame.Reset();
mainFrame.IsComponentReadyToLoad = previousComponentReady;
Expand Down Expand Up @@ -407,6 +409,9 @@ public bool AddChildView(IViewModule childView, string frameName) {
private void BindComponentToFrame(IViewModule component, FrameInfo frame) {
frame.Component = component;
component.Bind(frame, this);
if (!frame.IsMain) {
ChildViewModules[frame.Name] = new WeakReference<IViewModule>(component);
}
}

/// <summary>
Expand Down Expand Up @@ -605,6 +610,16 @@ private FrameInfo GetOrCreateFrame(string frameName) {
Frames[frameName] = newFrame;
AddPlugins(PluginsFactory(), newFrame);

// Rebind the existing IViewModule (kept by the consumer) to the new frame on remount
if (!newFrame.IsMain && ChildViewModules.TryGetValue(frameName, out var weakComponent)) {
if (weakComponent.TryGetTarget(out var existingComponent)) {
BindComponentToFrame(existingComponent, newFrame);
newFrame.IsComponentReadyToLoad = true;
} else {
ChildViewModules.Remove(frameName);
}
}

return newFrame;
}

Expand Down