-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set alignment for buttons in SheetView (#250)
* Set alignment for buttons in SheetView * added custom renderers for fixing text alignment in sheet view button. * Added xml comments * added xml comments * added xml comments * Added initalize method
- Loading branch information
Showing
8 changed files
with
258 additions
and
27 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
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,121 @@ | ||
using System.ComponentModel; | ||
using Android.Content; | ||
using Android.Views; | ||
using DIPS.Xamarin.UI.Android; | ||
using DIPS.Xamarin.UI.Internal; | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Platform.Android; | ||
using TextAlignment = Xamarin.Forms.TextAlignment; | ||
|
||
[assembly: ExportRenderer(typeof(InternalButton), typeof(InternalButtonRenderer))] | ||
|
||
namespace DIPS.Xamarin.UI.Android | ||
{ | ||
/// <summary> | ||
/// An internal class to use when having to interact with the buttons on Android platform | ||
/// </summary> | ||
internal class InternalButtonRenderer : ButtonRenderer | ||
{ | ||
/// <summary> | ||
/// Setting initialization | ||
/// </summary> | ||
internal static void Initialize() { } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="context"></param> | ||
public InternalButtonRenderer(Context context) : base(context) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets element from base class | ||
/// </summary> | ||
public new InternalButton Element => (InternalButton)base.Element; | ||
|
||
/// <summary> | ||
/// Called when [element changed]. | ||
/// </summary> | ||
protected override void OnElementChanged(ElementChangedEventArgs<Button> e) | ||
{ | ||
base.OnElementChanged(e); | ||
|
||
if (e.NewElement == null) | ||
{ | ||
return; | ||
} | ||
|
||
SetHorizonalTextAlignment(); | ||
SetVerticalTextAlignment(); | ||
} | ||
|
||
/// <summary> | ||
/// Handles the <see cref="E:ElementPropertyChanged" /> event. | ||
/// </summary> | ||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) | ||
{ | ||
base.OnElementPropertyChanged(sender, e); | ||
|
||
if (e.PropertyName == InternalButton.HorizontalTextAlignmentProperty.PropertyName) | ||
{ | ||
SetHorizonalTextAlignment(); | ||
} | ||
|
||
if (e.PropertyName == InternalButton.VerticalTextAlignmentProperty.PropertyName) | ||
{ | ||
SetVerticalTextAlignment(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// To set the horizontal text alignment. | ||
/// </summary> | ||
private void SetHorizonalTextAlignment() | ||
{ | ||
Control.Gravity = Element.HorizontalTextAlignment.ToHorizontalGravityFlags() | | ||
Element.VerticalTextAlignment.ToVerticalGravityFlags(); | ||
} | ||
|
||
/// <summary> | ||
/// To set the vertical text alignment. | ||
/// </summary> | ||
private void SetVerticalTextAlignment() | ||
{ | ||
Control.Gravity = Element.VerticalTextAlignment.ToVerticalGravityFlags() | | ||
Element.HorizontalTextAlignment.ToHorizontalGravityFlags(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// An internal class to set the flags for horizontal, vertictal text alignment. | ||
/// </summary> | ||
internal static class AlignmentHelper | ||
{ | ||
/// <summary> | ||
/// To set the flags for horizontal text alignment. | ||
/// </summary> | ||
public static GravityFlags ToHorizontalGravityFlags(this TextAlignment alignment) | ||
{ | ||
if (alignment == TextAlignment.Center) | ||
{ | ||
return GravityFlags.CenterHorizontal; | ||
} | ||
|
||
return alignment == TextAlignment.End ? GravityFlags.Right : GravityFlags.Left; | ||
} | ||
|
||
/// <summary> | ||
/// To set the flags for vertictal text alignment. | ||
/// </summary> | ||
public static GravityFlags ToVerticalGravityFlags(this TextAlignment alignment) | ||
{ | ||
if (alignment == TextAlignment.Center) | ||
{ | ||
return GravityFlags.CenterVertical; | ||
} | ||
|
||
return alignment == TextAlignment.End ? GravityFlags.Top : GravityFlags.Bottom; | ||
} | ||
} | ||
} |
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
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,46 @@ | ||
using Xamarin.Forms; | ||
|
||
namespace DIPS.Xamarin.UI.Internal | ||
{ | ||
/// <summary> | ||
/// An internal class to use when having to interact with the buttons | ||
/// </summary> | ||
internal class InternalButton : Button | ||
{ | ||
/// <summary> | ||
/// Bindable property for horizontal text alignment of a button. | ||
/// </summary> | ||
public static BindableProperty HorizontalTextAlignmentProperty = | ||
BindableProperty.Create(nameof(HorizontalTextAlignment), | ||
typeof(TextAlignment), | ||
typeof(InternalButton), | ||
TextAlignment.Center); | ||
|
||
/// <summary> | ||
/// Bindable property for vertical text alignment of a button. | ||
/// </summary> | ||
public static BindableProperty VerticalTextAlignmentProperty = | ||
BindableProperty.Create(nameof(VerticalTextAlignment), | ||
typeof(TextAlignment), | ||
typeof(InternalButton), | ||
TextAlignment.Center); | ||
|
||
/// <summary> | ||
/// Gets or sets the horizontal text alignment. | ||
/// </summary> | ||
public TextAlignment HorizontalTextAlignment | ||
{ | ||
get => (TextAlignment)GetValue(HorizontalTextAlignmentProperty); | ||
set => SetValue(HorizontalTextAlignmentProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the vertical text alignment. | ||
/// </summary> | ||
public TextAlignment VerticalTextAlignment | ||
{ | ||
get => (TextAlignment)GetValue(VerticalTextAlignmentProperty); | ||
set => SetValue(VerticalTextAlignmentProperty, value); | ||
} | ||
} | ||
} |
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
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
42 changes: 42 additions & 0 deletions
42
...ro/DIPS.Xamarin.Forms.IssuesRepro/DIPS.Xamarin.Forms.IssuesRepro/Github248/Github248.xaml
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,42 @@ | ||
<?xml version="1.0" | ||
encoding="utf-8"?> | ||
|
||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="DIPS.Xamarin.Forms.IssuesRepro.Github248.Github248" | ||
xmlns:dxui="http://dips.xamarin.ui.com" | ||
xmlns:d="http://xamarin.com/schemas/2014/forms/design" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
<dxui:ModalityLayout> | ||
<dxui:ModalityLayout.Behaviors> | ||
<dxui:SheetBehavior x:Name="sheetBehavior" | ||
IsOpen="True" | ||
IsCancelButtonVisible="True" | ||
CancelTitle="Cancel" | ||
ActionTitle="Save this" | ||
Title="Title" | ||
TitleColor="{dxui:DIPSColor ColorPalette=Dark}" | ||
TitleSize="16" | ||
HeaderColor="{x:Static dxui:ColorPalette.LightLight}" | ||
MinPosition=".5" | ||
MaxPosition="0.98" | ||
IsDraggable="True" | ||
VerticalContentAlignment="Fit"> | ||
<dxui:SheetBehavior.SheetContentTemplate> | ||
<DataTemplate> | ||
<StackLayout Spacing="0" | ||
Orientation="Vertical"> | ||
<Editor x:Name="editor" | ||
TextColor="{x:Static dxui:ColorPalette.Dark}" | ||
Text="Sample text sample text sample text sample text sample iiiii text sample text sample text sample text" | ||
Margin="10,0" | ||
FontSize="Small" | ||
BackgroundColor="{x:Static dxui:ColorPalette.LightAir}" /> | ||
</StackLayout> | ||
</DataTemplate> | ||
</dxui:SheetBehavior.SheetContentTemplate> | ||
</dxui:SheetBehavior> | ||
</dxui:ModalityLayout.Behaviors> | ||
</dxui:ModalityLayout> | ||
</ContentPage> |
15 changes: 15 additions & 0 deletions
15
...DIPS.Xamarin.Forms.IssuesRepro/DIPS.Xamarin.Forms.IssuesRepro/Github248/Github248.xaml.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,15 @@ | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Xaml; | ||
|
||
namespace DIPS.Xamarin.Forms.IssuesRepro.Github248 | ||
{ | ||
[Issue(248)] | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
public partial class Github248 : ContentPage | ||
{ | ||
public Github248() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |