Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add stub for virtualizing recycling scrollview #80

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Maui/VirtualizingRecyclingScrollView/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:VirtualizingRecyclingScrollView"
x:Class="VirtualizingRecyclingScrollView.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
14 changes: 14 additions & 0 deletions Maui/VirtualizingRecyclingScrollView/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace VirtualizingRecyclingScrollView;

public partial class App : Application
{
public App()
{
InitializeComponent();
}

protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new AppShell());
}
}
12 changes: 12 additions & 0 deletions Maui/VirtualizingRecyclingScrollView/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="VirtualizingRecyclingScrollView.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:VirtualizingRecyclingScrollView">

<ShellContent
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage"/>

</Shell>
9 changes: 9 additions & 0 deletions Maui/VirtualizingRecyclingScrollView/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace VirtualizingRecyclingScrollView;

public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
44 changes: 44 additions & 0 deletions Maui/VirtualizingRecyclingScrollView/CellModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

using System.ComponentModel;

namespace VirtualizingRecyclingScrollView;

public class CellModel : INotifyPropertyChanged
{
private static PropertyChangedEventArgs changedAll = new PropertyChangedEventArgs(null);

public Key key;

private string text;

private Color color;

public event PropertyChangedEventHandler? PropertyChanged;

public string Text
{
get => this.text;
set
{
this.text = value;
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Text)));
}
}

public Color Color
{
get => this.color;
set
{
this.color = value;
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Color)));
}
}

internal void Update(string text, Color color)
{
this.text = text;
this.color = color;
this.PropertyChanged?.Invoke(this, changedAll);
}
}
13 changes: 13 additions & 0 deletions Maui/VirtualizingRecyclingScrollView/Key.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace VirtualizingRecyclingScrollView;

public struct Key
{
public int x;
public int y;

public Key(int x, int y)
{
this.x = x;
this.y = y;
}
}
111 changes: 111 additions & 0 deletions Maui/VirtualizingRecyclingScrollView/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="VirtualizingRecyclingScrollView.MainPage"
xmlns:local="clr-namespace:VirtualizingRecyclingScrollView"
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
ios:Page.UseSafeArea="False"
Shell.NavBarIsVisible="False"
Background="White">

<Grid IgnoreSafeArea="True">
<Grid.RowDefinitions>
<RowDefinition Height="60" />
<RowDefinition Height="50" />
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>

<local:TrackingBorder x:Name="HeaderBackground" Grid.Row="0" Grid.RowSpan="2" Background="#DDFFFFFF" />
<Grid Grid.Row="1" x:Name="HeaderContent">
<VerticalStackLayout>
<local:TrackingLabel Text="Title" TextColor="Black" VerticalOptions="Center" Margin="10,0,10,0" FontSize="24" />
<HorizontalStackLayout Margin="9,0,0,0">
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
</HorizontalStackLayout>
<HorizontalStackLayout Margin="9,0,0,0">
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
</HorizontalStackLayout>
<HorizontalStackLayout Margin="9,0,0,0">
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
<local:TrackingBorder Background="Red" WidthRequest="5" HeightRequest="5" />
</HorizontalStackLayout>
</VerticalStackLayout>
<Grid HorizontalOptions="End">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120" />
<ColumnDefinition Width="60" />
<ColumnDefinition Width="120" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>

<Label Grid.Row="0" Grid.Column="0" Text="Shell El. Layout:" TextColor="Black" VerticalOptions="Center" HorizontalTextAlignment="End" HorizontalOptions="End" FontSize="14" />
<Label Grid.Row="0" Grid.Column="1" Text="{Binding LayoutNodes}" TextColor="Black" VerticalOptions="Center" HorizontalTextAlignment="Start" FontSize="14" WidthRequest="60" HeightRequest="16" />

<Label Grid.Row="1" Grid.Column="0" Text="Virtual El. Layout:" TextColor="Black" VerticalOptions="Center" HorizontalTextAlignment="End" HorizontalOptions="End" FontSize="14" />
<Label Grid.Row="1" Grid.Column="1" Text="{Binding LayoutVirtualNodes}" TextColor="Black" VerticalOptions="Center" HorizontalTextAlignment="Start" FontSize="14" WidthRequest="60" HeightRequest="16" />

<Label Grid.Row="0" Grid.Column="2" Text="Recycled Items:" TextColor="Black" VerticalOptions="Center" HorizontalTextAlignment="End" HorizontalOptions="End" FontSize="14" />
<Label Grid.Row="0" Grid.Column="3" Text="{Binding RecycledItems}" TextColor="Black" VerticalOptions="Center" HorizontalTextAlignment="Start" FontSize="14" WidthRequest="50" HeightRequest="16" />

