Skip to content

Commit

Permalink
Merge pull request #192 from adospace/inject-prop-attributes-feature
Browse files Browse the repository at this point in the history
Inject prop attributes feature
  • Loading branch information
adospace authored Dec 27, 2023
2 parents 678a22b + d865247 commit 6337361
Show file tree
Hide file tree
Showing 15 changed files with 1,192 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
env:
Solution_Name: ./src/MauiReactor.Build.sln
TemplatePack_Name: ./src/MauiReactor.TemplatePack/MauiReactor.TemplatePack.csproj
Version: 2.0.10-beta
Version: 2.0.11-beta

steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions samples/MauiReactor.TestApp/MauiReactor.TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<SingleProject>true</SingleProject>
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>

<!-- Display name -->
<ApplicationTitle>MauiReactor.TestApp</ApplicationTitle>
Expand Down
237 changes: 112 additions & 125 deletions samples/MauiReactor.TestApp/Pages/CardsAnimationPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,148 +4,135 @@
using System.Text;
using System.Threading.Tasks;
using MauiReactor.Shapes;
using Microsoft.Maui.Controls;

namespace MauiReactor.TestApp.Pages
namespace MauiReactor.TestApp.Pages;

class Card
{
class Card
{
public int Index { get; init; }
public int Index { get; init; }

public int Position { get; set; }
public int Position { get; set; }

}
}

class AnimationPageState
{
public List<Card> Cards { get; set; } = Enumerable.Range(1, 10).Select(index => new Card { Index = index - 1, Position = index }).ToList();
}
class AnimationPageState
{
public List<Card> Cards { get; set; } = Enumerable.Range(1, 10).Select(index => new Card { Index = index - 1, Position = index }).ToList();
}

class CardsAnimationPage : Component<AnimationPageState>
class CardsAnimationPage : Component<AnimationPageState>
{
public override VisualNode Render()
{
public override VisualNode Render()
{
return ContentPage(
[
Grid(
State.Cards
.Select(card => new CardPage()
.Index(card.Index)
.Position(card.Position)
.OnMovedBack(cardIndex =>
return ContentPage(
[
Grid(
State.Cards
.Select(card => new CardPage()
.Index(card.Index)
.Position(card.Position)
.OnMovedBack(cardIndex =>
{
SetState(s =>
{
SetState(s =>
foreach (var card in s.Cards)
{
foreach (var card in s.Cards)
{
card.Position++;
}

s.Cards[cardIndex].Position = 1;
});
})
)
.ToArray()
)
.Background(MauiControls.Brush.Black)
])
.Title("Animation Sample");
}
card.Position++;
}

s.Cards[cardIndex].Position = 1;
});
})
)
.ToArray()
)
.Background(MauiControls.Brush.Black)
])
.Title("Animation Sample");
}
}

