Closed vshapenko closed 4 years ago
@vshapenko The PR #765 fixes the issue.
Also noticed the above sample was quite slow (measured up to 8 seconds on iOS) but after inspection, most of the time is spent outside of Fabulous (Fabulous spends like 2ms, Xamarin.Forms takes the remaining of the 8 seconds to create the items everytime on insert or replace).
It's because of various factors:
The reason here seems to be mostly the latest.
Tested it with the following code:
match model.Selected with
| Items1 -> model.Items1 |> List.map (fun item -> View.Grid (children = [ View.Label(item) ]))
| Items2 -> model.Items2 |> List.map (fun item -> View.Grid (children = [ View.Button(item) ]))
| Items3 -> model.Items3 |> List.map (fun item -> View.Grid (children = [ View.Entry(item) ]))
It immediately fell to ~150ms when clicking the "Change" button.
So the recommendations I can make for your sample:
View.Grid
for exampleCombining same root type + bigger height (tested at 150) gives ~30ms for the sample above.
Also don't hesitate to make use of performance helpers like dependsOn
when you know your data is not likely to change.
let drawSelected model dispatch =
let items1 = model.Items1 |> List.map (fun item ->
dependsOn item (fun _ item ->
View.Label(text = item)
)
)
let items2 = model.Items2 |> List.map (fun item ->
dependsOn item (fun _ item ->
View.StackLayout (children =[View.Label(item)])
)
)
let items3 = model.Items3 |> List.map (fun item ->
dependsOn item (fun _ item ->
View.Grid (children =[View.Label(item)])
)
)
View.ContentPage(
View.StackLayout(
verticalOptions = LayoutOptions.FillAndExpand,
children = [
View.Button(
text = "Change",
command = (fun () ->
let next =
match model.Selected with
| Items1 ->Items2
| Items2 ->Items3
| Items3 -> Items1
dispatch (Select next)
)
)
View.CollectionView(key = "Items1", isVisible = (model.Selected = Items1), items = items1)
View.CollectionView(key = "Items2", isVisible = (model.Selected = Items2), items = items2)
View.CollectionView(key = "Items3", isVisible = (model.Selected = Items3), items = items3)
]
)
)
Hello! Given following code :
i have a strange collection view behavior - when i press Change button, i suspect collection would be populated by items chosen by Selected flag, but instead i get old items remain in collection and a new ones. Looks like there is a bug in calculating diff for ItemsView.