<Label Grid.Row="1" Grid.Column="2" Text="Dropped Frames:" TextColor="Black" VerticalOptions="Center" HorizontalTextAlignment="End" HorizontalOptions="End" FontSize="14" />
<Label Grid.Row="1" Grid.Column="3" Text="{Binding DroppedFrames}" TextColor="Black" VerticalOptions="Center" HorizontalTextAlignment="Start" FontSize="14" WidthRequest="50" HeightRequest="16" />

</Grid>
</Grid>
<local:TrackingBorder x:Name="FooterBackground" Grid.Row="3" Background="#DDFFFFFF" />

<local:TheScrollView x:Name="SV" Grid.RowSpan="4" ZIndex="-1">
<local:TheScrollView.Template>
<DataTemplate x:DataType="local:CellModel">
<!-- Slim template: we can't trim further than that -->
<local:TrackingLabel Virtualized="True" Text="{Binding Text}" TextColor="Black" Background="{Binding Color}" Margin="2" FontSize="16" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" />

<!-- Medium template: no triggers or visual states -->
<!-- <local:TrackingBorder Virtualized="True" Background="{Binding Color}" Margin="1" StrokeThickness="1" Stroke="DarkGray">
<local:TrackingLabel Virtualized="True" Text="{Binding Text}" TextColor="Black" Margin="2" FontSize="16" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" />
</local:TrackingBorder> -->

<!-- Fat template: That would include a border, a grid, icon and a label, maybe interactive with a trigger -->
</DataTemplate>
</local:TheScrollView.Template>
</local:TheScrollView>
</Grid>

</ContentPage>
22 changes: 22 additions & 0 deletions Maui/VirtualizingRecyclingScrollView/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace VirtualizingRecyclingScrollView;

public partial class MainPage : ContentPage
{
public MainPage()
{
this.BindingContext = TrackingModel.Instance;
InitializeComponent();

this.Dispatcher.DispatchDelayed(TimeSpan.FromSeconds(1), () => {
this.SV.ScrollToAsync(40, 0, false);
this.Dispatcher.DispatchDelayed(TimeSpan.FromSeconds(1), () => {
TrackingModel.Instance.Clear();
this.Dispatcher.DispatchDelayed(TimeSpan.FromSeconds(3), async () => {
MauiProgram.SuppressWorkarounds = true;
await this.SV.ScrollToAsync(40, 800, true);
MauiProgram.SuppressWorkarounds = false;
});
});
});
}
}
40 changes: 40 additions & 0 deletions Maui/VirtualizingRecyclingScrollView/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging;
using Microsoft.Maui.Handlers;

namespace VirtualizingRecyclingScrollView;

public static class MauiProgram
{
public static int IsInVirtualizationScope = 0;
public static bool SuppressWorkarounds = false;

public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureMauiHandlers(handlers =>
{
ViewHandler.ViewCommandMapper.ModifyMapping<IView, IViewHandler>(nameof(IView.InvalidateMeasure), (layout, handler, args, current) =>
{
if (MauiProgram.SuppressWorkarounds || MauiProgram.IsInVirtualizationScope == 0)
{
// Comment this out to stop layout invalidation...
current?.Invoke(layout, handler, args);
}
});
})
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace VirtualizingRecyclingScrollView;

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Android.App;
using Android.Runtime;

namespace VirtualizingRecyclingScrollView;

[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Foundation;

namespace VirtualizingRecyclingScrollView;

[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- See https://aka.ms/maui-publish-app-store#add-entitlements for more information about adding entitlements.-->
<dict>
<!-- App Sandbox must be enabled to distribute a MacCatalyst app through the Mac App Store. -->
<key>com.apple.security.app-sandbox</key>
<true/>
<!-- When App Sandbox is enabled, this value is required to open outgoing network connections. -->
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- The Mac App Store requires you specify if the app uses encryption. -->
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/itsappusesnonexemptencryption -->
<!-- <key>ITSAppUsesNonExemptEncryption</key> -->
<!-- Please indicate <true/> or <false/> here. -->

<!-- Specify the category for your app here. -->
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/lsapplicationcategorytype -->
<!-- <key>LSApplicationCategoryType</key> -->
<!-- <string>public.app-category.YOUR-CATEGORY-HERE</string> -->
<key>UIDeviceFamily</key>
<array>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
</dict>
</plist>
Loading