-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
Better type-safety for View API #341
Comments
Three thoughts on this
|
No I didn't but it is an example of the API indicating something valid that isn't
Yes I actually did and it took me a while to figure out what was wrong, I had this code: let layout =
StackLayout.stackLayout [
(* bunch of stuff in here*)
]
NavigationPage.navigationPage [
NavigationPage.Pages [
ContentPage.contentPage [
ContentPage.Content layout
]
(* more pages here *)
]
] then I started refactoring |
I agree it would be better if we remove most of the
I also agree this one is problematic.
But I think it's doing Fabulous a disservice. In the case of
For some cases like this one, I think we shouldn't use the underlying type as a constraint. |
Totally agree with you one this one
IMHO correctness > API ergonomics: I know a string is easier to work with but it is just as easy if someone would write a simple function to get an ImageSource if one finds himself/herself needing this too often: let source path = ImageSource.FromFile(path)
View.Image(source = source "some/path/to/image.png") if you want to improve usage with F# 5.0 then you probably want |
Agree. I think we should review each property and decide if it's worth providing some built-in tools for them. |
I'm ok with you guys making changes here, as long as the docs give lots and lots of snippets (most don't write this code by hand, they just cut and paste samples). Also please assess the changes with beginners in mind.
Both are important. |
A bunch of the changes have been included in #530 Didn't tackle the ViewElement composition problem for now. |
See https://fsprojects.github.io/Fabulous/Fabulous.XamarinForms/migration-guide-to-0.50.html for a detailed list of changes. |
v2 comes with a strongly-typed DSL now :) |
I have been playing with Fabulous lately and I got many bugs that could have been avoided if the View API had better type-safety, this is what simple-elements is trying to solve but even then it's still flaky,
Related to #139
ViewElement composition
Right now, you can use
ViewElement
virtually everywhere but you will get runtime exceptions: "The specified cast is not allowed" if you used aViewElement
in an "incorrect" place which doesn't tell you where it went wrong and is very problematic:IGestureRecognizer
and have specific gesture elements implement itgestureRecognizers
attribute will then accept typeIGestureRecognizer list
content
of anotherContentPage
)IPage
to for page elementView.NavigationPage(...)
returnsIPage
View.ContentPage(...)
returnsIPage
pages
ofView.NavigationPage
must acceptIPage list
content
ofView.ContentPage
must acceptViewElement list
View.SwitchCell
inside the children ofView.StackLayout
(probably other types ofCell
descendants)Attribute type-safety: remove
obj
attributesThickness
View.Image
as ImageSourceView.Grid
asRowDefinition list
View.Grid
asColumnDefinition list
commandParamter
attribute because it doesn't do anythingRestrict ViewElement extension methods
All
ViewElement
values share the same extension methods which is really weird, for example you can have:I am not sure if this gives exceptions but I am pretty sure it is incorrect
The text was updated successfully, but these errors were encountered: