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

Port the ShapeDemos sample #782

Merged
merged 20 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Expander =

let expanderView model dispatch =
let loadEmbeddedImage path =
ImageSrc (ImageSource.FromResource((sprintf "AllControls.%s" path), typeof<Msg>.Assembly))
Image.fromImageSource (ImageSource.FromResource((sprintf "AllControls.%s" path), typeof<Msg>.Assembly))

View.NonScrollingContentPage(
title = "Expander sample",
Expand All @@ -34,7 +34,7 @@ module Expander =
View.Label(
text = "Baboon",
fontAttributes = FontAttributes.Bold,
fontSize = Named NamedSize.Medium
fontSize = FontSize.fromNamedSize NamedSize.Medium
)
View.Image(
source = (if model.IsExpanded then loadEmbeddedImage "collapse.png" else loadEmbeddedImage "expand.png"),
Expand All @@ -48,7 +48,7 @@ module Expander =
coldefs = [ Auto; Auto ],
children = [
View.Image(
source = ImagePath "http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg",
source = Image.fromPath "http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg",
aspect = Aspect.AspectFill,
height = 120.,
width = 120.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module MediaElement =
title = "MediaElement sample",
content =
View.MediaElement(
source = MediaPath "https://sec.ch9.ms/ch9/9888/66d91d60-565a-4854-9b2b-80a7148d9888/EliteKit_mid.mp4",
source = Media.fromPath "https://sec.ch9.ms/ch9/9888/66d91d60-565a-4854-9b2b-80a7148d9888/EliteKit_mid.mp4",
autoPlay = true,
showsPlaybackControls = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module FFImageLoading =
View.Label "Note, when last checked this did not work on Android"
View.Label "However maybe the sample is not configured correctly"
View.CachedImage(
source = ImagePath "http://loremflickr.com/600/600/nature?filename=simple.jpg",
source = Image.fromPath "http://loremflickr.com/600/600/nature?filename=simple.jpg",
//loadingPlaceholder = Path "path/to/loading-placeholder.png",
//errorPlaceholder = Path "path/to/error-placeholder.png",
height = 600.,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ module TabbedPage1 =
content = View.StackLayout([
View.Label(text = "Image (URL):")
View.Image(
source = ImagePath "http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg",
source = Image.fromPath "http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg",
horizontalOptions = LayoutOptions.Fill,
verticalOptions = LayoutOptions.FillAndExpand
)
Expand All @@ -217,7 +217,7 @@ module TabbedPage1 =
margin = Thickness (0., 20., 0., 0.)
)
View.Image(
source = ImageSrc (ImageSource.FromResource("AllControls.Baboon_Serengeti.jpg", typeof<Msg>.Assembly)),
source = Image.fromImageSource (ImageSource.FromResource("AllControls.Baboon_Serengeti.jpg", typeof<Msg>.Assembly)),
horizontalOptions = LayoutOptions.Fill,
verticalOptions = LayoutOptions.FillAndExpand
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module TabbedPage2 =
)
View.Span(
text = "Studio ",
fontSize = FontSize 10.
fontSize = FontSize.fromValue 10.
)
])
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module TabbedPage3 =
View.Label(
text = "Seated Monkey",
margin = Thickness (0.0, 8.0),
fontSize = Named NamedSize.Large,
fontSize = FontSize.fromNamedSize NamedSize.Large,
textColor = Color.Blue
)
View.Label(
Expand All @@ -46,14 +46,14 @@ module TabbedPage3 =
View.Image(
height = 240.0,
width = 160.0,
source = ImagePath "https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/Vervet_monkey_Krugersdorp_game_reserve_%285657678441%29.jpg/160px-Vervet_monkey_Krugersdorp_game_reserve_%285657678441%29.jpg"
source = Image.fromPath "https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/Vervet_monkey_Krugersdorp_game_reserve_%285657678441%29.jpg/160px-Vervet_monkey_Krugersdorp_game_reserve_%285657678441%29.jpg"
).Order(-1)
.AlignSelf(FlexAlignSelf.Center)

View.Label(margin = Thickness (0.0, 4.0)).Grow(1.0)
View.Button(
text = "Learn More",
fontSize = Named NamedSize.Large,
fontSize = FontSize.fromNamedSize NamedSize.Large,
textColor = Color.White,
backgroundColor = Color.Green,
cornerRadius = 20
Expand All @@ -75,7 +75,7 @@ module TabbedPage3 =
View.Label(
text = "Banana Monkey",
margin = Thickness (0.0, 8.0),
fontSize = Named NamedSize.Large,
fontSize = FontSize.fromNamedSize NamedSize.Large,
textColor = Color.Blue
)
View.Label(
Expand All @@ -96,14 +96,14 @@ module TabbedPage3 =
View.Image(
height = 213.0,
width = 320.0,
source = ImagePath "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Crab_eating_macaque_in_Ubud_with_banana.JPG/320px-Crab_eating_macaque_in_Ubud_with_banana.JPG"
source = Image.fromPath "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Crab_eating_macaque_in_Ubud_with_banana.JPG/320px-Crab_eating_macaque_in_Ubud_with_banana.JPG"
).Order(-1)
.AlignSelf(FlexAlignSelf.Center)

View.Label(margin = Thickness (0.0, 4.0)).Grow(1.0)
View.Button(
text = "Learn More",
fontSize = Named NamedSize.Large,
fontSize = FontSize.fromNamedSize NamedSize.Large,
textColor = Color.White,
backgroundColor = Color.Green,
cornerRadius = 20
Expand Down Expand Up @@ -183,7 +183,7 @@ module TabbedPage3 =
children = [
View.Label(
text = "AbsoluteLayout Demo",
fontSize = Named NamedSize.Large,
fontSize = FontSize.fromNamedSize NamedSize.Large,
horizontalOptions = LayoutOptions.Center
)
View.AbsoluteLayout(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ module Effects =
View.ScrollingContentPage(
title = "Effects sample",
content = View.StackLayout([
View.Label("Focus effect (no properties)", fontSize=Named NamedSize.Large)
View.Label("Focus effect (no properties)", fontSize=FontSize.fromNamedSize NamedSize.Large)
View.Label("Classic Entry field", margin=Thickness (0., 15., 0., 0.))
View.Entry()
View.Label("Entry field with Focus effect", margin=Thickness (0., 15., 0., 0.))
View.Entry(effects = [
View.Effect("FabulousXamarinForms.FocusEffect")
])

View.Label("Shadow effect (with properties)", fontSize=Named NamedSize.Large, margin=Thickness (0., 30., 0., 0.))
View.Label("Shadow effect (with properties)", fontSize=FontSize.fromNamedSize NamedSize.Large, margin=Thickness (0., 30., 0., 0.))
View.Label("Classic Label field", margin=Thickness (0., 15., 0., 0.))
View.Label("This is a label without shadows")
View.Label("Label field with Shadow effect", margin=Thickness (0., 15., 0., 0.))
Expand Down
26 changes: 13 additions & 13 deletions Fabulous.XamarinForms/samples/Calculator/Calculator/Calculator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open Fabulous.XamarinForms.LiveUpdate
open Xamarin.Forms

module App =
type Operator = Add | Subtract | Multiply | Divide
type Operator = Add | Subtract | Multiply | Divide

/// Represents a calculator button press
type Msg =
Expand Down Expand Up @@ -61,7 +61,7 @@ module App =
match model with
| Initial | Error -> model
| Result operand // previously calculated result is now the first operand
| Operand operand | OperandOperator (operand, _) -> OperandOperator(operand, operator)
| Operand operand | OperandOperator (operand, _) -> OperandOperator(operand, operator)
| OperandOperatorOperand _ -> calculate model msg
| Equals -> calculate model msg

Expand All @@ -77,7 +77,7 @@ module App =
View.Button(text = text, command=(fun () -> dispatch command))
.Row(row)
.Column(column)
.FontSize(FontSize 36.0)
.FontSize(FontSize.fromValue 36.0)
//.ButtonCornerRadius(0)

let mkNumberButton number row column =
Expand All @@ -91,12 +91,12 @@ module App =
let mkOperatorButton text operator row column =
(mkButton text (Operator operator) row column)
.BackgroundColor(orange)
.TextColor(Color.Black)
.TextColor(Color.Black)

View.ContentPage(
View.Grid(rowdefs=[ Star; Star; Star; Star; Star; Star ], coldefs=[ Star; Star; Star; Star ],
children=[
View.Label(text = display model, fontSize = FontSize 48.0, fontAttributes = FontAttributes.Bold, backgroundColor = Color.Black, textColor = Color.White, horizontalTextAlignment = TextAlignment.End, verticalTextAlignment = TextAlignment.Center).ColumnSpan(4)
View.Label(text = display model, fontSize = FontSize.fromValue 48.0, fontAttributes = FontAttributes.Bold, backgroundColor = Color.Black, textColor = Color.White, horizontalTextAlignment = TextAlignment.End, verticalTextAlignment = TextAlignment.Center).ColumnSpan(4)
mkNumberButton 7 1 0; mkNumberButton 8 1 1; mkNumberButton 9 1 2
mkNumberButton 4 2 0; mkNumberButton 5 2 1; mkNumberButton 6 2 2
mkNumberButton 1 3 0; mkNumberButton 2 3 1; mkNumberButton 3 3 2
Expand All @@ -112,11 +112,11 @@ module App =
)
)

let program =
let program =
Program.mkSimple (fun() -> Initial) update view
|> Program.withConsoleTrace

type CalculatorApp () as app =
type CalculatorApp () as app =
inherit Application ()

let runner = App.program |> XamarinFormsProgram.run app
Expand All @@ -128,18 +128,18 @@ type CalculatorApp () as app =

#if SAVE_MODEL_WITH_JSON
let modelId = "model"
override __.OnSleep() =
override __.OnSleep() =

let json = Newtonsoft.Json.JsonConvert.SerializeObject(runner.CurrentModel)
Debug.WriteLine("OnSleep: saving model into app.Properties, json = {0}", json)

app.Properties.[modelId] <- json

override __.OnResume() =
override __.OnResume() =
Debug.WriteLine "OnResume: checking for model in app.Properties"
try
try
match app.Properties.TryGetValue modelId with
| true, (:? string as json) ->
| true, (:? string as json) ->

Debug.WriteLine("OnResume: restoring model from app.Properties, json = {0}", json)
let model = Newtonsoft.Json.JsonConvert.DeserializeObject<App.Model>(json)
Expand All @@ -148,10 +148,10 @@ type CalculatorApp () as app =
runner.SetCurrentModel (model, Cmd.none)

| _ -> ()
with ex ->
with ex ->
App.program.onError("Error while restoring model found in app.Properties", ex)

override this.OnStart() =
override this.OnStart() =
Debug.WriteLine "OnStart: using same logic as OnResume()"
this.OnResume()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module CityView =
Temperature: int<kelvin>
WeatherKind: WeatherKind
HourlyForecast: HourlyForecastValue list }
type CityData =

type CityData =
{ Name: string
Data: WeatherData option
IsRefreshing: bool }
Expand All @@ -24,7 +24,7 @@ module CityView =
View.StackLayout([
View.Label(
text = cityName.ToUpper(),
fontSize = Named NamedSize.Title,
fontSize = FontSize.fromNamedSize NamedSize.Title,
horizontalOptions = LayoutOptions.Center,
padding = Thickness(0., 20., 0., 0.)
)
Expand All @@ -35,7 +35,7 @@ module CityView =
)
])
)

// View to display once we have data
let loadedView (cityIndex: int, cityName: string, isRefreshing: bool, data: WeatherData) requestRefresh =
dependsOn (cityName, isRefreshing, data) (fun _ (cityName, isRefreshing, data) ->
Expand All @@ -57,7 +57,7 @@ module CityView =
)
| _ ->
content

// UI
containerView <|
View.Grid(
Expand All @@ -70,34 +70,34 @@ module CityView =
horizontalOptions = LayoutOptions.Center,
padding = Thickness(0., 20., 0., 0.)
)

View.Image(
source = ImagePath (sprintf "%s.png" (cityName.Replace(" ", "_").ToLower())),
source = Image.fromPath (sprintf "%s.png" (cityName.Replace(" ", "_").ToLower())),
aspect = Aspect.AspectFit,
opacity = 0.8,
opacity = 0.8,
verticalOptions = LayoutOptions.FillAndExpand
).Row(1)

View.Label(
text = (Helpers.kelvinToRoundedFahrenheit data.Temperature).ToString() + "°",
margin = Thickness(30., 0., 0., 0.),
horizontalTextAlignment = TextAlignment.Center,
fontSize = Styles.CurrentTemperatureFontSize
).Row(2)

View.Label(
text = data.WeatherKind.ToString().ToUpper(),
fontSize = Styles.CurrentWeatherKindFontSize,
horizontalOptions = LayoutOptions.Center,
margin = Thickness(0., 10., 0., 0.)
).Row(3)

View.Label(
text = data.Date.ToString("dddd, MMMM dd, yyyy, h:mm tt").ToUpper(),
fontSize = Styles.CurrentDateFontSize,
horizontalOptions = LayoutOptions.Center
).Row(4)

View.StackLayout(
orientation = StackOrientation.Horizontal,
horizontalOptions = LayoutOptions.Center,
Expand All @@ -121,7 +121,7 @@ module CityView =
horizontalTextAlignment = TextAlignment.Center
)
View.Image(
source = ImagePath (sprintf "http://openweathermap.org/img/wn/%s@2x.png" forecast.IconName),
source = Image.fromPath (sprintf "http://openweathermap.org/img/wn/%s@2x.png" forecast.IconName),
aspect = Aspect.AspectFit,
horizontalOptions = LayoutOptions.Center,
verticalOptions = LayoutOptions.CenterAndExpand
Expand Down
Loading