diff --git a/README.md b/README.md index 4a19759..5143e7c 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ using Dispatch; [System.Serializable] public class UIState : State { public int nice; + public List bugs = new List () { "wasp", "ant" } ; + } ``` @@ -31,6 +33,7 @@ public static class UIActions { ``` ## View + ```csharp using VioletUI; @@ -68,4 +71,32 @@ public class AddButtonView : MyBaseView { dispatcher.Run(UIActions.Set(0)); } } +``` + +## RepeatView + +```csharp +public abstract class BaseRepeatView : RepeatView { + protected override UIState State => UIStateMB.Singleton.State; + protected override UIState LastState => UIStateMB.Singleton.LastState; +} + +public abstract class BaseChildView : ChildView { + protected override UIState State => UIStateMB.Singleton.State; + protected override UIState LastState => UIStateMB.Singleton.LastState; +} + +public class BugsView : BaseRepeatView () { + public override List Items => State?.bugs; + public override List LastItems => LastState?.bugs; +} + +public class BugView : BaseView { + public override void Render(UIState state, UIState lastState) { + if (lastState != null && Item == LastItem) { return; } + + print($"I am bug number {Index} and my name changed from {LastItem} to {Item}"); + } +} + ``` \ No newline at end of file diff --git a/Runtime/Views/RepeatView.cs b/Runtime/Views/RepeatView.cs index f87949f..66e124c 100644 --- a/Runtime/Views/RepeatView.cs +++ b/Runtime/Views/RepeatView.cs @@ -15,7 +15,7 @@ internal override void OnShowInternal() { } internal override void RenderInternal(TState state, TState lastState) { - if (Items.Count == LastItems?.Count) { return; } + if (lastState != null && Items.Count == LastItems?.Count) { return; } if (ViewPrefab == null) { return; } RenderChildren();