Skip to content

Commit

Permalink
Merge pull request #8 from fabulous-dev/fixes
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
TimLariviere authored Feb 9, 2023
2 parents 76cc4f8 + 57a11c7 commit 4af01f3
Show file tree
Hide file tree
Showing 50 changed files with 663 additions and 117 deletions.
Binary file added Rider_LiveTemplates.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions samples/CounterApp/CounterApp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Fabulous.Maui.Controls\Fabulous.Maui.Controls.csproj" />
<ProjectReference Include="..\..\src\Fabulous.Maui\Fabulous.Maui.fsproj" />
<ProjectReference Include="..\..\src\Microsoft.Maui.FabCompat\Microsoft.Maui.FabCompat.csproj" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions samples/Gallery/Gallery.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Fabulous.Maui.Controls\Fabulous.Maui.Controls.csproj" />
<ProjectReference Include="..\..\src\Fabulous.Maui\Fabulous.Maui.fsproj" />
<ProjectReference Include="..\..\src\Microsoft.Maui.FabCompat\Microsoft.Maui.FabCompat.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion samples/HelloWorld/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module App =
.centerHorizontal()

// Compatibility button
Button(model.ButtonText, Increment)
TextButton(model.ButtonText, Increment)
//.style(Styles.textButton)
//.semantics(Semantics(Hint = "Counts the number of times you click"))
.centerHorizontal()
Expand Down
2 changes: 2 additions & 0 deletions samples/HelloWorld/HelloWorld.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Fabulous.Maui.Controls\Fabulous.Maui.Controls.csproj" />
<ProjectReference Include="..\..\src\Fabulous.Maui\Fabulous.Maui.fsproj" />
<ProjectReference Include="..\..\src\Microsoft.Maui.FabCompat\Microsoft.Maui.FabCompat.csproj" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions src/Fabulous.Maui.Controls/AttachedDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public static class AttachedData
{
public static Func<IView, string, object?, object?>? Get;
public static Action<IView, string, object>? Set;
public static Action<IView, string>? Clear;
}

public static class AttachedDataExtensions
Expand All @@ -19,4 +20,9 @@ public static void SetAttachedData<T>(this IView view, string key, T value)
{
AttachedData.Set?.Invoke(view, key, value);
}