class CardState
{
public double Rotation { get; set; } = Random.Shared.NextDouble() * 5 - 2.5;
class CardState
{
public double Rotation { get; set; } = Random.Shared.NextDouble() * 5 - 2.5;

public bool MovingBack { get; set; }
public bool MovingBack { get; set; }
}

partial class CardPage : Component<CardState>
{
private static readonly MauiControls.Brush[] _cardBackgrounds = new[]
{
(From: "#36D1DC", To: "#5B86E5"),
(From: "#CB356B", To: "#BD3F32"),
(From: "#283c86", To: "#45a247"),
(From: "#EF3B36", To: "#FFFFFF"),
(From: "#c0392b", To: "#8e44ad"),
(From: "#159957", To: "#155799"),
(From: "#000046", To: "#1CB5E0"),
(From: "#007991", To: "#78ffd6"),
(From: "#56CCF2", To: "#2F80ED"),
(From: "#F2994A", To: "#F2C94C"),
}
.Select(MakeBrush)
.ToArray();

class CardPage : Component<CardState>
public static MauiControls.Brush MakeBrush((string From, string To) fromTo)
{
private static readonly MauiControls.Brush[] _cardBackgrounds = new[]
{
(From: "#36D1DC", To: "#5B86E5"),
(From: "#CB356B", To: "#BD3F32"),
(From: "#283c86", To: "#45a247"),
(From: "#EF3B36", To: "#FFFFFF"),
(From: "#c0392b", To: "#8e44ad"),
(From: "#159957", To: "#155799"),
(From: "#000046", To: "#1CB5E0"),
(From: "#007991", To: "#78ffd6"),
(From: "#56CCF2", To: "#2F80ED"),
(From: "#F2994A", To: "#F2C94C"),
}
.Select(MakeBrush)
.ToArray();

public static MauiControls.Brush MakeBrush((string From, string To) fromTo)
{
var brush = new MauiControls.LinearGradientBrush();
brush.GradientStops.Add(new MauiControls.GradientStop(Color.FromArgb(fromTo.From), 0.0f));
brush.GradientStops.Add(new MauiControls.GradientStop(Color.FromArgb(fromTo.To), 1.0f));
return brush;
}

private int _cardIndex;
private int _zIndex;
private Action<int>? _onMovedBackAction;

public CardPage Index(int cardIndex)
{
_cardIndex = cardIndex;
return this;
}

public CardPage Position(int zIndex)
{
_zIndex = zIndex;
return this;
}

public CardPage OnMovedBack(Action<int> onMovedBackAction)
{
_onMovedBackAction = onMovedBackAction;
return this;
}

public override VisualNode Render()
{
return Border(
[
Timer()
.Interval(300)
.OnTick(()=>
{
if (State.MovingBack)
{
State.MovingBack = false;
_onMovedBackAction?.Invoke(_cardIndex);
}
})
.IsEnabled(State.MovingBack)
])
.ZIndex(_zIndex)
.TranslationY(State.MovingBack ? -230 : 0)
.Rotation(State.Rotation)
.WithAnimation()
.Background(_cardBackgrounds[_cardIndex])
.WidthRequest(300)
.HeightRequest(200)
.StrokeCornerRadius(5)
.VEnd()
.HCenter()
.Margin(0, 40)
.OnTapped(()=>
{
SetState(s =>
{
s.MovingBack = true;
s.Rotation += 360 * 2;
});
})
;
var brush = new MauiControls.LinearGradientBrush();
brush.GradientStops.Add(new MauiControls.GradientStop(Color.FromArgb(fromTo.From), 0.0f));
brush.GradientStops.Add(new MauiControls.GradientStop(Color.FromArgb(fromTo.To), 1.0f));
return brush;
}

[Prop]
private int _index;

}
[Prop]
private int _position;

[Prop]
private Action<int>? _onMovedBack;

public override VisualNode Render()
{
return Border(
[
Timer()
.Interval(300)
.OnTick(()=>
{
if (State.MovingBack)
{
State.MovingBack = false;
_onMovedBack?.Invoke(_index);
}
})
.IsEnabled(State.MovingBack)
])
.ZIndex(_position)
.TranslationY(State.MovingBack ? -230 : 0)
.Rotation(State.Rotation)
.WithAnimation()
.Background(_cardBackgrounds[_index])
.WidthRequest(300)
.HeightRequest(200)
.StrokeCornerRadius(5)
.VEnd()
.HCenter()
.Margin(0, 40)
.OnTapped(()=>
{
SetState(s =>
{
s.MovingBack = true;
s.Rotation += 360 * 2;
});
})
;

}


}
16 changes: 7 additions & 9 deletions samples/MauiReactor.TestApp/Pages/CounterPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,23 @@ public override VisualNode Render()

}

class CounterWithServicePage : Component<CounterPageState>
partial class CounterWithServicePage : Component<CounterPageState>
{
IncrementService _incrementService = Services.GetRequiredService<IncrementService>();
[Inject]
IncrementService _incrementService;

public override VisualNode Render()
{
return new ContentPage("Counter Sample")
{
public override VisualNode Render()
=> ContentPage("Counter Sample",
VStack(spacing: 10,
Label($"Counter: {State.Counter}")
.AutomationId("Counter_Label")
.VCenter()
.HCenter(),

Button("Click To Increment",() => SetState(s => s.Counter = _incrementService.Increment(s.Counter)))
Button("Click To Increment", () => SetState(s => s.Counter = _incrementService.Increment(s.Counter)))
.AutomationId("Counter_Button")
)
.VCenter()
.HCenter()
};
}
);
}
13 changes: 5 additions & 8 deletions samples/MauiReactor.TestApp/Pages/ListViewExtendedTestPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ListViewExtendedTestPage : Component<ListViewExtendedTestPageState>
{
public override VisualNode Render()
{
return new ContentPage("ListView Extended Test (BETA)")
return new ContentPage("ListView Extended")
{
new ListView(MauiControls.ListViewCachingStrategy.RecycleElement)
.IsGroupingEnabled(true)
Expand All @@ -39,24 +39,21 @@ private void OnSelectedItem(object? sender, MauiControls.SelectedItemChangedEven
private ViewCell RenderGroup(GroupOfPerson person)
{
return ViewCell(
[
Label(person.Initial,
[
MenuFlyout(
[
MenuFlyoutItem("MenuItem1")
.OnClicked(()=>OnClickMenuItem("MenuItem1")),
MenuFlyoutItem("MenuItem2")
.OnClicked(()=>OnClickMenuItem("MenuItem2")),
MenuFlyoutItem("MenuItem3")
.OnClicked(()=>OnClickMenuItem("MenuItem3")),
])
])
.OnClicked(()=>OnClickMenuItem("MenuItem3"))
)
)
.FontSize(14.0)
.FontAttributes(MauiControls.FontAttributes.Bold)
.Margin(5)
.BackgroundColor(Colors.LightGray)
]);
);
}

private ViewCell RenderItem(Person person)
Expand Down
Loading

0 comments on commit 6337361

Please sign in to comment.