maui-linux/System.Maui.Platform.UAP/DispatcherProvider.cs

39 строки
768 B
C#
Исходник Обычный вид История

2020-05-19 03:56:25 +03:00
using System;
using System.Maui;
using System.Maui.Platform.UWP;
[UWP] Multi-window (#2432) * Changes to support multiple windows on UWP * Locker on Layout.cs to prevent concurrency * Changes on UnitTests to work with multi-window * implemented Xamarin.Forms.Core and UAP Element.Dispatcher * Implementation on each platform * Implementation on each platform * Improved Element casting for Dispatcher utilization * Correction of the items presented in the code review * Control Gallery for Multiple Window and Code Review * [UnitTests]Add missing file * Correction for Unit Tests * Correction for Unit Tests * Correction for Unit Tests - Removed ThreadStatic in Ticker * removed thread static * removed thread static into application class * Update Control Gallery * Code Review (Changes) * Comment * Adjust StackOverflow when close the app * Performace improvements * - fix merge and ui test performance * Name of method and adjust on NavigationProxy * Adjustments in the implementation of the DispatcherManager * Updated the ListProxy method and adjust the initialization of dispacther on page. * Remove GetDispacther method from IPlatformServices and some adjusments of code review. * Adjust after merge on NavigationProxy * Register IDispatcherProvider on Xamarin.Forms.Core.UnitTests * Adjustments for correct unit tests operation * Adjustments for correct unit tests operation * remove spaces * Adjust for UITests * Remove IsInvokeRequired and adjusted de instance of s_resolutionList * Remove lock() on ResolveLayoutChanges method * Make IDispatcher implementations internal * Removed Dispatcher association from Element and Page class. Removed Child Assignment in Element Class and ThreadStatic Removal from NavigationProxy Property * Remove DispatcherManager; contain thread static to UWP implementation * Make dispatcher lazy * MockDispatcherProvider on Xaml.UnitTests * Add mock Dispatcher and DispatcherProvider for XAML unit tests * Revert "Add mock Dispatcher and DispatcherProvider for XAML unit tests" This reverts commit 134320d348a3812e44507ae0b50459c8f43478e9. * Add MockDispactcherProvider on Pager.UnitTests * Revert covariance change * Centralize dispatcher checking logic * Add a fallback dispatcher for platforms without a registered DispatcherProvider * Remove Dispatcher/DispatcherProvider from project * Allow UI test pages which use ListProxy to get a dispatcher in UITest mode * Prevent crash instantiating UITest version of Issue2004 * Removed unnecessary old codes * Clean up whitespace changes * Remove unused method
2019-08-15 20:36:38 +03:00
[assembly: Dependency(typeof(DispatcherProvider))]
2020-05-19 03:56:25 +03:00
namespace System.Maui.Platform.UWP
[UWP] Multi-window (#2432) * Changes to support multiple windows on UWP * Locker on Layout.cs to prevent concurrency * Changes on UnitTests to work with multi-window * implemented Xamarin.Forms.Core and UAP Element.Dispatcher * Implementation on each platform * Implementation on each platform * Improved Element casting for Dispatcher utilization * Correction of the items presented in the code review * Control Gallery for Multiple Window and Code Review * [UnitTests]Add missing file * Correction for Unit Tests * Correction for Unit Tests * Correction for Unit Tests - Removed ThreadStatic in Ticker * removed thread static * removed thread static into application class * Update Control Gallery * Code Review (Changes) * Comment * Adjust StackOverflow when close the app * Performace improvements * - fix merge and ui test performance * Name of method and adjust on NavigationProxy * Adjustments in the implementation of the DispatcherManager * Updated the ListProxy method and adjust the initialization of dispacther on page. * Remove GetDispacther method from IPlatformServices and some adjusments of code review. * Adjust after merge on NavigationProxy * Register IDispatcherProvider on Xamarin.Forms.Core.UnitTests * Adjustments for correct unit tests operation * Adjustments for correct unit tests operation * remove spaces * Adjust for UITests * Remove IsInvokeRequired and adjusted de instance of s_resolutionList * Remove lock() on ResolveLayoutChanges method * Make IDispatcher implementations internal * Removed Dispatcher association from Element and Page class. Removed Child Assignment in Element Class and ThreadStatic Removal from NavigationProxy Property * Remove DispatcherManager; contain thread static to UWP implementation * Make dispatcher lazy * MockDispatcherProvider on Xaml.UnitTests * Add mock Dispatcher and DispatcherProvider for XAML unit tests * Revert "Add mock Dispatcher and DispatcherProvider for XAML unit tests" This reverts commit 134320d348a3812e44507ae0b50459c8f43478e9. * Add MockDispactcherProvider on Pager.UnitTests * Revert covariance change * Centralize dispatcher checking logic * Add a fallback dispatcher for platforms without a registered DispatcherProvider * Remove Dispatcher/DispatcherProvider from project * Allow UI test pages which use ListProxy to get a dispatcher in UITest mode * Prevent crash instantiating UITest version of Issue2004 * Removed unnecessary old codes * Clean up whitespace changes * Remove unused method
2019-08-15 20:36:38 +03:00
{
internal class DispatcherProvider : IDispatcherProvider
{
[ThreadStatic]
static Dispatcher s_current;
public IDispatcher GetDispatcher(object context)
{
if (s_current != null)
{
return s_current;
}
if (context is BindableObject)
{
if (context is VisualElement element)
{
var renderer = Platform.GetRenderer(element);
if (renderer?.ContainerElement != null)
{
s_current = new Dispatcher(renderer.ContainerElement.Dispatcher);
return s_current;
}
}
return null;
}
[UWP] Multi-window (#2432) * Changes to support multiple windows on UWP * Locker on Layout.cs to prevent concurrency * Changes on UnitTests to work with multi-window * implemented Xamarin.Forms.Core and UAP Element.Dispatcher * Implementation on each platform * Implementation on each platform * Improved Element casting for Dispatcher utilization * Correction of the items presented in the code review * Control Gallery for Multiple Window and Code Review * [UnitTests]Add missing file * Correction for Unit Tests * Correction for Unit Tests * Correction for Unit Tests - Removed ThreadStatic in Ticker * removed thread static * removed thread static into application class * Update Control Gallery * Code Review (Changes) * Comment * Adjust StackOverflow when close the app * Performace improvements * - fix merge and ui test performance * Name of method and adjust on NavigationProxy * Adjustments in the implementation of the DispatcherManager * Updated the ListProxy method and adjust the initialization of dispacther on page. * Remove GetDispacther method from IPlatformServices and some adjusments of code review. * Adjust after merge on NavigationProxy * Register IDispatcherProvider on Xamarin.Forms.Core.UnitTests * Adjustments for correct unit tests operation * Adjustments for correct unit tests operation * remove spaces * Adjust for UITests * Remove IsInvokeRequired and adjusted de instance of s_resolutionList * Remove lock() on ResolveLayoutChanges method * Make IDispatcher implementations internal * Removed Dispatcher association from Element and Page class. Removed Child Assignment in Element Class and ThreadStatic Removal from NavigationProxy Property * Remove DispatcherManager; contain thread static to UWP implementation * Make dispatcher lazy * MockDispatcherProvider on Xaml.UnitTests * Add mock Dispatcher and DispatcherProvider for XAML unit tests * Revert "Add mock Dispatcher and DispatcherProvider for XAML unit tests" This reverts commit 134320d348a3812e44507ae0b50459c8f43478e9. * Add MockDispactcherProvider on Pager.UnitTests * Revert covariance change * Centralize dispatcher checking logic * Add a fallback dispatcher for platforms without a registered DispatcherProvider * Remove Dispatcher/DispatcherProvider from project * Allow UI test pages which use ListProxy to get a dispatcher in UITest mode * Prevent crash instantiating UITest version of Issue2004 * Removed unnecessary old codes * Clean up whitespace changes * Remove unused method
2019-08-15 20:36:38 +03:00
return s_current = s_current ?? new Dispatcher();
}
}
}