This commit is contained in:
James Clancey 2019-06-29 14:07:12 -08:00
Родитель 86f0baf4b1
Коммит 593fc48058
3 изменённых файлов: 59 добавлений и 2 удалений

Просмотреть файл

@ -55,7 +55,10 @@ namespace HotUI {
viewHandler?.SetView (this.GetRenderView());
}
}
internal void UpdateFromOldView (IViewHandler handler) => ViewHandler = handler;
internal void UpdateFromOldView (View view) {
ViewHandler = view.ViewHandler;
view.ViewHandler = null;
}
View builtView;
public View BuiltView => builtView;
void ResetView()

Просмотреть файл

@ -135,7 +135,7 @@ namespace HotUI {
}
}
newView.UpdateFromOldView (oldView.ViewHandler);
newView.UpdateFromOldView (oldView);
return newView;

Просмотреть файл

@ -0,0 +1,54 @@
using System;
using Xunit;
namespace HotUI.Tests {
public class ViewTests {
public class StatePage : View {
public readonly State<int> clickCount = new State<int> (1);
public readonly State<string> text = new State<string> ();
public readonly State<bool> boolState = new State<bool> ();
}
[Fact]
public void RebuildingViewsReuseNativeView()
{
Text text = null;
Text currentText = null;
var view = new StatePage ();
view.text.Value = "Hello";
int buildCount = 0;
view.Body = () => {
buildCount++;
currentText = new Text ($"{view.text.Value} - {view.clickCount.Value}");
return currentText;
};
var viewHandler = new GenericViewHandler ();
view.ViewHandler = viewHandler;
text = currentText;
var textHandler = new GenericViewHandler ();
text.ViewHandler = textHandler;
Assert.Equal (1, buildCount);
view.clickCount.Value++;
Assert.Equal (2, buildCount);
//Check to make sure that the view was rebuilt
Assert.NotEqual (text,currentText);
//Make sure the old one is unasociated
Assert.Null (text?.ViewHandler);
//Make sure the new view has the old handler
Assert.Equal (currentText?.ViewHandler, textHandler);
}
}
}