Skip to content

Commit

Permalink
Fix RepeatView
Browse files Browse the repository at this point in the history
* don't bail on rendering children if a child throws Bail
* don't create a prefab as one of the children
  • Loading branch information
neilsarkar committed Aug 21, 2020
1 parent bc4b0ef commit 96966a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Runtime/Views/RepeatView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,25 @@ void RenderChildren() {
return;
}

#if UNITY_EDITOR
var model = PrefabUtility.InstantiatePrefab(ViewPrefab, transform) as GameObject;
model.SetActive(false);
#endif

for (int i = 0; i < Items.Count; i++) {
var child = Instantiate(ViewPrefab, transform);
var child = CreateChild(i);
var view = child.GetComponent<ChildView<TState, T>>();
if (view == null) {continue;}
view.RenderInternal(State, default(TState));
try {
view.RenderInternal(State, default(TState));
} catch (Bail) {}
}

}

GameObject CreateChild(int index) {
#if UNITY_EDITOR
if (index == 0) {
return PrefabUtility.InstantiatePrefab(ViewPrefab, transform) as GameObject;
}
#endif
return Instantiate(ViewPrefab, transform);
}
}
}
1 change: 1 addition & 0 deletions Runtime/Views/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void State_OnChange() {

void OnEnable() {
if (State == null) { if (Application.isPlaying) { Warn($"State is null in {name} OnEnable"); } return; }
State.OnChange -= State_OnChange;
State.OnChange += State_OnChange;
OnShowInternal();
OnShow();
Expand Down

0 comments on commit 96966a1

Please sign in to comment.