adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
552 stars 45 forks source link

SwipeItemView not implemented #215

Closed afriscic closed 4 months ago

afriscic commented 4 months ago

Hello.

Out of standard MAUI controls I've noticed that SwipeItemView implementation is missing. Please if you can implement SwipeItemView so that custom swipe items can be created easily.

BTW Thank you for creating this library. It's AWSEOME!!!

adospace commented 4 months ago

Hi, thanks for your interest in MauiReactor. Do you mean SwipeItem?

class MainPageSwipeState
{
    public ObservableCollection<Person> Persons { get; set; }
}

class MainPageSwipe : Component<MainPageSwipeState>
{
    protected override void OnMounted()
    {
        var person1 = new Person("John", "Doe", new DateTime(1980, 5, 10));
        var person2 = new Person("Jane", "Smith", new DateTime(1990, 6, 20));
        var person3 = new Person("Alice", "Johnson", new DateTime(1985, 7, 30));
        var person4 = new Person("Bob", "Williams", new DateTime(2000, 8, 15));
        var person5 = new Person("Charlie", "Brown", new DateTime(1995, 9, 25));

        State.Persons = new ObservableCollection<Person>(new[] { person1, person2, person3, person4, person5 });
        base.OnMounted();
    }

    public override VisualNode Render()
        => ContentPage(
            CollectionView()
                .ItemsSource(State.Persons, RenderPerson)
                );

    private VisualNode RenderPerson(Person person) 
        => SwipeView(
            VStack(spacing: 5,
                Label($"{person.FirstName} {person.LastName}"),
                Label(person.DateOfBirth.ToShortDateString())
                    .FontSize(12)
            )
            .VCenter()
        )
        .LeftItems(
        [
            SwipeItem()
                .IconImageSource("archive.png")
                .Text("Archive")
                .BackgroundColor(Colors.Green),
            SwipeItem()
                .IconImageSource("delete.png")
                .Text("Delete")
                .BackgroundColor(Colors.Red)
                .OnInvoked(()=>State.Persons.Remove(person))
        ])
        .HeightRequest(60);
}
afriscic commented 4 months ago

No. It's this: https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.controls.swipeitemview?view=net-maui-8.0 It enables creation of custom swipe items, link. I tried scaffolding it but I haven't managed it to show anything.

Here is an example of working xaml code that i have in classic MAUI:

<SwipeView Threshold="50">
    <SwipeView.RightItems>
        <SwipeItems>
            <SwipeItemView BackgroundColor="Red"
                            Command="{Binding Source={Reference Name=PacksDetailsPage}, Path=BindingContext.DeletePackCommand}"
                            CommandParameter="{Binding PackSeriaNumber}">
                <Label Text="{StaticResource IconDelete}"
                        TextColor="Black"
                        FontAttributes="Bold"
                        FontSize="25"
                        FontFamily="IconsFont"
                        HorizontalOptions="Center"
                        VerticalOptions="Center"/>
            </SwipeItemView>
        </SwipeItems>
    </SwipeView.RightItems>
...
adospace commented 4 months ago

Hi, I've fixed this in version 2.0.29

Sample code:

SwipeView(
      VStack(spacing: 5,
          Label(item.Item1),
          Label(item.Item2)
      )
     )
     .RightItems([
       SwipeItemView(
          HStack(
              Label("Custom Swipte Item")
              )
          )
     ]);