Merge branch 'master' into listview-subviews

This commit is contained in:
Frank A. Krueger 2019-01-05 12:11:20 -06:00 committed by GitHub
commit ff6ca1f0b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 189 additions and 34 deletions

100
Ooui.Forms/ActionSheet.cs Normal file
View File

@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms.Internals;
namespace Ooui.Forms
{
public class ActionSheet
{
private readonly Button _cancelButton;
private readonly List<Button> _buttons;
public Element Element { get; private set; }
public ActionSheet(ActionSheetArguments arguments)
{
Element = new Div();
Element.ClassName = "modal-dialog";
var content = new Div();
content.ClassName = "modal-content";
var header = new Div();
header.ClassName = "modal-header";
var h4 = new Heading(4)
{
Text = arguments.Title
};
header.AppendChild(h4);
content.AppendChild(header);
var body = new Div();
body.ClassName = "modal-body";
content.AppendChild(body);
_buttons = new List<Button>();
foreach (var button in arguments.Buttons)
{
var btnBody = new Div();
btnBody.Style.MarginBottom = 5;
var btn = new Button(button);
btn.Style.Width = "100%";
btn.ClassName = "btn";
btn.Click += (s,e) => SetResult(button);
_buttons.Add(btn);
btnBody.AppendChild(btn);
body.AppendChild(btnBody);
}
if (!string.IsNullOrEmpty(arguments.Cancel))
{
var footer = new Div();
footer.ClassName = "modal-footer";
_cancelButton = new Button(arguments.Cancel);
_cancelButton.ClassName = "btn -btn-default";
_cancelButton.Click += (s, e) => SetResult(arguments.Cancel);
footer.AppendChild(_cancelButton);
content.AppendChild(footer);
}
Element.AppendChild(content);
void SetResult(string result)
{
arguments.SetResult(result);
}
}
public event TargetEventHandler Clicked
{
add
{
_cancelButton.Click += value;
foreach (var btn in _buttons)
{
btn.Click += value;
}
}
remove
{
_cancelButton.Click -= value;
foreach (var btn in _buttons)
{
btn.Click -= value;
}
}
}
}
}

View File

@ -45,6 +45,19 @@ namespace Ooui.Forms
_renderer.RemoveChild (alert.Element); _renderer.RemoveChild (alert.Element);
} }
}); });
MessagingCenter.Subscribe(this, Page.ActionSheetSignalName, (Page sender, ActionSheetArguments arguments) =>
{
var sheet = new ActionSheet(arguments);
sheet.Clicked += CloseSheet;
_renderer.AppendChild(sheet.Element);
void CloseSheet (object s, EventArgs e)
{
_renderer.RemoveChild(sheet.Element);
}
});
} }
void IDisposable.Dispose () void IDisposable.Dispose ()

View File

@ -110,32 +110,37 @@ namespace Ooui.Forms.Renderers
Element.SetStyleFont (Element.FontFamily, Element.FontSize, Element.FontAttributes, Control.Style); Element.SetStyleFont (Element.FontFamily, Element.FontSize, Element.FontAttributes, Control.Style);
} }
void UpdateImage () async void UpdateImage ()
{ {
//IImageSourceHandler handler; IImageSourceHandler handler;
//FileImageSource source = Element.Image; FileImageSource source = Element.Image;
//if (source != null && (handler = Internals.Registrar.Registered.GetHandlerForObject<IImageSourceHandler> (source)) != null) {
// UIImage uiimage;
// try {
// uiimage = await handler.LoadImageAsync (source, scale: (float)UIScreen.MainScreen.Scale);
// }
// catch (OperationCanceledException) {
// uiimage = null;
// }
// Ooui.Button button = Control;
// if (button != null && uiimage != null) {
// button.SetImage (uiimage.ImageWithRenderingMode (UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);
// button.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit; if (source != null &&
(handler = Xamarin.Forms.Internals.Registrar.Registered.GetHandler<IImageSourceHandler>(source.GetType())) != null)
{
string uiimage;
try
{
uiimage = await handler.LoadImageAsync(source, scale: 1.0f);
}
catch (OperationCanceledException)
{
uiimage = null;
}
// ComputeEdgeInsets (Control, Element.ContentLayout); var Button = Control;
// } if (Button != null && uiimage != null)
//} {
//else { Button.Style.BackgroundImage = uiimage;
// Control.SetImage (null, UIControlState.Normal); Button.Style.BackgroundPosition = "center";
// ClearEdgeInsets (Control); }
//} }
//((IVisualElementController)Element).NativeSizeChanged (); else
{
Control.Style.BackgroundImage = null;
Control.Style.BackgroundPosition = null;
}
((IVisualElementController)Element).NativeSizeChanged ();
} }
void UpdateText () void UpdateText ()

