Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra DataTemplate instantiations on iOS #158

Closed
fschwiet opened this issue Jun 19, 2017 · 4 comments
Closed

extra DataTemplate instantiations on iOS #158

fschwiet opened this issue Jun 19, 2017 · 4 comments

Comments

@fschwiet
Copy link

fschwiet commented Jun 19, 2017

I created a branch with tracing to highlight the issue: https://github.com/fschwiet/CarouselView/tree/view-double-constructed

Repro steps:

  1. Open the demo app
  2. Click "Navigate".
  3. Count the number of times "!!!!!! PhotoUrl2 constructor called." shows up in the application output.
  • Expected result: "!!!!!! PhotoUrl2 constructor called." only shows up in the debug output once.
  • Actual result
    • On iOS: "!!!!!! PhotoUrl2 constructor called." shows up in the debug output twice.
    • On Android: "!!!!!! PhotoUrl2 constructor called." only shows up in the debug output once.

I can understand if this doesn't seem like a big deal, really its just a slight performance cost in most scenarios. In my scenario though I am using OxyPlot in the first DataTemplate and OxyPlot won't let you bind its PlotModel to more than one view, so I get an exception. There is a work-around to make it work in OxyPlot, but its complicated and I'd rather not. OxyPlot has had this restriction for a long time so I doubt they're going to change their behavior now (oxyplot/oxyplot-xamarin#60).

@alexrainman
Copy link
Owner

There's no way to avoid this. In iOS, SizeChanged is called multiple times. Sometimes one time, sometimes two, and that's something i cannot control.

@alexrainman
Copy link
Owner

Also, internally UIPageViewController creates the next page for smooth swiping and that's what you maybe seeing.

@alexrainman
Copy link
Owner

Found a way to prevent multiple calls. Next release.

@fschwiet
Copy link
Author

Thank you Alex.

Also, internally UIPageViewController creates the next page for smooth swiping and that's what you maybe seeing.

This sounds ok, as long as the instantiations for each DataTemplate don't overlap.

I did hit the crash in my project on Android, indicating one of the DataTemplates is being created twice. I haven't been able to repro it with the test project though. So I may still need to use the oxyplot workaround.

It makes me wonder if it'd be better (I don't think its possible now) to just pass in an array of Views instead of DataTemplates (in this case the number of views is quite small). I might give that a try, it seems like I could just make a change to where ever the current code checks for a DataTemplate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants