Skip to content

Commit

Permalink
Bump to latest
Browse files Browse the repository at this point in the history
- Modal Navigation Manager (dotnet#1563)
- Implement the basic WindowHandler (dotnet#1468)
- Don't extract native defaults, meaning users can no longer reset a color back to a platform theme (dotnet#1485)
- Implement Alerts (Alert, Prompt and ActionSheet) (dotnet#1328)
- And so on.
  • Loading branch information
rookiejava committed Oct 14, 2021
1 parent 1e7cdef commit 97edd75
Show file tree
Hide file tree
Showing 21 changed files with 186 additions and 45 deletions.
47 changes: 47 additions & 0 deletions src/Compatibility/Core/src/Tizen/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ static void SetupInit(IMauiContext context, InitializationOptions options = null

Device.Info = new Forms.TizenDeviceInfo();

if (options?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true)
RegisterCompatRenderers(options);

string profile = ((TizenDeviceInfo)Device.Info).Profile;
if (profile == "mobile")
{
Expand Down Expand Up @@ -501,6 +504,50 @@ static void SetupInit(IMauiContext context, InitializationOptions options = null
IsInitialized = true;
}

internal static void RegisterCompatRenderers(InitializationOptions maybeOptions = null)
{
if (!IsInitializedRenderers)
{
IsInitializedRenderers = true;
if (maybeOptions != null)
{
var options = maybeOptions;
var handlers = options.Handlers;
var flags = options.Flags;
var effectScopes = options.EffectScopes;

//TODO: ExportCell?
//TODO: ExportFont

// renderers
Registrar.RegisterRenderers(handlers);

// effects
if (effectScopes != null)
{
for (var i = 0; i < effectScopes.Length; i++)
{
var effectScope = effectScopes[0];
Registrar.RegisterEffects(effectScope.Name, effectScope.Effects);
}
}

// css
Registrar.RegisterStylesheets(flags);
}
else
{
// Only need to do this once
Registrar.RegisterAll(new[] {
typeof(ExportRendererAttribute),
typeof(ExportCellAttribute),
typeof(ExportImageSourceHandlerAttribute),
typeof(ExportFontAttribute)
});
}
}
}

static void RegisterSkiaSharpRenderers()
{
// Register all skiasharp-based rednerers here.
Expand Down
10 changes: 8 additions & 2 deletions src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ public MockParentHandler(VisualElement parent)

public IMauiContext MauiContext => null;

object IViewHandler.NativeView => NativeView;
object IElementHandler.NativeView => NativeView;

object IViewHandler.ContainerView => NativeView;

bool HasContainer { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
bool IViewHandler.HasContainer { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

Maui.IElement IElementHandler.VirtualView => throw new NotImplementedException();

public void DisconnectHandler() { }

public void Dispose()
Expand Down Expand Up @@ -170,6 +171,11 @@ public void UpdateValue(string property)
{
throw new NotImplementedException();
}

public void SetVirtualView(Maui.IElement view)
{
throw new NotImplementedException();
}
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/Compatibility/Core/src/Tizen/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal static IVisualElementRenderer CreateRenderer(VisualElement element)
//TODO: Handle this with AppBuilderHost
try
{
handler = Forms.MauiContext.Handlers.GetHandler(element.GetType());
handler = Forms.MauiContext.Handlers.GetHandler(element.GetType()) as IViewHandler;
handler.SetMauiContext(Forms.MauiContext);
}
catch
Expand Down
12 changes: 12 additions & 0 deletions src/Controls/src/Core/HandlerImpl/Window.Tizen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#nullable enable
using System;
using EWindow = ElmSharp.Window;

namespace Microsoft.Maui.Controls
{
public partial class Window
{
internal EWindow NativeWindow =>
(Handler?.NativeView as EWindow) ?? throw new InvalidOperationException("Window should have a ElmSharp.Window set.");
}
}
19 changes: 19 additions & 0 deletions src/Controls/src/Core/Platform/AlertManager/AlertManager.Tizen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace Microsoft.Maui.Controls.Platform
{
internal partial class AlertManager
{
internal static void Subscribe(Window window)
{
//TODO: Need to implementation
//throw new NotImplementedException();
}

internal static void Unsubscribe(Window window)
{
//TODO: Need to implementation
//throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Microsoft.Maui.Controls.Platform
{
internal partial class ModalNavigationService
internal partial class ModalNavigationManager
{
ModalStack _modalStack => MauiContext.Context!.ModalStack;
IPageController CurrentPageController => _navModel.CurrentPage;
Expand Down
5 changes: 5 additions & 0 deletions src/Core/src/Handlers/Label/LabelHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public static void MapHorizontalTextAlignment(LabelHandler handler, ILabel label
handler.NativeView?.UpdateHorizontalTextAlignment(label);
}

public static void MapVerticalTextAlignment(LabelHandler handler, ILabel label)
{
handler.NativeView?.UpdateVerticalTextAlignment(label);
}

public static void MapLineBreakMode(LabelHandler handler, ILabel label)
{
handler.NativeView?.UpdateLineBreakMode(label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected override EProgressBar CreateNativeView()
return progressBar;
}

protected override void SetupDefaults(EProgressBar nativeView)
void SetupDefaults(EProgressBar nativeView)
{
nativeView.Color = ThemeConstants.ProgressBar.ColorClass.Default;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Slider/SliderHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected override void DisconnectHandler(ESlider nativeView)
nativeView!.DragStopped -= OnDragStopped;
}

protected override void SetupDefaults(ESlider nativeView)
void SetupDefaults(ESlider nativeView)
{
DefaultMinTrackColor = nativeView.GetBarColor();
DefaultMaxTrackColor = nativeView.GetBackgroundColor();
Expand Down
6 changes: 3 additions & 3 deletions src/Core/src/Handlers/View/ViewHandlerOfT.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ protected virtual void Dispose(bool disposing)
if (disposing)
{
// Dispose managed state (managed objects)
if (WrappedNativeView != null)
if (WrappedNativeView is TNativeView wrapped)
{
DisconnectHandler(WrappedNativeView);
WrappedNativeView.Unrealize();
DisconnectHandler(wrapped);
wrapped.Unrealize();
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/Core/src/Handlers/Window/WindowHandler.Tizen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using ElmSharp;

namespace Microsoft.Maui.Handlers
{
public partial class WindowHandler : ElementHandler<IWindow, Window>
{
public static void MapTitle(WindowHandler handler, IWindow window) { }

public static void MapContent(WindowHandler handler, IWindow window)
{
_ = handler.MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");
_ = handler.MauiContext.Context ?? throw new InvalidOperationException($"{nameof(CoreUIAppContext)} should have been set by base class.");

var nativeContent = window.Content.ToNative(handler.MauiContext);
handler.MauiContext.Context.SetContent(nativeContent);
}
}
}
2 changes: 2 additions & 0 deletions src/Core/src/Handlers/Window/WindowHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using NativeView = Android.App.Activity;
#elif WINDOWS
using NativeView = Microsoft.UI.Xaml.Window;
#elif TIZEN
using NativeView = ElmSharp.Window;
#endif

namespace Microsoft.Maui.Handlers
Expand Down
2 changes: 2 additions & 0 deletions src/Core/src/LifecycleEvents/Tizen/TizenLifecycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public static class TizenLifecycle
public delegate void OnRegionFormatChanged(CoreUIApplication application, RegionFormatChangedEventArgs e);
public delegate void OnTerminate(CoreUIApplication application);

// Internal events
internal delegate void OnMauiContextCreated(IMauiContext mauiContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public static class TizenLifecycleBuilderExtensions
public static ITizenLifecycleBuilder OnLowMemory(this ITizenLifecycleBuilder lifecycle, TizenLifecycle.OnLowMemory del) => lifecycle.OnEvent(del);
public static ITizenLifecycleBuilder OnRegionFormatChanged(this ITizenLifecycleBuilder lifecycle, TizenLifecycle.OnRegionFormatChanged del) => lifecycle.OnEvent(del);
public static ITizenLifecycleBuilder OnTerminate(this ITizenLifecycleBuilder lifecycle, TizenLifecycle.OnTerminate del) => lifecycle.OnEvent(del);

internal static ITizenLifecycleBuilder OnMauiContextCreated(this ITizenLifecycleBuilder lifecycle, TizenLifecycle.OnMauiContextCreated del) => lifecycle.OnEvent(del);
}
}
1 change: 1 addition & 0 deletions src/Core/src/Platform/IMauiContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IMauiContext
Android.Content.Context? Context { get; }
#elif TIZEN
CoreUIAppContext? Context { get; }
ElmSharp.Window? Window { get; }
#endif
}
}
2 changes: 2 additions & 0 deletions src/Core/src/Platform/MauiContext.Tizen.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ElmSharp;

namespace Microsoft.Maui
{
Expand Down Expand Up @@ -33,5 +34,6 @@ public CoreUIAppContext? Context
}
}

public Window? Window => Context?.MainWindow;
}
}
1 change: 0 additions & 1 deletion src/Core/src/Platform/Tizen/CoreUIAppContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public static CoreUIAppContext GetInstance(CoreApplication application, Window?
if (IsInitialized)
return _instance!;


_instance = (window == null) ? new CoreUIAppContext(application) : new CoreUIAppContext(application, window);
return _instance;
}
Expand Down
44 changes: 29 additions & 15 deletions src/Core/src/Platform/Tizen/HandlerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Tizen.Applications;
using ElmSharp;

namespace Microsoft.Maui
Expand All @@ -15,34 +16,47 @@ public static EvasObject ToNative(this IView view, IMauiContext context)
view = ir.ReplacedView;

var handler = view.Handler;

if (handler?.MauiContext != null &&
handler.MauiContext != context)
{
if (handler?.MauiContext != null && handler.MauiContext != context)
handler = null;
}

if (handler == null)
{
handler = context.Handlers.GetHandler(view.GetType());
handler = context.Handlers.GetHandler(view.GetType()) as IViewHandler;

if (handler == null)
throw new Exception($"Handler not found for view {view} or was not {nameof(IViewHandler)}.");

if (handler == null)
throw new Exception($"Handler not found for view {view}");
handler.SetMauiContext(context);

handler.SetMauiContext(context);
view.Handler = handler;
}
view.Handler = handler;

if (handler.VirtualView != view)
handler.SetVirtualView(view);


if (((INativeViewHandler)handler).NativeView is not EvasObject result)
{
throw new InvalidOperationException($"Unable to convert {view} to {typeof(EvasObject)}");
}

return result;
}

public static void SetWindow(this Window nativeWindow, IWindow window, IMauiContext mauiContext)
{
_ = nativeWindow ?? throw new ArgumentNullException(nameof(nativeWindow));
_ = window ?? throw new ArgumentNullException(nameof(window));
_ = mauiContext ?? throw new ArgumentNullException(nameof(mauiContext));

var handler = window.Handler as IWindowHandler;
if (handler == null)
handler = mauiContext.Handlers.GetHandler(window.GetType()) as IWindowHandler;

if (handler == null)
throw new Exception($"Handler not found for view {window} or was not {nameof(IWindowHandler)}'");

handler.SetMauiContext(mauiContext);

window.Handler = handler;

if (handler.VirtualView != window)
handler.SetVirtualView(window);
}
}
}
5 changes: 5 additions & 0 deletions src/Core/src/Platform/Tizen/LabelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public static void UpdateHorizontalTextAlignment(this Label nativeLabel, ILabel
nativeLabel.HorizontalTextAlignment = label.HorizontalTextAlignment.ToNative();
}

public static void UpdateVerticalTextAlignment(this Label nativeLabel, ILabel label)
{
nativeLabel.VerticalTextAlignment = label.VerticalTextAlignment.ToNative();
}

public static void UpdateLineBreakMode(this Label nativeLabel, ILabel label)
{
nativeLabel.LineBreakMode = label.LineBreakMode.ToNative();
Expand Down
Loading

0 comments on commit 97edd75

Please sign in to comment.