Xamarin.forms 是否可以延迟加载PRISM/Xamarin表单中未';你现在不需要吗?
我有以下AppDelegate,它需要相当长的时间才能加载:Xamarin.forms 是否可以延迟加载PRISM/Xamarin表单中未';你现在不需要吗?,xamarin.forms,prism,appdelegate,syncfusion,lazy-initialization,Xamarin.forms,Prism,Appdelegate,Syncfusion,Lazy Initialization,我有以下AppDelegate,它需要相当长的时间才能加载: Syncfusion.ListView.XForms.iOS.SfListViewRenderer.Init(); new Syncfusion.SfNumericUpDown.XForms.iOS.SfNumericUpDownRenderer(); Syncfusion.SfCarousel.XForms.iOS.SfCarouselRenderer.Init(); Sy
Syncfusion.ListView.XForms.iOS.SfListViewRenderer.Init();
new Syncfusion.SfNumericUpDown.XForms.iOS.SfNumericUpDownRenderer();
Syncfusion.SfCarousel.XForms.iOS.SfCarouselRenderer.Init();
Syncfusion.XForms.iOS.Buttons.SfSegmentedControlRenderer.Init();
Syncfusion.XForms.iOS.Buttons.SfCheckBoxRenderer.Init();
new Syncfusion.XForms.iOS.ComboBox.SfComboBoxRenderer();
//Syncfusion.XForms.iOS.TabView.SfTabViewRenderer.Init();
new Syncfusion.SfRotator.XForms.iOS.SfRotatorRenderer();
new Syncfusion.SfRating.XForms.iOS.SfRatingRenderer();
new Syncfusion.SfBusyIndicator.XForms.iOS.SfBusyIndicatorRenderer();
-
当我知道主屏幕不需要这些组件的时候,我应该考虑哪些选项,但是对于子屏幕呢?
- 我使用的是PRISM,似乎每个选项卡都是在允许显示或与最终用户交互之前立即预加载的。在显示界面之前,如何延迟Prism选项卡视图的预渲染
- 我应该使用惰性?什么是正确的方法
- 我是否应该将这些组件移动到另一个初始化部分
public partial class AppDelegate : FormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App(new iOSInitializer()));
return base.FinishedLaunching(app, options);
}
}
}
public class iOSInitializer : IPlatformInitializer, IPlatformFinalizer
{
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterInstance<IPlatformFinalizer>(this);
}
public void Finalize()
{
new Syncfusion.SfNumericUpDown.XForms.iOS.SfNumericUpDownRenderer();
Syncfusion.SfCarousel.XForms.iOS.SfCarouselRenderer.Init();
Syncfusion.XForms.iOS.Buttons.SfSegmentedControlRenderer.Init();
Syncfusion.XForms.iOS.Buttons.SfCheckBoxRenderer.Init();
}
}
public class App : PrismApplication
{
protected override async void OnInitialized()
{
await NavigationService.NavigateAsync("SplashScreen");
}
}
public class SplashScreenViewModel : INavigationAware
{
private IPlatformFinalizer _platformFinalizer { get; }
private INavigationService _navigationService { get; }
public SplashScreenViewModel(INavigationService navigationService, IPlatformFinalizer platformFinalizer)
{
_navigationService = navigationService;
_platformFinalizer = platformFinalizer;
}
public async void OnNavigatedTo(INavigationParameters navigationParameters)
{
_platformFinalizer.Finalize();
await _navigationService.NavigateAsync("/MainPage");
}
}
public分部类AppDelegate:FormsApplicationDelegate
{
公共覆盖bool FinishedLaunching(UIApplication应用程序、NSDictionary选项)
{
全局::Xamarin.Forms.Forms.Init();
LoadApplication(新应用程序(新初始值设定项());
返回基地。完成发射(应用程序,选项);
}
}
}
公共类IOS初始值设定项:IPlatformInitializer、IPlatformFinalizer
{
公共无效注册表类型(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterInstance(此);
}
公共图书馆
{
新的Syncfusion.SfNumericUpDown.XForms.iOS.SfNumericUpDownRenderer();
Syncfusion.SfCarousel.XForms.iOS.SfCarouselRenderer.Init();
Syncfusion.XForms.iOS.Buttons.SfSegmentedControlRenderer.Init();
Syncfusion.XForms.iOS.Buttons.SfCheckBoxRenderer.Init();
}
}
公共类应用程序:PrismApplication
{
受保护的重写异步void OnInitialized()
{
等待NavigationService.NavigateAsync(“SplashScreen”);
}
}
公共类SplashScreenViewModel:INavigationAware
{
私有IPlatformFinalizer _platformFinalizer{get;}
私有INavigationService_导航服务{get;}
公共SplashScreenViewModel(INavigationService navigationService,IPlatformFinalizer平台Finalizer)
{
_导航服务=导航服务;
_platformFinalizer=platformFinalizer;
}
公共异步void OnNavigatedTo(INavigationParameters navigationParameters)
{
_platformFinalizer.Finalize();
等待_navigationService.NavigateAsync(“/MainPage”);
}
}
如果您使用的是模块,您可以采取类似的方法,尽管在启动时初始化的任何模块在您设置要导航到的页面之前仍然会调用Init呈现器。这就是说,在这里使用模块确实会给你带来很多好处,因为你只需要在那时初始化应用程序实际需要的东西
所有这些都表明,如果您看到了很多好处,我会感到惊讶,因为这些Init
调用通常都是空方法,只是为了防止链接器将它们链接出来。。。如果您没有链接或没有链接器文件,您可以简单地指示链接器不要使用Syncfusion和其他库