View File

@ -59,6 +59,7 @@ namespace Ooui.Forms.Renderers
UpdateRowHeight(); UpdateRowHeight();
UpdateItems (); UpdateItems ();
UpdateSeparator ();
UpdateBackgroundColor (); UpdateBackgroundColor ();
} }
@ -94,7 +95,10 @@ namespace Ooui.Forms.Renderers
} }
_timer.Start(); _timer.Start();
} }
else if (e.PropertyName == Xamarin.Forms.ListView.SeparatorColorProperty.PropertyName)
UpdateSeparator ();
else if (e.PropertyName == Xamarin.Forms.ListView.SeparatorVisibilityProperty.PropertyName)
UpdateSeparator ();
} }
protected override void Dispose (bool disposing) protected override void Dispose (bool disposing)
@ -131,6 +135,7 @@ namespace Ooui.Forms.Renderers
private void OnCollectionChanged (object sender, NotifyCollectionChangedEventArgs e) private void OnCollectionChanged (object sender, NotifyCollectionChangedEventArgs e)
{ {
UpdateItems (); UpdateItems ();
UpdateSeparator ();
} }
private void UnsubscribeCellClicks () private void UnsubscribeCellClicks ()
@ -200,6 +205,27 @@ namespace Ooui.Forms.Renderers
} }
} }
private void UpdateSeparator()
{
if (Control == null)
return;
var listItems = Control.Children.OfType<ListItem>().ToList();
foreach (var li in listItems)
{
if (Element.SeparatorVisibility == SeparatorVisibility.Default)
{
var color = Element.SeparatorColor.ToOouiColor(Color.FromStyleValue("#999"));
li.Style["border-bottom"] = string.Format("{0}px {1} {2}", 1, "solid", color.ToString());
}
else
{
li.Style["border-bottom"] = null;
}
}
}
void ListItem_Click (object sender, TargetEventArgs e) void ListItem_Click (object sender, TargetEventArgs e)
{ {
if (Control == null) if (Control == null)

View File

@ -32,9 +32,14 @@ namespace Ooui
public Value BackgroundImage { public Value BackgroundImage {
get => this["background-image"]; get => this["background-image"];
set => this["background-image"] = value; set => this["background-image"] = AddUrl(value);
} }
public Value BackgroundPosition {
get => this["background-position"];
set => this["background-position"] = value;
}
public Value BorderTopColor { public Value BorderTopColor {
get => this["border-top-color"]; get => this["border-top-color"];
set => this["border-top-color"] = value; set => this["border-top-color"] = value;
@ -219,31 +224,31 @@ namespace Ooui
public Value MarginTop { public Value MarginTop {
get => this["margin-top"]; get => this["margin-top"];
set => this["margin-top"] = value; set => this["margin-top"] = AddNumberUnits (value, "px");
} }
public Value MarginRight { public Value MarginRight {
get => this["margin-right"]; get => this["margin-right"];
set => this["margin-right"] = value; set => this["margin-right"] = AddNumberUnits (value, "px");
} }
public Value MarginBottom { public Value MarginBottom {
get => this["margin-bottom"]; get => this["margin-bottom"];
set => this["margin-bottom"] = value; set => this["margin-bottom"] = AddNumberUnits (value, "px");
} }
public Value MarginLeft { public Value MarginLeft {
get => this["margin-left"]; get => this["margin-left"];
set => this["margin-left"] = value; set => this["margin-left"] = AddNumberUnits (value, "px");
} }
public Value Margin { public Value Margin {
get => this["margin-top"]; get => this["margin-top"];
set { set {
this["margin-top"] = value; this["margin-top"] = AddNumberUnits (value, "px");
this["margin-right"] = value; this["margin-right"] = AddNumberUnits (value, "px");
this["margin-bottom"] = value; this["margin-bottom"] = AddNumberUnits (value, "px");
this["margin-left"] = value; this["margin-left"] = AddNumberUnits (value, "px");
} }
} }
@ -425,7 +430,13 @@ namespace Ooui
} }
return o.ToString (); return o.ToString ();
} }
static string AddUrl(object val)
{
if (val == null)
return null;
return String.Format("url('{0}')", val);
}
static string AddNumberUnits (object val, string units) static string AddNumberUnits (object val, string units)
{ {
if (val == null) if (val == null)