Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#371 Add iOS to Caliburn.Micro.Platform
- Loading branch information
1 parent
f73b606
commit 0903272
Showing
5 changed files
with
381 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
src/Caliburn.Micro.Platform/Platforms/iOS/CaliburnApplicationDelegate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Foundation; | ||
using UIKit; | ||
|
||
namespace Caliburn.Micro | ||
{ | ||
/// <summary> | ||
/// Encapsulates the app and its available services. | ||
/// </summary> | ||
public class CaliburnApplicationDelegate : UIApplicationDelegate | ||
{ | ||
private bool isInitialized; | ||
|
||
/// <summary> | ||
/// Creates an instance of <see cref="CaliburnApplicationDelegate"/>. | ||
/// </summary> | ||
public CaliburnApplicationDelegate() { | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Creates an instance of <see cref="CaliburnApplicationDelegate"/>. | ||
/// </summary> | ||
/// <param name="handle">/// The handle for this class</param> | ||
public CaliburnApplicationDelegate(IntPtr handle) : base(handle) { | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Creates an instance of <see cref="CaliburnApplicationDelegate"/>. | ||
/// </summary> | ||
/// <param name="t">>Unused sentinel value, pass NSObjectFlag.Empty</param> | ||
public CaliburnApplicationDelegate(NSObjectFlag t) | ||
: base(t) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Called by the bootstrapper's constructor at design time to start the framework. | ||
/// </summary> | ||
protected virtual void StartDesignTime() | ||
{ | ||
AssemblySource.Instance.Clear(); | ||
AssemblySource.Instance.AddRange(SelectAssemblies()); | ||
|
||
Configure(); | ||
|
||
IoC.GetInstance = GetInstance; | ||
IoC.GetAllInstances = GetAllInstances; | ||
IoC.BuildUp = BuildUp; | ||
} | ||
|
||
/// <summary> | ||
/// Called by the bootstrapper's constructor at runtime to start the framework. | ||
/// </summary>B | ||
protected virtual void StartRuntime() | ||
{ | ||
EventAggregator.HandlerResultProcessing = (target, result) => | ||
{ | ||
var task = result as Task; | ||
if (task != null) | ||
{ | ||
result = new IResult[] { task.AsResult() }; | ||
} | ||
var coroutine = result as IEnumerable<IResult>; | ||
if (coroutine != null) | ||
{ | ||
var viewAware = target as IViewAware; | ||
var view = viewAware != null ? viewAware.GetView() : null; | ||
var context = new CoroutineExecutionContext { Target = target, View = view }; | ||
Coroutine.BeginExecute(coroutine.GetEnumerator(), context); | ||
} | ||
}; | ||
|
||
AssemblySourceCache.Install(); | ||
AssemblySource.Instance.AddRange(SelectAssemblies()); | ||
|
||
Configure(); | ||
IoC.GetInstance = GetInstance; | ||
IoC.GetAllInstances = GetAllInstances; | ||
IoC.BuildUp = BuildUp; | ||
} | ||
|
||
/// <summary> | ||
/// Start the framework. | ||
/// </summary> | ||
protected void Initialize() | ||
{ | ||
if (isInitialized) | ||
{ | ||
return; | ||
} | ||
|
||
isInitialized = true; | ||
|
||
PlatformProvider.Current = new IOSPlatformProvider(); | ||
|
||
if (Execute.InDesignMode) | ||
{ | ||
try | ||
{ | ||
StartDesignTime(); | ||
} | ||
catch | ||
{ | ||
//if something fails at design-time, there's really nothing we can do... | ||
isInitialized = false; | ||
throw; | ||
} | ||
} | ||
else | ||
{ | ||
StartRuntime(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Override to configure the framework and setup your IoC container. | ||
/// </summary> | ||
protected virtual void Configure() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Override to tell the framework where to find assemblies to inspect for views, etc. | ||
/// </summary> | ||
/// <returns>A list of assemblies to inspect.</returns> | ||
protected virtual IEnumerable<Assembly> SelectAssemblies() | ||
{ | ||
return new[] { GetType().GetTypeInfo().Assembly }; | ||
} | ||
|
||
/// <summary> | ||
/// Override this to provide an IoC specific implementation. | ||
/// </summary> | ||
/// <param name="service">The service to locate.</param> | ||
/// <param name="key">The key to locate.</param> | ||
/// <returns>The located service.</returns> | ||
protected virtual object GetInstance(Type service, string key) | ||
{ | ||
return Activator.CreateInstance(service); | ||
} | ||
|
||
/// <summary> | ||
/// Override this to provide an IoC specific implementation | ||
/// </summary> | ||
/// <param name="service">The service to locate.</param> | ||
/// <returns>The located services.</returns> | ||
protected virtual IEnumerable<object> GetAllInstances(Type service) | ||
{ | ||
return new[] { Activator.CreateInstance(service) }; | ||
} | ||
|
||
/// <summary> | ||
/// Override this to provide an IoC specific implementation. | ||
/// </summary> | ||
/// <param name="instance">The instance to perform injection on.</param> | ||
protected virtual void BuildUp(object instance) | ||
{ | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Caliburn.Micro.Platform/Platforms/iOS/IUIViewController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
|
||
namespace Caliburn.Micro | ||
{ | ||
/// <summary> | ||
/// An interface to allow the IOSPlatformProvider provide view lifecycle events | ||
/// </summary> | ||
public interface IUIViewController | ||
{ | ||
/// <summary> | ||
/// Returns if the current view is already loaded | ||
/// </summary> | ||
bool IsViewLoaded { get; } | ||
|
||
/// <summary> | ||
/// Invoked when the view is loaded | ||
/// </summary> | ||
event EventHandler ViewLoaded; | ||
|
||
/// <summary> | ||
/// Invoked the view appears | ||
/// </summary> | ||
event EventHandler ViewAppeared; | ||
} | ||
} |
Oops, something went wrong.