Skip to content

Commit

Permalink
Bump to latest
Browse files Browse the repository at this point in the history
- Adds the GraphicsViewHandler and ShapeViewHandler
- Apply one stop shop UseMauiControls (dotnet#1157)
- Implements new APIs for each IView
- and so on
  • Loading branch information
rookiejava committed Apr 3, 2022
1 parent 9d38a04 commit a2a5479
Show file tree
Hide file tree
Showing 26 changed files with 352 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/Compatibility/Core/src/Forms.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !(__ANDROID__ || __IOS__ || WINDOWS || (__TIZEN__ || TIZEN))
#if !(__ANDROID__ || __IOS__ || WINDOWS || TIZEN)
using System;
using System.Collections.Generic;
using System.Text;
Expand Down
15 changes: 12 additions & 3 deletions src/Compatibility/Core/src/Tizen/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public static bool IsInitialized

public static bool UseFastLayout { get; private set; }

public static DisplayResolutionUnit DisplayResolutionUnit { get; private set; }
public static DisplayResolutionUnit DisplayResolutionUnit { get; private set; } = DisplayResolutionUnit.Pixel();

public static int ScreenDPI => s_dpi.Value;

Expand Down Expand Up @@ -394,11 +394,13 @@ public static TOut GetHandlerForObject<TOut>(object obj, params object[] args) w

public static void Init(IActivationState activationState) => Init(activationState.Context);

public static void Init(IActivationState activationState, InitializationOptions options) => Init(activationState.Context, options);

public static void Init(CoreApplication application) => Init(new MauiContext(CoreUIAppContext.GetInstance(application)));

public static void Init(IMauiContext context)
public static void Init(IMauiContext context, InitializationOptions options = null)
{
SetupInit(context);
SetupInit(context, options);
}

public static void Init(CoreApplication application, bool useDeviceIndependentPixel)
Expand Down Expand Up @@ -465,6 +467,13 @@ static void SetupInit(IMauiContext context, InitializationOptions options = null
IsInitialized = true;
}

// Once we get essentials/cg converted to using startup.cs
// we will delete all the renderer code inside this file
internal static void RenderersRegistered()
{
IsInitializedRenderers = true;
}

internal static void RegisterCompatRenderers(InitializationOptions options)
{
if (!IsInitializedRenderers)
Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;
using EvasObject = ElmSharp.EvasObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using ElmSharp;
using Microsoft.Maui.Controls.Platform;
using ERect = ElmSharp.Rect;

namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using ElmSharp;
using ElmSharp.Accessible;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native;
using Size = Microsoft.Maui.Graphics.Size;
Expand Down
17 changes: 0 additions & 17 deletions src/Compatibility/Core/src/Tizen/VisualElementChangedEventArgs.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>tizen40</TargetFramework>
<!--<DisableImplicitFrameworkReferences>True</DisableImplicitFrameworkReferences>-->
<!--<TargetIdentifier>Tizen</TargetIdentifier>-->
<RootNamespace>Maui.Controls.Sample.Tizen</RootNamespace>
<AssemblyName>Maui.Controls.Sample.Tizen</AssemblyName>
</PropertyGroup>
Expand Down
7 changes: 5 additions & 2 deletions src/Controls/samples/Controls.Sample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public static MauiApp CreateMauiApp()
//#elif WINDOWS
// handlers.AddCompatibilityRenderer(typeof(CustomButton),
// typeof(Microsoft.Maui.Controls.Compatibility.Platform.UWP.ButtonRenderer));
//#endif
// #elif TIZEN
// handlers.AddCompatibilityRenderer(typeof(CustomButton),
// typeof(Microsoft.Maui.Controls.Compatibility.Platform.Tizen.ButtonRenderer));
// #endif
//#pragma warning restore CS0618 // Type or member is obsolete
// });

Expand Down Expand Up @@ -227,7 +230,7 @@ public static MauiApp CreateMauiApp()
.OnClosed((a, b) => LogEvent(nameof(WindowsLifecycle.OnClosed)))
.OnLaunched((a, b) => LogEvent(nameof(WindowsLifecycle.OnLaunched)))
.OnVisibilityChanged((a, b) => LogEvent(nameof(WindowsLifecycle.OnVisibilityChanged))));
#elif __TIZEN__ || TIZEN
#elif TIZEN
events.AddTizen(tizen => tizen
.OnAppControlReceived((a, b) => LogEvent(nameof(TizenLifecycle.OnAppControlReceived)))
.OnCreate((a) => LogEvent(nameof(TizenLifecycle.OnCreate)))
Expand Down
5 changes: 5 additions & 0 deletions src/Core/src/Handlers/Editor/EditorHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public static void MapFormatting(EditorHandler handler, IEditor editor)
handler.NativeView?.UpdateMaxLength(editor);
}

public static void MapKeyboard(EditorHandler handler, IEditor editor)
{
handler.NativeView?.UpdateKeyboard(editor);
}

[MissingMapper]
public static void MapCharacterSpacing(EditorHandler handler, IEditor editor) { }

Expand Down
71 changes: 71 additions & 0 deletions src/Core/src/Handlers/Entry/EntryHandler.Tizen.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using Tizen.UIExtensions.ElmSharp;
using SmartEvent = ElmSharp.SmartEvent;
using EEntry = ElmSharp.Entry;

namespace Microsoft.Maui.Handlers
{
public partial class EntryHandler : ViewHandler<IEntry, Entry>
{

protected override Entry CreateNativeView()
{
return new EditfieldEntry(NativeParent)
Expand All @@ -17,14 +19,37 @@ protected override Entry CreateNativeView()
protected override void ConnectHandler(Entry nativeView)
{
nativeView.Activated += OnCompleted;
nativeView.CursorChanged += OnCursorChanged;

// In order to know when the selection is cleared, "selecton,cleared" event has been used.
// Because CursorChanged event is still invoked with the selected text when an user clears selection. It is an known issue in EFL.
SmartEvent selectionCleared = new SmartEvent(nativeView, nativeView.RealHandle, ThemeConstants.Entry.Signals.SelectionCleared);
selectionCleared.On += OnSelectionCleared;

nativeView.TextChanged += OnTextChanged;
nativeView.EntryLayoutFocused += OnFocused;
nativeView.EntryLayoutUnfocused += OnUnfocused;

nativeView.PrependMarkUpFilter(MaxLengthFilter);

// TODO: Fix me later
// An initial CursorPosition is set after layouting to avoid timing issue when the EditField entry is initialized.
//if (VirtualView != null)
//{
// MainThread.BeginInvokeOnMainThread(() =>
// {
// nativeView.UpdateSelectionLength(VirtualView);
// });
//}
}

protected override void DisconnectHandler(Entry nativeView)
{
nativeView.Activated -= OnCompleted;
nativeView.CursorChanged -= OnCursorChanged;
nativeView.TextChanged -= OnTextChanged;
nativeView.EntryLayoutFocused -= OnFocused;
nativeView.EntryLayoutUnfocused -= OnUnfocused;
}

public static void MapText(EntryHandler handler, IEntry entry)
Expand Down Expand Up @@ -101,6 +126,21 @@ public static void MapFormatting(EntryHandler handler, IEntry entry)
handler.NativeView?.UpdateHorizontalTextAlignment(entry);
}

public static void MapSelectionLength(EntryHandler handler, IEntry entry)
{
handler.NativeView?.UpdateSelectionLength(entry);
}

public static void MapCursorPosition(EntryHandler handler, IEntry entry)
{
handler.NativeView?.UpdateSelectionLength(entry);
}

public static void MapKeyboard(EditorHandler handler, IEditor editor)
{
handler.NativeView?.UpdateKeyboard(editor);
}

[MissingMapper]
public static void MapCharacterSpacing(EntryHandler handler, IEntry entry) { }

Expand All @@ -123,6 +163,37 @@ void OnTextChanged(object? sender, EventArgs e)
VirtualView.Text = NativeView.Text;
}

void OnCursorChanged(object? sender, EventArgs e)
{
if (VirtualView == null || NativeView == null)
return;

var position = NativeView.CursorPosition;

NativeView.GetSelectRegion(out int start, out int end);

if (start > -1)
{
position = (start < end) ? start : end;
var selectionLength = Math.Abs(end - start);
VirtualView.SelectionLength = selectionLength;
}

VirtualView.CursorPosition = position;
}

void OnSelectionCleared(object sender, EventArgs e)
{
if (VirtualView == null || NativeView == null)
return;

if (NativeView.IsFocused)
{
VirtualView.SelectionLength = 0;
VirtualView.CursorPosition = NativeView.CursorPosition;
}
}

void OnCompleted(object? sender, EventArgs e)
{
if (NativeView == null)
Expand Down
17 changes: 17 additions & 0 deletions src/Core/src/Handlers/GraphicsView/GraphicsViewHandler.Tizen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.Maui.Graphics.Skia.Views;

namespace Microsoft.Maui.Handlers
{
public partial class GraphicsViewHandler : ViewHandler<IGraphicsView, SkiaGraphicsView>
{
protected override SkiaGraphicsView CreateNativeView()
{
return new SkiaGraphicsView(NativeParent);
}

public static void MapDrawable(GraphicsViewHandler handler, IGraphicsView graphicsView)
{
handler.NativeView?.UpdateDrawable(graphicsView);
}
}
}
11 changes: 6 additions & 5 deletions src/Core/src/Handlers/Page/PageHandler.Tizen.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
using System;
using Tizen.UIExtensions.Common;
using Tizen.UIExtensions.ElmSharp;
using NativeView = ElmSharp.EvasObject;

namespace Microsoft.Maui.Handlers
{
public partial class PageHandler : ViewHandler<IPage, PageView>, INativeViewHandler
public partial class PageHandler : ViewHandler<IPage, Page>, INativeViewHandler
{
INativeViewHandler? _contentHandler;

protected override PageView CreateNativeView()
protected override Page CreateNativeView()
{
_ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} must be set to create a Page");
_ = NativeParent ?? throw new InvalidOperationException($"{nameof(NativeParent)} cannot be null");

var view = new PageView(NativeParent);
var view = new Page(NativeParent);
view.Show();
return view;
}

protected override void ConnectHandler(PageView nativeView)
protected override void ConnectHandler(Page nativeView)
{
base.ConnectHandler(nativeView);
nativeView.LayoutUpdated += OnLayoutUpdated;
}

protected override void DisconnectHandler(PageView nativeView)
protected override void DisconnectHandler(Page nativeView)
{
base.DisconnectHandler(nativeView);
nativeView.LayoutUpdated -= OnLayoutUpdated;
Expand Down
5 changes: 5 additions & 0 deletions src/Core/src/Handlers/Picker/PickerHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ void Reload()

public static void MapReload(PickerHandler handler, IPicker picker) => handler.Reload();

public static void MapTitleColor(PickerHandler handler, IPicker picker)
{
handler.NativeView?.UpdateTitleColor(picker);
}

public static void MapFont(PickerHandler handler, IPicker picker)
{
var fontManager = handler.GetRequiredService<IFontManager>();
Expand Down
9 changes: 9 additions & 0 deletions src/Core/src/Handlers/SearchBar/SearchBarHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ protected override void ConnectHandler(SearchBar nativeView)
nativeView.Activated += OnActivated;
nativeView.TextChanged += OnTextChanged;
nativeView.PrependMarkUpFilter(MaxLengthFilter);
nativeView.EntryLayoutFocused += OnFocused;
nativeView.EntryLayoutUnfocused += OnUnfocused;

}

protected override void DisconnectHandler(SearchBar nativeView)
{
nativeView.Activated -= OnActivated;
nativeView.TextChanged -= OnTextChanged;
nativeView.EntryLayoutFocused -= OnFocused;
nativeView.EntryLayoutUnfocused -= OnUnfocused;
}

public static void MapText(SearchBarHandler handler, ISearchBar searchBar)
Expand Down Expand Up @@ -90,6 +94,11 @@ public static void MapFormatting(SearchBarHandler handler, ISearchBar searchBar)
handler.NativeView?.UpdateHorizontalTextAlignment(searchBar);
}

public static void MapCancelButtonColor(SearchBarHandler handler, ISearchBar searchBar)
{
handler.NativeView?.UpdateCancelButtonColor(searchBar);
}

[MissingMapper]
public static void MapCharacterSpacing(SearchBarHandler handler, ISearchBar searchBar) { }

Expand Down
57 changes: 57 additions & 0 deletions src/Core/src/Handlers/ShapeView/ShapeViewHandler.Tizen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Handlers
{
public partial class ShapeViewHandler : ViewHandler<IShapeView, MauiShapeView>
{
protected override MauiShapeView CreateNativeView()
{
return new MauiShapeView(NativeParent!);
}

public static void MapShape(ShapeViewHandler handler, IShapeView shapeView)
{
handler.NativeView?.UpdateShape(shapeView);
}

public static void MapAspect(ShapeViewHandler handler, IShapeView shapeView)
{
handler.NativeView?.InvalidateShape(shapeView);
}

public static void MapFill(ShapeViewHandler handler, IShapeView shapeView)
{
handler.NativeView?.InvalidateShape(shapeView);
}

public static void MapStroke(ShapeViewHandler handler, IShapeView shapeView)
{
handler.NativeView?.InvalidateShape(shapeView);
}

public static void MapStrokeThickness(ShapeViewHandler handler, IShapeView shapeView)
{
handler.NativeView?.InvalidateShape(shapeView);
}

public static void MapStrokeDashPattern(ShapeViewHandler handler, IShapeView shapeView)
{
handler.NativeView?.InvalidateShape(shapeView);
}

public static void MapStrokeLineCap(ShapeViewHandler handler, IShapeView shapeView)
{
handler.NativeView?.InvalidateShape(shapeView);
}

public static void MapStrokeLineJoin(ShapeViewHandler handler, IShapeView shapeView)
{
handler.NativeView?.InvalidateShape(shapeView);
}

public static void MapStrokeMiterLimit(ShapeViewHandler handler, IShapeView shapeView)
{
handler.NativeView?.InvalidateShape(shapeView);
}
}
}
Loading

0 comments on commit a2a5479

Please sign in to comment.