unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.79k stars 706 forks source link

`ListView` selected error #14792

Open HaoLife opened 9 months ago

HaoLife commented 9 months ago

Current behavior

ListViewBase has issues with invalid or delayed selection in mvux mode


        void SingleSelectionCase()
        {
            if (base.ItemsSource is ICollectionView collectionView)
            {
                collectionView.MoveCurrentToPosition(clickedIndex);
                clickedIndex = collectionView.CurrentPosition;
            }

            if (modifiers.HasFlag(VirtualKeyModifiers.Control) && clickedIndex == base.SelectedIndex)
            {
                base.SelectedIndex = -1;
            }
            else
            {
                base.SelectedIndex = clickedIndex;
            }
        }

// clickedIndex=1
//collectionView.MoveCurrentToPosition(clickedIndex);
// collectionView.CurrentPosition=0
                collectionView.MoveCurrentToPosition(clickedIndex);
                clickedIndex = collectionView.CurrentPosition;

Expected behavior

No response

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

No response

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

<PackageVersion Include="Uno.Extensions.Reactive" Version="3.0.10" />
<PackageVersion Include="Uno.Extensions.Reactive.WinUI" Version="3.0.10" />

Affected platforms

WebAssembly, Android, iOS, macOS (AppKit), Mac Catalyst, Skia (WPF), Skia (Linux Framebuffer)

IDE

Visual Studio 2022

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

jeromelaban commented 9 months ago

Thanks for the report. Can you provide a full sample that reproduces your problem? It will be easier to discuss the original behavior.

HaoLife commented 9 months ago

MainPage.xaml ` <Page x:Class="UnoApp1.Presentation.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:UnoApp1.Presentation" xmlns:uen="using:Uno.Extensions.Navigation.UI" xmlns:utu="using:Uno.Toolkit.UI" xmlns:mvux="using:Uno.Extensions.Reactive.UI" NavigationCacheMode="Required" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

`

` using System; using System.Threading;

namespace UnoApp1.Presentation;

public partial record MainModel { private INavigator _navigator; private readonly IDispatcher dispatcher;

public MainModel(
    IStringLocalizer localizer,
    IOptions<AppConfig> appInfo,
    INavigator navigator,
    IDispatcher dispatcher)
{
    _navigator = navigator;
    this.dispatcher = dispatcher;

    Title = "Main";
    Title += $" - {localizer["ApplicationName"]}";
    Title += $" - {appInfo?.Value?.Environment}";
}

public string? Title { get; }

public IState<string> Name => State<string>.Value(this, () => string.Empty);

public async Task GoToSecond()
{
    var name = await Name;
    await _navigator.NavigateViewModelAsync<SecondModel>(this, data: new Entity(name!));
}

//Uno.Extensions.Reactive.Bindings.BindableListFeed<string>
public IListFeed<string> Trends => ListFeed.Async(async (ct) => await this.GetAsync());

public async ValueTask<IImmutableList<string>> GetAsync()
{

    var list = new List<string>() { "test", "456", "7", "8", "9" };

    return list.ToImmutableList();
}

}

`

image [Uploading UnoApp1 (2).zip…]()

jeromelaban commented 9 months ago

Thanks. It seems that the repro was not attached properly. To create a repro, make sure to follow this.

HaoLife commented 9 months ago

UnoApp1.zip

dr1rrb commented 9 months ago

Hey @HaoLife, thanks for the report.

I tried your sample, I'm not sure what is failing? No matter how I use the selection with MVUX, I get the right selected item (even if I try to unselect the item using the CTRL key).

HaoLife commented 9 months ago

It needs to constantly switch between selected items, which may lag or become ineffective when replaced frequently

https://github.com/unoplatform/uno/assets/25171162/f0647b02-721a-4a61-842a-43dafc87bb0b

1702740136370