public static void ClearAttachedData<T>(this IView view, string key)
{
AttachedData.Clear?.Invoke(view, key);
}
}
2 changes: 1 addition & 1 deletion src/Fabulous.Maui.Controls/Controls/FabImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Fabulous.Maui
{
public interface IFabImage : IImage, IFabView, IFabImageSourcePart
public interface IFabImage : Microsoft.Maui.IImage, IFabView, IFabImageSourcePart
{
void SetIsAnimationPlaying(bool value);
void SetAspect(Aspect value);
Expand Down
8 changes: 7 additions & 1 deletion src/Fabulous.Maui.Controls/Controls/FabTextButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public class FabTextButton : FabButton, IFabTextButton
public void SetTextColor(Color? value) => TextColor = value;
public void SetFont(Font value) => Font = value;
public void SetCharacterSpacing(double value) => CharacterSpacing = value;
public void SetText(string value) => Text = value;

public void SetText(string value)
{
if (Text == value) return;
Text = value;
InvalidateMeasure();
}
}
}
26 changes: 13 additions & 13 deletions src/Fabulous.Maui.Controls/FabWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ namespace Fabulous.Maui
{
public interface IFabWindow : IWindow, IFabTitledElement
{
void SetOnCreated(Action? value);
void SetOnResumed(Action? value);
void SetContent(IView value);
void SetFlowDirection(FlowDirection value);
void SetHeight(double value);
void SetMaximumHeight(double value);
void SetMaximumWidth(double value);
void SetMinimumWidth(double value);
void SetMinimumHeight(double value);
void SetOnActivated(Action? value);
void SetOnBackButtonClicked(Func<bool>? value);
void SetOnBackgrounding(Action<IPersistedState>? value);
void SetOnCreated(Action? value);
void SetOnDeactivated(Action? value);
void SetOnStopped(Action? value);
void SetOnDestroying(Action? value);
void SetOnBackgrounding(Action<IPersistedState>? value);
void SetOnBackButtonClicked(Func<bool>? value);
void SetOnDisplayDensityChanged(Action<float>? value);
void SetOnFrameChanged(Action<Microsoft.Maui.Graphics.Rect>? value);
void SetContent(IView value);
void SetOnResumed(Action? value);
void SetOnStopped(Action? value);
void SetVisualDiagnosticsOverlay(IVisualDiagnosticsOverlay value);
void SetWidth(double value);
void SetX(double value);
void SetY(double value);
void SetWidth(double value);
void SetMinimumWidth(double value);
void SetMaximumWidth(double value);
void SetHeight(double value);
void SetMinimumHeight(double value);
void SetMaximumHeight(double value);
void SetFlowDirection(FlowDirection value);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Fabulous.Maui.Controls/Fabulous.Maui.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<UseMauiCore>true</UseMauiCore>
<UseMaui>true</UseMaui>
<UseMauiEssentials>true</UseMauiEssentials>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Fabulous\src\Fabulous\Fabulous.fsproj" />
<ProjectReference Include="..\Microsoft.Maui.FabCompat\Microsoft.Maui.FabCompat.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Fabulous" VersionOverride="[2.2.0, 2.3.0)" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Fabulous.Maui.Controls/Layouts/Partials/FabLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Fabulous.Maui
{
public interface IFabLayout : ILayout, IFabView, IFabContainer, IFabSafeAreaView, IFabPadding
public interface IFabLayout : Microsoft.Maui.ILayout, IFabView, IFabContainer, IFabSafeAreaView, IFabPadding
{
void SetClipsToBounds(bool value);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Fabulous.Maui.Controls/Partials/FabElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ namespace Fabulous.Maui
{
public interface IFabElement : IElement
{
IViewNode ViewNode { get; set; }
T? GetAttachedData<T>(string key, T? defaultValue);
void SetAttachedData<T>(string key, T value);
}
}

namespace Fabulous.Maui.Controls
{
public abstract class FabElement: IFabElement
public abstract class FabElement: Microsoft.Maui.Controls.View, IFabElement
{
private IElementHandler? _handler;

Expand Down
2 changes: 2 additions & 0 deletions src/Fabulous.Maui.Controls/Partials/FabView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Microsoft.Maui.Primitives;
using Microsoft.Maui.Handlers.Defaults;

using LayoutAlignment = Microsoft.Maui.Primitives.LayoutAlignment;

namespace Fabulous.Maui
{
public interface IFabView : IView, IFabElement, IFabTransform
Expand Down
57 changes: 48 additions & 9 deletions src/Fabulous.Maui/AppHostBuilderExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ namespace Fabulous.Maui
open System.Runtime.CompilerServices
open Fabulous.Maui.Compatibility
open Microsoft.Extensions.DependencyInjection.Extensions
open Microsoft.Extensions.DependencyInjection
open Microsoft.Maui
open Microsoft.Maui.Controls
open Microsoft.Maui.Controls.Internals
open Microsoft.Maui.FabCompat.Handlers
open Microsoft.Maui.Graphics
open Microsoft.Maui.Handlers
open Microsoft.Maui.Handlers.Defaults
open Microsoft.Maui.Hosting
open Microsoft.Maui.Controls.Hosting
open Fabulous
open Fabulous.Maui.Controls
open Microsoft.Maui.Layouts
open Microsoft.Maui.Handlers
open Microsoft.Maui.Hosting
open Microsoft.Maui.Platform

module FabulousHandlers =
module AttachedData =
let getBindablePropertyByKey (key: string) =
match key with
| FabGridLayoutAttachedDataKeys.Column -> Microsoft.Maui.Controls.Grid.ColumnProperty
Expand All @@ -21,22 +29,48 @@ module FabulousHandlers =
| FabGridLayoutAttachedDataKeys.RowSpan -> Microsoft.Maui.Controls.Grid.RowSpanProperty
| _ -> failwith $"Unknown key {key}"

let getDefaultValueByKey (key: string) =
match key with
| FabGridLayoutAttachedDataKeys.Column -> box GridLayoutDefaults.Column
| FabGridLayoutAttachedDataKeys.ColumnSpan -> box GridLayoutDefaults.ColumnSpan
| FabGridLayoutAttachedDataKeys.Row -> box GridLayoutDefaults.Row
| FabGridLayoutAttachedDataKeys.RowSpan -> box GridLayoutDefaults.RowSpan
| FabCompatAbsoluteLayoutAttachedDataKeys.LayoutBounds -> box Rect.Zero
| FabCompatAbsoluteLayoutAttachedDataKeys.LayoutFlags -> box AbsoluteLayoutFlags.None
| _ -> failwith $"Unknown key {key}"

let getAttachedData (view: IView) (key: string) (defaultValue: obj) =
match view with
| :? IFabView as fabView -> fabView.GetAttachedData(key, defaultValue)
| :? IFabCompatView as fabCompatView ->
| :? IFabElement as element -> element.GetAttachedData(key, defaultValue)
| :? BindableObject as bindable ->
let bindableProperty = getBindablePropertyByKey key
(fabCompatView :?> BindableObject).GetValue(bindableProperty)
bindable.GetValue(bindableProperty)
| _ -> failwith $"Unknown view type {view.GetType().Name}"

let setAttachedData (view: IView) (key: string) (value: obj) =
match view with
| :? IFabView as fabView -> fabView.SetAttachedData(key, value)
| :? IFabCompatView as fabCompatView ->
| :? IFabElement as element -> element.SetAttachedData(key, value)
| :? BindableObject as bindable ->
let bindableProperty = getBindablePropertyByKey key
(fabCompatView :?> BindableObject).SetValue(bindableProperty, value)
bindable.SetValue(bindableProperty, value)
| _ -> failwith $"Unknown view type {view.GetType().Name}"

let clearAttachedData (view: IView) (key: string) =
match view with
| :? IFabElement as element ->
let defaultValue = getDefaultValueByKey key
element.SetAttachedData(key, defaultValue)
| :? BindableObject as bindable ->
let bindableProperty = getBindablePropertyByKey key
bindable.ClearValue(bindableProperty)
| _ -> failwith $"Unknown view type {view.GetType().Name}"

let init () =
AttachedData.Get <- System.Func<_, _, _, _>(getAttachedData)
AttachedData.Set <- System.Action<_, _, _>(setAttachedData)
AttachedData.Clear <- System.Action<_, _>(clearAttachedData)

module FabulousHandlers =
let register (collection: IMauiHandlersCollection) =
collection
.AddMauiControlsHandlers()
Expand All @@ -62,6 +96,10 @@ module FabulousHandlers =
.AddHandler<FabWindow, WindowHandler>()
.AddHandler<FabNavigationStack, FabNavigationViewHandler>()
|> ignore

type FakeResourceProvider() =
interface ISystemResourcesProvider with
member this.GetSystemResources() = ResourceDictionary()

[<Extension>]
type AppHostBuilderExtensions =
Expand All @@ -73,8 +111,9 @@ type AppHostBuilderExtensions =
program: Program<'args, 'model, 'msg, 'marker>,
args: 'args
) =
AttachedData.Get <- System.Func<_, _, _, _>(FabulousHandlers.getAttachedData)
AttachedData.Set <- System.Action<_, _, _>(FabulousHandlers.setAttachedData)
AttachedData.init()

DependencyService.Register<FakeResourceProvider>();

this.ConfigureMauiHandlers(FabulousHandlers.register) |> ignore

Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous.Maui/Compatibility/Attributes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ module Attributes =
| ValueSome { Light = light; Dark = dark } -> target.SetAppTheme(bindableProperty, light.ToMauiColor(), dark.ToMauiColor()))

/// Define an attribute storing a Widget for a bindable property
let inline defineBindableWidget (bindableProperty: BindableProperty) =
let defineBindableWidget (bindableProperty: BindableProperty) =
Attributes.definePropertyWidget
bindableProperty.PropertyName
(fun target -> (target :?> BindableObject).GetValue(bindableProperty))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module CarouselView =
module CarouselViewBuilders =
type Fabulous.Maui.View with

static member inline CarouselView<'msg, 'itemData, 'itemMarker when 'itemMarker :> IFabCompatView>(items: seq<'itemData>) =
static member inline CarouselView<'msg, 'itemData, 'itemMarker when 'itemMarker :> IFabView>(items: seq<'itemData>) =
WidgetHelpers.buildItems<'msg, IFabCompatCarouselView, 'itemData, 'itemMarker> CarouselView.WidgetKey ItemsView.ItemsSource items

[<Extension>]
Expand Down
2 changes: 2 additions & 0 deletions src/Fabulous.Maui/Compatibility/Views/CompatApplication.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System
open System.Runtime.CompilerServices
open Fabulous
open Fabulous.Maui
open Microsoft.Maui
open Microsoft.Maui.Controls
open Microsoft.Maui.ApplicationModel

Expand Down Expand Up @@ -31,6 +32,7 @@ type CompatApplication() =

type IFabCompatApplication =
inherit IFabCompatElement
inherit IApplication

module CompatApplication =
let WidgetKey = CompatWidgets.register<CompatApplication>()
Expand Down
Loading

0 comments on commit 4af01f3

Please sign in to comment.