Skip to content

[Bug]: OnSearchTextChanged is not reliable  #207

@Strypper

Description

@Strypper

Contact Details

[email protected]

What happened?

Cái thanh tìm kiếm trong trang CardsByGroupPage không hoạt động ổn định. Hành vi tìm kiếm không nhất quán, ứng dụng đôi khi tự động bị treo và cách làm mới giao diện người dùng tiêu tốn quá nhiều tài nguyên.

  1. Lỗi treo ứng dụng: Khi tìm kiếm từ "Blaz", UI sẽ hiển thị thẻ "Blazor Web View". Sau khi xóa từ khóa, trang sẽ hiển thị đầy đủ các control của nhóm này, nhưng ứng dụng đột ngột bị khựng lại và treo.

image
2. Lỗi logic tìm kiếm: Khi tìm kiếm từ "AC", UI lẽ ra phải trả về ít nhất là thẻ "ActivityIndicator", nhưng kết quả tìm kiếm lại là 0.

image
3. Lỗi xóa văn bản: Khi xóa hết chữ, UI sẽ trả về toàn bộ control, nhưng khi sử dụng nút "x" của thanh tìm kiếm để xóa văn bản, UI không thực hiện điều tương tự. Có vẻ như nút "x" không kích hoạt sự kiện thay đổi văn bản.
4. Lỗi khi nhấn nút "x" và quay về: Sau khi nhấn nút "x" và nút quay về, ứng dụng bị treo.
5. Device.BeginInvokeOnMainThread hiện đang bị đánh dấu là obsolete.

How does that look?

Vị trí của search logic
Logic: CardsByGroupPageViewModel.cs - OnSearchTextChanged - Kích hoạt search
Logic: CardsByGroupPageViewModel.cs - FilterControls - Apply filter lên UI
UI: CardsByGroupPage.xaml

                                <SearchBar
                                    HorizontalOptions="Center"
                                    MinimumWidthRequest="250"
                                    Placeholder="Search controls, converters and many more"
                                    Text="{x:Binding SearchText,
                                                     Mode=TwoWay}"
                                    VerticalOptions="Center" />
    partial void OnSearchTextChanged(string value)
    {
        _debounceTimer?.Dispose(); // Cancel any existing timer
        _debounceTimer = new Timer(_ =>
        {
            // This code runs after the debounce period elapses
            // Ensure you're on the UI thread if necessary, especially if modifying UI elements directly
            Device.BeginInvokeOnMainThread(() =>
            {
                FilterControls(SelectedItem, value);
            });
        }, null, DebouncePeriodInMilliseconds, Timeout.Infinite); // Timeout.Infinite ensures the timer runs only once
    }

Version

9.0

What platforms are you seeing the problem on?

Windows

Relevant log output

System.InvalidOperationException: PlatformView cannot be null here
   at Microsoft.Maui.Handlers.ViewHandler`2.get_PlatformView()
   at Microsoft.Maui.Handlers.ImageButtonHandler.ImageButtonImageSourcePartSetter.SetImageSource(ImageSource platformImage)
   at Microsoft.Maui.Platform.ImageSourcePartExtensions.UpdateSourceAsync(IImageSourcePart image, FrameworkElement destinationContext, IImageSourceServiceProvider services, Action`1 setImage, Single imageScale, CancellationToken cancellationToken)
   at Microsoft.Maui.Platform.ImageSourcePartLoader.UpdateImageSourceAsync()
   at Microsoft.Maui.TaskExtensions.FireAndForget(Task task, Action`1 errorCallback)
Microsoft.Maui.Handlers.IImageHandler: Error: Unexpected exception in MapSource.

Code of Conduct

  • I agree to respect and follow this project's rules

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions