Skip to content

Commit

Permalink
Merge pull request #219 from fabulous-dev/avalonia-update
Browse files Browse the repository at this point in the history
Avalonia 11.0.9 update
  • Loading branch information
edgarfgp authored Feb 9, 2024
2 parents 6345ca7 + 6c9f761 commit 0800b91
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 169 deletions.
22 changes: 11 additions & 11 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
<PackageVersion Include="NUnit" Version="3.13.3" />
<PackageVersion Include="FsUnit" Version="5.2.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="Avalonia" Version="11.0.7" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.0.7" />
<PackageVersion Include="Avalonia.Android" Version="11.0.7" />
<PackageVersion Include="Avalonia.iOS" Version="11.0.7" />
<PackageVersion Include="Avalonia.Desktop" Version="11.0.7" />
<PackageVersion Include="Avalonia.Browser" Version="11.0.7" />
<PackageVersion Include="Avalonia.Skia" Version="11.0.7" />
<PackageVersion Include="Avalonia.Controls.ItemsRepeater" Version="11.0.7" />
<PackageVersion Include="Avalonia.Controls.ColorPicker" Version="11.0.7" />
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.0.7" />
<PackageVersion Include="Avalonia.Controls.TreeDataGrid" Version="11.0.1" />
<PackageVersion Include="Avalonia" Version="11.0.9" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.0.9" />
<PackageVersion Include="Avalonia.Android" Version="11.0.9" />
<PackageVersion Include="Avalonia.iOS" Version="11.0.9" />
<PackageVersion Include="Avalonia.Desktop" Version="11.0.9" />
<PackageVersion Include="Avalonia.Browser" Version="11.0.9" />
<PackageVersion Include="Avalonia.Skia" Version="11.0.9" />
<PackageVersion Include="Avalonia.Controls.ItemsRepeater" Version="11.0.9" />
<PackageVersion Include="Avalonia.Controls.ColorPicker" Version="11.0.9" />
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.0.9" />
<PackageVersion Include="Avalonia.Controls.TreeDataGrid" Version="11.0.2" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions extensions/Fabulous.Avalonia.ColorPicker/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
_No unreleased changes_

## [2.4.0-pre1] - 2024-02-09
### Changed
- Update to use version 11.0.9

## [2.3.0] - 2024-01-17
### Added
- No changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<Compile Include="ColorPreviewer.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia.Controls.ColorPicker" VersionOverride="11.0.7" />
<PackageReference Include="Avalonia.Controls.ColorPicker" VersionOverride="11.0.9" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions extensions/Fabulous.Avalonia.DataGrid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
_No unreleased changes_

## [2.4.0-pre1] - 2024-02-09
### Changed
- Update to use version 11.0.9

## [2.3.0] - 2024-01-17
### Added
- No changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<Compile Include="DataGrid.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia.Controls.DataGrid" VersionOverride="11.0.7" />
<PackageReference Include="Avalonia.Controls.DataGrid" VersionOverride="11.0.9" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions extensions/Fabulous.Avalonia.ItemsRepeater/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
_No unreleased changes_

## [2.4.0-pre1] - 2024-02-09
### Changed
- Update to use version 11.0.9

## [2.3.0] - 2024-01-17
### Added
- No changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<Compile Include="ItemsRepeater.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia.Controls.ItemsRepeater" VersionOverride="11.0.7" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" VersionOverride="11.0.9" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions extensions/Fabulous.Avalonia.TreeDataGrid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
_No unreleased changes_

## [2.4.0-pre1] - 2024-02-09
### Changed
- Update to use version 11.0.2

## [2.3.0] - 2024-01-17
### Added
- No changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<Compile Include="TreeDataGrid.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia.Controls.TreeDataGrid" VersionOverride="11.0.1" />
<PackageReference Include="Avalonia.Controls.TreeDataGrid" VersionOverride="11.0.2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
Expand Down
190 changes: 48 additions & 142 deletions samples/Gallery/Pages/TransitioningContentControlPage.fs
Original file line number Diff line number Diff line change
@@ -1,96 +1,26 @@
namespace Gallery

open System
open System.Collections.Generic
open System.Diagnostics
open System.Threading
open System.Threading.Tasks
open Avalonia
open Avalonia.Animation
open Avalonia.Controls
open Avalonia.Layout
open Avalonia.Media
open Avalonia.Media.Imaging
open Avalonia.Styling
open Avalonia.VisualTree
open Fabulous.Avalonia
open Fabulous
open Avalonia.Animation.Easings

type PageTransition(displayTitle: string) =
let _transition: IPageTransition = null

member val Transition = _transition with get, set

member val DisplayTitle = displayTitle

override this.ToString() = this.DisplayTitle

type CustomTransition(duration) =

let mutable _duration: TimeSpan = Unchecked.defaultof<_>
member val Duration = _duration with get, set

member this.GetVisualParent(from: Visual, to': Visual) =
let p1 = from.GetVisualParent()
let p2 = to'.GetVisualParent()

if p1 <> null && p2 <> null && p1 <> p2 then
raise(ArgumentException("Controls for PageSlide must have same parent."))

if p1 = null then
raise(InvalidOperationException("Cannot determine visual parent."))
else
p1

interface IPageTransition with
member this.Start(from: Visual, to': Visual, forward: bool, cancellationToken: CancellationToken) =
task {
if cancellationToken.IsCancellationRequested then
()
else
let tasks = List<Task>()
let parent = this.GetVisualParent(from, to')
let scaleProperty = ScaleTransform.ScaleYProperty

if from <> null then
let animation = Animation()
let keyFrame = KeyFrame()
keyFrame.Setters.AddRange [ Setter(Property = scaleProperty, Value = 1.) ]
keyFrame.Cue <- Cue(0.)
let keyFrame' = KeyFrame()
keyFrame'.Setters.AddRange [ Setter(Property = scaleProperty, Value = 0.) ]
keyFrame'.Cue <- Cue(1.)
animation.Children.AddRange([ keyFrame; keyFrame' ])
animation.Duration <- this.Duration
tasks.Add(animation.RunAsync(from, cancellationToken))

if to' <> null then
let animation = Animation()
let keyFrame = KeyFrame()
keyFrame.Setters.AddRange [ Setter(Property = scaleProperty, Value = 0.) ]
keyFrame.Cue <- Cue(0.)
let keyFrame' = KeyFrame()
keyFrame'.Setters.AddRange [ Setter(Property = scaleProperty, Value = 1.) ]
keyFrame'.Cue <- Cue(1.)
animation.Children.AddRange([ keyFrame; keyFrame' ])
animation.Duration <- this.Duration
tasks.Add(animation.RunAsync(to', cancellationToken))

do! Task.WhenAll(tasks)

if from <> null && not cancellationToken.IsCancellationRequested then
from.IsVisible <- false
}

open type Fabulous.Avalonia.View

module TransitioningContentControlPage =
type Model =
{ Images: Bitmap list
SelectedImage: Bitmap
PageTransitions: PageTransition list
SelectedTransition: PageTransition
Duration: float option
{ Images: string list
SelectedImage: string
PageTransition: IPageTransition
IsReverse: bool
Transitions: string list
Duration: float
ClipToBounds: bool }

type Msg =
Expand All @@ -99,60 +29,23 @@ module TransitioningContentControlPage =
| TransitionChanged of SelectionChangedEventArgs
| DurationChanged of float option
| ClipToBoundsChanged of bool
| TransitionsUpdated of PageTransition list

type CmdMsg = SettingUpTransitions of PageTransition list * int

let updateTransitions (pageTransitions: PageTransition list) duration =
let transitions =
pageTransitions
|> List.mapi(fun index value ->
match index with
| 1 -> value.Transition <- CrossFade(TimeSpan.FromMilliseconds(duration))
| 2 -> value.Transition <- PageSlide(TimeSpan.FromMilliseconds(duration), PageSlide.SlideAxis.Horizontal) :> IPageTransition
| 3 -> value.Transition <- PageSlide(TimeSpan.FromMilliseconds(duration), PageSlide.SlideAxis.Vertical) :> IPageTransition
| 4 ->
let compositeTransition = CompositePageTransition()
compositeTransition.PageTransitions.Add(pageTransitions[1].Transition)
compositeTransition.PageTransitions.Add(pageTransitions[2].Transition)
compositeTransition.PageTransitions.Add(pageTransitions[3].Transition)
value.Transition <- compositeTransition :> IPageTransition
| 5 -> value.Transition <- CustomTransition(TimeSpan.FromMilliseconds(duration)) :> IPageTransition
| _ -> value.Transition <- null

value)

TransitionsUpdated transitions
| ReverseChanged of bool

type CmdMsg = | NoCmdMsg

let mapCmdMsgToCmd cmdMsg =
match cmdMsg with
| SettingUpTransitions(pageTransitions, i) -> Cmd.ofMsg(updateTransitions pageTransitions i)

let pageTransitions =
[ PageTransition("None")
PageTransition("CrossFade")
PageTransition("Slide horizontally")
PageTransition("Slide vertically")
PageTransition("Composite")
PageTransition("Custom") ]
| NoCmdMsg -> Cmd.none

let init () =
let images = [ "fabulous-icon.png"; "fsharp-icon.png"; "fabulous-icon.png" ]

let images =
images
|> List.map(fun image ->
let path = $"avares://Gallery/Assets/Icons/{image}"
ImageSource.fromString path)

{ Images = images
SelectedImage = images[0]
SelectedTransition = pageTransitions[0]
PageTransitions = pageTransitions
Duration = Some 250.
{ Images = [ "fabulous-icon.png"; "fsharp-icon.png"; "fabulous-icon.png" ]
SelectedImage = "fabulous-icon.png"
PageTransition = PageSlide(TimeSpan.FromSeconds(250.), PageSlide.SlideAxis.Horizontal)
Transitions = [ "Slide"; "CrossFade"; "3D Rotation"; "Composite" ]
Duration = 250.
IsReverse = false
ClipToBounds = false },
[ SettingUpTransitions(pageTransitions, 500) ]
[]

let update msg model =
match msg with
Expand All @@ -161,7 +54,7 @@ module TransitioningContentControlPage =
let index = (index + 1) % model.Images.Length

{ model with
SelectedImage = model.Images[index] },
SelectedImage = model.Images.[index] },
[]

| PrevImage ->
Expand All @@ -170,12 +63,12 @@ module TransitioningContentControlPage =
let index = if index < 0 then model.Images.Length - 1 else index

{ model with
SelectedImage = model.Images[index] },
SelectedImage = model.Images.[index] },
[]

| DurationChanged duration ->
let duration = duration |> Option.defaultValue 500
{ model with Duration = Some duration }, [ SettingUpTransitions(model.PageTransitions, int duration) ]
{ model with Duration = duration }, []

| ClipToBoundsChanged clipToBounds ->
{ model with
Expand All @@ -185,23 +78,31 @@ module TransitioningContentControlPage =
| TransitionChanged selection ->
let control = selection.Source :?> ComboBox
let selectedItem = control.SelectedIndex
let selection = control.Items[selectedItem] :?> string
let selection = control.Items.[selectedItem] :?> string

let transition =
match selection with
| "Slide" -> PageSlide(TimeSpan.FromMilliseconds(model.Duration), PageSlide.SlideAxis.Horizontal) :> IPageTransition
| "CrossFade" -> CrossFade(TimeSpan.FromSeconds(model.Duration))
| "3D Rotation" -> Rotate3DTransition(TimeSpan.FromSeconds(model.Duration), PageSlide.SlideAxis.Horizontal)
| "Composite" ->
let crossFade = CrossFade(TimeSpan.FromSeconds(model.Duration))
crossFade.FadeInEasing <- BounceEaseIn()
crossFade.FadeOutEasing <- BounceEaseOut()

let selectedTransition =
model.PageTransitions |> List.tryFind(fun x -> x.DisplayTitle = selection)
let compositePageTransition = CompositePageTransition()
compositePageTransition.PageTransitions.Add(Rotate3DTransition(TimeSpan.FromSeconds(model.Duration), PageSlide.SlideAxis.Horizontal))
compositePageTransition.PageTransitions.Add(crossFade)
compositePageTransition

match selectedTransition with
| None -> model, []
| Some value ->
{ model with
SelectedTransition = selectedTransition.Value },
[]
| _ -> PageSlide(TimeSpan.FromSeconds(model.Duration), PageSlide.SlideAxis.Horizontal)

| TransitionsUpdated pageTransitions ->
{ model with
PageTransitions = pageTransitions },
PageTransition = transition },
[]

| ReverseChanged isReverse -> { model with IsReverse = isReverse }, []

let program =
Program.statefulWithCmdMsg init update mapCmdMsgToCmd
|> Program.withTrace(fun (format, args) -> Debug.WriteLine(format, box args))
Expand All @@ -227,15 +128,15 @@ module TransitioningContentControlPage =
(HStack(5.) {
HeaderedContentControl(
"Select a transition",
ComboBox(model.PageTransitions |> List.map(_.DisplayTitle), (fun x -> TextBlock(x)))
ComboBox(model.Transitions, (fun x -> TextBlock(x)))
.selectedIndex(0)
.onSelectionChanged(TransitionChanged)
.verticalAlignment(VerticalAlignment.Center)
)

HeaderedContentControl(
"Duration",
NumericUpDown(100., 1000., model.Duration, DurationChanged)
NumericUpDown(100., 1000., Some model.Duration, DurationChanged)
.increment(250.)
.verticalAlignment(VerticalAlignment.Center)
)
Expand Down Expand Up @@ -263,9 +164,14 @@ module TransitioningContentControlPage =

Button(">", NextImage).dock(Dock.Right)

CheckBox("Reverse", model.IsReverse, ReverseChanged)
.dock(Dock.Bottom)
.margin(5.)

Border(
TransitioningContentControl(Image(model.SelectedImage))
.pageTransition(model.SelectedTransition.Transition)
TransitioningContentControl(Image($"avares://Gallery/Assets/Icons/{model.SelectedImage}"))
.pageTransition(model.PageTransition)
.isTransitionReversed(model.IsReverse)
.size(200., 200.)
)
.margin(5.)
Expand Down
Loading

0 comments on commit 0800b91

Please sign in to comment.