Coder Social home page Coder Social logo

xfgloss's Introduction

XFGloss: Xamarin.Forms UI Enhancements

MyGet CI NuGet

XFGloss icon

XFGloss adds new properties to the Xamarin.Forms standard UI components on the Android and iOS platforms. It uses attached properties and enhanced platform-specific renderers to work its magic. More details are available here.

Building XFGloss requires Visual Studio 2015 with update 3 installed on the Windows platform, or Xamarin Studio 6.0 on the Mac platform. A nuget package is also available for easy inclusion into your Xamarin.Forms projects. See the Adding XFGloss to Your Xamarin.Forms-Based App section below for the needed integration steps.

In the above screenshots, a gradient background was added to the bottom half of the XF ContentPage by adding this code to the Xaml declaration:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xfg="clr-namespace:XFGloss;assembly=XFGloss"
             x:Class="XFGlossSample.Views.AboutPage"
             Title="XFGloss Sample App" Padding="10">
    
    <xfg:ContentPageGloss.BackgroundGradient>
        <xfg:Gradient Rotation="150">
            <xfg:GradientStep StepColor="White" StepPercentage="0" />
            <xfg:GradientStep StepColor="White" StepPercentage=".5" />
            <xfg:GradientStep StepColor="#ccd9ff" StepPercentage="1" />
        </xfg:Gradient>
    </xfg:ContentPageGloss.BackgroundGradient>
    ...
</ContentPage>

XFGloss properties can also be constructed in code. Here's the C# equivalent for the above Xaml.

namespace XFGlossSample.Views
{
    public class AboutPage : ContentPage
    {
        public AboutPage()
        {
            Title = "XFGloss Sample App";
            Padding = 10;
    
			// Manually construct a multi-color gradient at an angle of our choosing
			var bkgrndGradient = new Gradient()
			{
				Rotation = 150,
				Steps = new GradientStepCollection()
				{
					new GradientStep(Color.White, 0),
					new GradientStep(Color.White, .5),
					new GradientStep(Color.FromHex("#ccd9ff"), 1)
				}
			};
    
            ContentPageGloss.SetBackgroundGradient(this, bkgrndGradient);
				
            Content = { ... }
        }
    }
}

You can also instantiate an XFGloss instance to make multiple assignments easier. Note that the gloss instance doesn't have to be retained. It only provides convenient access to the static setters.

// Create a XF Switch component and apply some gloss to it
var onOffSwitch = new Switch();
var gloss = new SwitchGloss(onOffSwitch);
gloss.TintColor = Color.Red;
gloss.ThumbTintColor = Color.Maroon;
gloss.OnTintColor = Color.Green;
gloss.ThumbOnTintColor = Color.Lime;

Sample App

XFGloss Property Example

The XFGloss solution provided in this repository also includes the "XFGlossSample" Xamarin.Forms-based app. It demonstrates all the XFGloss properties being applied in both Xaml and C# code.


New/Enhanced Properties Provided by XFGloss

Some of the properties added by XFGloss already exist on some XF components. For example, the BackgroundColor property is available on many XF components. In such cases, XFGloss adds those properties to other XF components that didn't previously offer them. Other properties like the BackgroundGradient property are completely new to the XF environment.

Here's a brief description of the properties added/expanded by XFGloss:


AccessoryType (iOS only)

AccessoryType Example

Type: XFGloss.CellGlossAccessoryType enum value
Added to: EntryCell, ImageCell, TextCell and ViewCell

Allows specifying the accessory type to be shown on the right side of the cell. Possible values are None, DisclosureIndicator, Checkmark and EditIndicator.

The Android platform doesn't offer accessory types as part of its standard UI, so this property is ignored on Android devices.

The iOS DetailButton and DetailDisclosureButton accessory types aren't currently supported due to Xamarin.Forms' ListView component not allowing the external access needed to react to the user tapping the Details button. I plan to submit a PR that will address this, and will add support for those types to XFGloss once the needed access is available.

The XF TableView component already provides the needed access, so I could add support for those accessory types for use with the TableView only if it is needed in the meantime. Please submit an issue if you would like the TableView-only property to be added before ListView also supports it.

Xaml Example:

<TextCell Text="DisclosureIndicator" xfg:CellGloss.AccessoryType="DisclosureIndicator" />

C# Example:

var cell = new TextCell();
cell.Text = "DisclosureIndicator";
    
CellGloss.SetAccessoryType(cell, CellGlossAccessoryType.DisclosureIndicator);

Sample App Code Excerpts: Xaml, C#


BackgroundColor

BackgroundColor Example

Type: Xamarin.Forms Color
Added to: EntryCell, ImageCell, SwitchCell, TextCell and ViewCell

Allows a color value to be specified as a cell's background color. Possible values are either named colors or numeric color values.

KNOWN ISSUE: The BackgroundColor property does not consistently operate as expected on Android API 21 (Lollipop) when it is applied to a touch enabled element. The material design ripple effect is expected when a user touches the element on API 21 and higher. The effect occurs as expected sometime but not others. In the other cases, the pre-21 highlighting of the entire element occurs instead of the ripple effect. The behavior works as expected (ripple on API 22 and higher, element highlighting on API 20 and lower) on all the other supported Android APIs (16 - 23).

Xaml Example:

<TextCell Text="Red" xfg:CellGloss.BackgroundColor="Red" />

C# Example:

var cell = new TextCell();
cell.Text = "Red";
    
CellGloss.SetBackgroundColor(cell, Color.Red);

Sample App Code Excerpts: Xaml, C#


BackgroundGradient

BackgroundGradient Example

Type: XFGloss.Gradient
Added to: ContentPage, EntryCell, ImageCell, SwitchCell, TextCell and ViewCell

Allows a multiple-color linear gradient to be specified as a content page or cells' background. You can specify as many colors as you like and control their distribution across the fill at any angle. Convenience properties and constructors also make it easy to create two-color horizontal or vertical fills.

KNOWN ISSUE: The BackgroundGradient property does not consistently operate as expected on Android API 21 (Lollipop) when it is applied to a touch enabled element. The material design ripple effect is expected when a user touches the element on API 21 and higher. The effect occurs as expected sometime but not others. In the other cases, the pre-21 highlighting of the entire element occurs instead of the ripple effect. The behavior works as expected (ripple on API 22 and higher, element highlighting on API 20 and lower) on all the other supported Android APIs (16 - 23).

Xaml Example:

<TextCell Text="Red" TextColor="White">
    <xfg:CellGloss.BackgroundGradient>
        <xfg:Gradient StartColor="Red" EndColor="Maroon" IsRotationTopToBottom="true" />
    </xfg:CellGloss.BackgroundGradient>
</TextCell>

<TextCell Text="All Three" TextColor="White" x:Name="rotatingCell">
    <!-- You can also create gradients at any angle with as many steps as you want. -->
    <xfg:CellGloss.BackgroundGradient>
        <xfg:Gradient Rotation="135" x:Name="rotatingGradient">
            <xfg:GradientStep StepColor="Red" StepPercentage="0" />
            <xfg:GradientStep StepColor="Maroon" StepPercentage=".25" />
            <xfg:GradientStep StepColor="Lime" StepPercentage=".4" />
            <xfg:GradientStep StepColor="Green" StepPercentage=".6" />
            <xfg:GradientStep StepColor="Blue" StepPercentage=".75" />
            <xfg:GradientStep StepColor="Navy" StepPercentage="1" />
        </xfg:Gradient>
    </xfg:CellGloss.BackgroundGradient>
</TextCell>

C# Example:

var cell = new TextCell();
cell.Text = "Red";
cell.TextColor = Color.White;

CellGloss.SetBackgroundGradient(cell, new Gradient(Color.Red, Color.Maroon, Gradient.RotationTopToBottom));

// Manually construct a multi-color gradient at an angle of our choosing
var rotatingCell = new TextCell();
rotatingCell.Text = "All Three";
rotatingCell.TextColor = Color.White;

var rotatingGradient = new Gradient(135); // 135 degree angle
rotatingGradient.AddStep(Color.Red, 0);
rotatingGradient.AddStep(Color.Maroon, .25);
rotatingGradient.AddStep(Color.Lime, .4);
rotatingGradient.AddStep(Color.Green, .6);
rotatingGradient.AddStep(Color.Blue, .75);
rotatingGradient.AddStep(Color.Navy, 1);

CellGloss.SetBackgroundGradient(rotatingCell, rotatingGradient);

Sample App Code Excerpts: Xaml, C#


MaxTrackTintColor

MaxTrackTintColor Example

Type: Xamarin.Forms.Color
Added to: Slider

Allows a color value to be specified for a Slider's right side of the track, beginning at the current thumb position. Possible values are either named colors or numeric color values.

KNOWN ISSUE: Modifying this property has no effect on an Android device running API 21 (Lollipop). Android's native support for this property is broken in that API level. This property works as expected on Android devices running all other API levels between 16 (Jelly Bean) and 23 (Marshmallow).

Xaml Example:

<Slider Minimum="0" Maximum="100" Value="25" xfg:SliderGloss.MaxTrackTintColor="Red" /> 

C# Example:

var slider = new Slider { Minimum = 0, Maximum = 100, Value = 25 };
SliderGloss.SetMaxTrackTintColor(slider, Color.Red);

Sample App Code Excerpts: Xaml, C#


MinTrackTintColor

MinTrackTintColor Example

Type: Xamarin.Forms.Color
Added to: Slider

Allows a color value to be specified for a Slider's left side of the track, up to the current thumb position. Possible values are either named colors or numeric color values.

KNOWN ISSUE: Modifying this property causes both the left and right sides of the track's colors to be changed on Android devices running API 21 (Lollipop). Android's native support for this property was incorrectly implemented in that API level. This property works as expected on Android devices running all other API levels between 16 (Jelly Bean) and 23 (Marshmallow).

Xaml Example:

<Slider Minimum="0" Maximum="100" Value="25" xfg:SliderGloss.MinTrackTintColor="Red" /> 

C# Example:

var slider = new Slider { Minimum = 0, Maximum = 100, Value = 25 };
SliderGloss.SetMinTrackTintColor(slider, Color.Red);

Sample App Code Excerpts: Xaml, C#


OnTintColor

OnTintColor Example

Type: Xamarin.Forms Color
Added to: Switch and SwitchCell

Allows a color value to be specified as the Switch control's track color when it is in the "on" position for the Switch and SwitchCell classes. Possible values are either named colors or numeric color values.

Xaml Example:

<SwitchCell Text="Red" xfg:SwitchCellGloss.OnTintColor="Red" />

<Switch xfg:SwitchGloss.OnTintColor="Red" />

C# Example:

var cell = new SwitchCell();
cell.Text = "Red";
SwitchCellGloss.SetOnTintColor(cell, Color.Red);

var switchCtrl = new Switch();
SwitchGloss.SetOnTintColor(switchCtrl, Color.Red);

Sample App Code Excerpts: Xaml, C#


ThumbOnTintColor

ThumbOnTintColor Example

Type: Xamarin.Forms Color
Added to: Switch and SwitchCell

Allows a color value to be specified as the Switch control's thumb color when it is in the "on" position for the Switch and SwitchCell classes. Possible values are either named colors or numeric color values.

Xaml Example:

<SwitchCell Text="Red" xfg:SwitchCellGloss.ThumbOnTintColor="Red" />

<Switch xfg:SwitchGloss.ThumbOnTintColor="Red" />

C# Example:

var cell = new SwitchCell();
cell.Text = "Red";
SwitchCellGloss.SetThumbOnTintColor(cell, Color.Red);

var switchCtrl = new Switch();
SwitchGloss.SetThumbOnTintColor(switchCtrl, Color.Red);

Sample App Code Excerpts: Xaml, C#


ThumbTintColor

ThumbTintColor Example

Type: Xamarin.Forms Color
Added to: Slider, Switch and SwitchCell

Allows a color value to be specified as the Slider control's thumb color as well as the Switch control's thumb color when it is in the "off" position for the Switch and SwitchCell classes. Possible values are either named colors or numeric color values.

Xaml Example:

<SwitchCell Text="Red" xfg:SwitchCellGloss.ThumbTintColor="Red" />

<Switch xfg:SwitchGloss.ThumbTintColor="Red" />

C# Example:

var cell = new SwitchCell();
cell.Text = "Red";
SwitchCellGloss.SetThumbTintColor(cell, Color.Red);

var switchCtrl = new Switch();
SwitchGloss.SetThumbTintColor(switchCtrl, Color.Red);

Sample App Code Excerpts: Xaml, C#


TintColor

TintColor Example

Type: Xamarin.Forms Color
Added to: All cell classes' accessory types (iOS only), and the Switch and SwitchCell components (both platforms)

Allows a color value to be specified as the Switch control's track color when it is in the "off" position for the Switch and SwitchCell classes, and for the accessory view on iOS. Possible values are either named colors or numeric color values.

Xaml Example:

<TextCell Text="Red" xfg:CellGloss.TintColor="Red" xfg:CellGloss.AccessoryType="Checkmark" />

<SwitchCell Text="Red" xfg:CellGloss.TintColor="Red" />

<Switch xfg:SwitchGloss.TintColor="Red" />

C# Example:

// iOS AccessoryType
var cell = new TextCell();
cell.Text = "Red";

var gloss = new CellGloss(cell);
gloss.TintColor = Color.Red;
gloss.AccessoryType = CellGlossAccessoryType.Checkmark;

// SwitchCell
var switchCell = new SwitchCell();
switchCell.Text = "Red";

CellGloss.SetTintColor(switchCell, Color.Red);

// Switch
var switchCtrl = new Switch();
SwitchGloss.SetTintColor(switchCtrl, Color.Red);

Sample App Code Excerpts: Xaml, C#


Adding XFGloss to Your Xamarin.Forms-Based App

Integrating XFGloss into your XF-based app is easy. First, add the nuget package to your app's PCL and Android/iOS platform projects. Next, initialize XFGloss from each of the platform projects, like so:

Android MainActivity.cs:

namespace XFGlossSample.Droid
{
    [Activity(Label = "XFGlossSample.Droid", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
    
            base.OnCreate(savedInstanceState);
    
            Xamarin.Forms.Forms.Init(this, savedInstanceState);
    
            LoadApplication(new App());
            
            // IMPORTANT: Initialize XFGloss AFTER calling LoadApplication on the Android platform
            XFGloss.Droid.Library.Init(this, savedInstanceState);
        }
    }
}

iOS AppDelegate.cs:

namespace XFGlossSample.iOS
{
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Xamarin.Forms.Forms.Init();
    
            /********** ADD THIS CALL TO INITIALIZE XFGloss *********/
            XFGloss.iOS.Library.Init();
    
            LoadApplication(new App());
    
            return base.FinishedLaunching(app, options);
        }
    }
}

Next, add a namespace entry to your Xaml files, or a using statement to your C# files, and start adding the new XFGloss properties to Xamarin.Forms components as demonstrated here and in the XFGlossSample app's source code.

XML namespace declaration needed in Xaml files:

xmlns:xfg="clr-namespace:XFGloss;assembly=XFGloss"

Using statement needed in C# files:

using XFGloss;

Using XFGloss With the Android AppCompat Package

XFGloss has been tested with Android APIs 16 (Jelly Bean) through 23 (Marshmallow). The Android AppCompat library is required for Android devices running APIs prior to Marshmallow. In such cases, the XFGloss features that depend on the AppCompat library will fail gracefully if the application's main activity doesn't extend the XF FormsAppCompatActivity class.

Using the SwitchCompat Cell Renderer

XFGloss also provides a new SwitchCell renderer for the Android platform when using the AppCompat library. The new renderer utilizes the SwitchCompat component instead of the standard Android Switch control, resulting in a material design styled switch instead of the previous styling, as seen below.

TintColor Example

Default XF SwitchCell renderer running on Android Jelly Bean on the left, XFGloss SwitchCompat-based renderer on the right

This option can be disabled if the previous styling is preferred. However, the custom XFGloss tinting properties will not be applied if the standard SwitchCell renderer is used.

To disable the use of the SwitchCompat-based renderer, set the XFGloss.Droid.Library.UsingSwitchCompatCell property to false BEFORE calling the Init method, like so:

Android MainActivity.cs:

XFGloss.Droid.Library.UsingSwitchCompatCell = false;

// IMPORTANT: Initialize XFGloss AFTER calling LoadApplication on the Android platform
XFGloss.Droid.Library.Init(this, savedInstanceState);

Rendering Translucent Switch and Slider Tracks on Older Devices

XFGloss can also render Android Switch and Slider track with partially transparent colors on older pre-API 21 devices. This option is disabled by default as it can negatively impact the performance of older Android devices.

You can enable the option by setting the XFGloss.Droid.Library.UsingAppCompatAlpha property to true. A good place to do this is in your Android app's MainActivity.cs file as seen below.

Android MainActivity.cs:

XFGloss.Droid.Library.UsingAppCompatAlpha = true;

Using XFGloss with Other Custom XF Controls

XFGloss should work with existing custom XF controls provided that the following criteria is met.

1. The ExportRenderer Attribute Should Not Map to Existing XF Controls

The ExportRenderer attribute tells the XF framework what code should be executed to create and communicate with a platform-specific UI component when a given generic XF control is used. Most tutorials/examples of making custom XF components show a ExportRenderer attribute that maps a new generic XF control (the first typeof parameter in the attribute) to a new platform-specific renderer (the second typeof parameter). Your existing custom controls should work with XFGloss if that approach was used.

Existing custom controls with an ExportRenderer attribute like this should work:

[assembly: ExportRenderer(typeof(MyCustomSwitch), typeof(MyCustomSwitchRenderer))]

A custom control won't be compatible with XFGloss if the ExportRenderer attribute maps a new custom renderer directly to an existing XF control. XFGloss uses this technique to enhance the stock controls instead of creating new custom ones. XFGloss must be the only case where custom renderers are mapped to standard XF controls. If there are multiple mappings to the same XF control, the last mapping to be processed at runtime is the only renderer that will be used.

Existing custom controls with an ExportRenderer attribute that maps directly to a stock XF control (the Switch control in this example) won't work:

[assembly: ExportRenderer(typeof(Switch), typeof(MyCustomSwitchRenderer))]

2. Existing Renderers Should Inherit From XFGloss Renderers Where Applicable

To make XFGloss work with your custom component, change your custom renderers to inherit from the XFGloss renderers instead of the Xamarin.Forms renderers.

For example, change:

public class MyCustomContentPageRenderer : PageRenderer
{
...
}

To:

public class MyCustomContentPageRenderer : XFGlossContentPageRenderer
{
...
}

A complete list of the XF renderers that are customized by XFGloss is provided below. Change existing custom renderers to inherit from the XFGloss renderer if its current base class is found in this list.

XF Renderer XFG Renderer XFG Renderer on Android API < 23 w/AppCompat
EntryCellRenderer XFGlossEntryCellRenderer
ImageCellRenderer XFGlossImageCellRenderer
PageRenderer* XFGlossContentPageRenderer
SliderRenderer XFGlossSliderRenderer
SwitchRenderer XFGlossSwitchRenderer XFGlossSwitchCompatRenderer
SwitchCellRenderer XFGlossSwitchCellRenderer XFGlossSwitchCompatCellRenderer
TextCellRenderer XFGlossTextCellRenderer
ViewCellRenderer XFGlossViewCellRenderer

* PageRenderer inheritance should only be changed if the associated ExportRenderer attribute is mapping the XF ContentPage control to a custom renderer. Mapping the XF Page base class to custom renderers causes unstable behavior on the Android platform.

3. Existing Renderers Should Always Call the Base Class Versions of Overridden Methods

The XFGloss renderer classes require their overridden versions of OnElementChanged and OnElementPropertyChanged methods to be called, as well as other overridable methods and properties on a per-control basis. Verify your renderers are calling the base class implementations of any overridden methods and properties if XFGloss isn't working as expected.


Known Issues

  • The default XF EntryCell renderer on iOS doesn't take the accessory view into account when positioning/sizing the text entry field. I plan to submit a PR that corrects this issue.

  • An Android.Content.Res.Resources+NotFoundException is thrown on Android API 16 (Jelly Bean) with a message that reads "Unable to find resource ID #0x404" when you switch between tabs multiple times in any of the example pages. I believe this is an issue with either Android API 16 or Xamarin.Forms v2.3.1.114, as the exception doesn't occur on any of the other tested Android APIs (17 through 23). However, I will investigate further if other users aren't seeing the issue with other Xamarin.Forms apps running on API 16.

  • The BackgroundColor and BackgroundGradient properties do not consistently operate as expected on Android API 21 (Lollipop) when they are applied to a touch enabled element. The material design ripple effect is expected when a user touches the element on API 21 and higher. The effect occurs as expected sometime but not others. In the other cases, the pre-21 highlighting of the entire element occurs instead of the ripple effect. The behavior works as expected (ripple on API 22 and higher, element highlighting on API 20 and lower) on all the other supported Android APIs (16 - 23).

  • The MaxTrackTintColor and MinTrackTintColor properties do not operate as expected on Android API 21 (Lollipop). A new tinting technique was introduced in API 21. The initial implementation was broken, but was fixed in the next release. See the documentation for the MaxTrackTintColor and MinTrackTintColor properties for more details.


Future Enhancements

I plan to add support for other properties that aren't offered by the Xamarin.Forms components as my schedule allows. PRs, especially those that add support for other XF-supported platforms, are always welcomed!


Credits

XFGloss was inspired by "Lighting Up Native Platform Features In Xamarin Forms." Thanks goes out to the series' author, Keith Rome, for the inspiration and starting point for XFGloss.

I was encouraged to take XFGloss to the next level by episode 3 (Your First Open Source Project) of the excellent Merge Conflict podcast. Thanks to both Frank A. Krueger and James Montemagno for your timely guidance.

Finally, my skills with Xamarin were once again greatly improved this year by getting recertified as a Xamarin Certified Mobile Developer after having been originally certified in 2013. Here's a special shout out to some of my favorite Xamarin University instructors, including Glenn Stephens, Kym Phillpotts and Judy McNeil! They're all seasoned Xamarin developers and great instructors. Thank you all and the other XamU instructors for the great training!


License

The MIT License (MIT)

Copyright (c) 2016-2018 Ansuria Solutions LLC & Tommy Baggett

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


About the Author

I am a Xamarin Certified Mobile Developer focused on Android, iOS and tvOS application development using Microsoft tools and C#, and Apple tools and Swift. I have 25+ years of professional software development experience and have successfully telecommuted on a variety of projects since 2008. You can learn more about me on my website or LinkedIn page.

xfgloss's People

Contributors

kyle-seongwoo-jun avatar tbaggett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xfgloss's Issues

XFGloss Background Gradient Fails on iOS with Xamarin.Forms V16.8.0

XFGloss does not seem to be able to set the colour of the iOS navigation bar since I updated Xamarin.Forms to V16.8.0.

The following is an abbreviated way that I set a background gradient on my screens:

public abstract class ViewBase : ContentPage
{
	private XFGloss.Gradient GradientBackground = new XFGloss.Gradient()
	{
		Rotation = 0,
		Steps = new XFGloss.GradientStepCollection()
		{
			new XFGloss.GradientStep( Color.FromHex( "#888888"), 0.0 ),
			new XFGloss.GradientStep( Color.FromHex( "#777777"), 0.15),
			new XFGloss.GradientStep( Color.FromHex( "#666666"), 0.6 ),
			new XFGloss.GradientStep( Color.FromHex( "#555555"), 0.9 ),
			}
		};

	public ViewBase()
	{
		BackgroundColor = Colours.MainBackground;
		XFGloss.ContentPageGloss.SetBackgroundGradient( this, GradientBackground );
		Title = "My Content Page";
	}
}

This still compiles and runs without error but the navigation bar on iOS now remains the default white colour.

ListView ContextMenu Active ViewCell Color

This is mainly for Android, but can probably be translated to other platforms as well.

If I add xfGloss:CellGloss.BackgroundColor="White" to a ViewCell, I get the benefit of having a different color background from the parent ListView, however I lose the selected color when I long-press the view cell in order to bring up the Android ContextMenu.

Is there any way to set the background color AND have a separate color when the context menu is active?

I can see this being useful on iOS too, however it's more likely that the background will stay the same color when the view cell is swiped to reveal the context menu.

Proposed API

xfGloss:CellGloss.ContextMenuActiveBackgroundColor="#xxx"

And this color would be set for the active view cell when the Context Menu is open.

note: I'm not actually sure what the name should be, color states on Android are a pita

Grid

Hi,

Is it possible to add gradient to an entire grid?

Thanks!

How to define as global style in App.xaml

I want to each ContentPage has following element
xfg:ContentPageGloss.BackgroundGradient
<xfg:Gradient Rotation="170">
<xfg:GradientStep StepColor="#9DCC5F" StepPercentage="0" />
<xfg:GradientStep StepColor="#00B0CD" StepPercentage="1" />
</xfg:Gradient>
</xfg:ContentPageGloss.BackgroundGradient>
How can I do in App.xaml?

Gradient does not work with AppShell

A curious one. I have a new Xamarin Forms app and it starts with a welcome page that uses XFGloss for diagonal gradients. After the Welcome screen is uses the Xamarin AppShell for the main part. The Android project works fine, Welcome page with gradient then AppShell pages. With iOS however the Welcome page works but the AppShell has a black background, nothing showing. What makes it curious is that just removing the code from the Welcome page that creates the background solves the issue and I get the AppShell again. If I bypass the Welcome page and go straight to the AppShell it still fails as long as I have the gradient code included. I've included a sample which demonstrates the issue. Note that this is in the iPhoneSimulator, so it is possible that it may work on an iOS device but it makes dev work problematic.
TestAppShell.zip

Change to avoid specific XF versions

Thanks for this project, I just started looking into it!

Is it feasible to change the Nuget package to require a minimum version of XF? I know some packages are forced to require a specific version for compatibility reasons, and others can do simple minimums.

Having a Gradient on a Row of a Grid?

Similar to the request for the ability to have a Gradient over a whole grid...

We need to be able to have a Gradient over a part of the Page only - specifically we've got a header area of the page which needs a Gradient over it.

Is this possible? It seems not, as the Gradient is designed to work over the entire ContentPage or a Cell.

[Question] Possible to use a second custom renderer ontop of XFG?

I spent a while debugging why a new SwitchCellRenderer wasn't working and have discovered that it was because XFG has registered its own (I wasn't using it for the SwitchCells and wasn't aware it affected them).

Now that I'm aware that I, if anything, should be creating a subclass of XFGlossSwitchCellRenderer, how about do I go applying it to SwitchCells? Is there any way I can tell XFG to use a new subclass of XFGlossSwitchCellRenderer rather than the default XFGlossSwitchCellRenderer?

I'm just looking to tweak something subtle about SwitchCells (padding, nothing too crazy).

Thanks!

I am creating a new renderer as such:

public class PCLSwitchCellRenderer : XFGlossSwitchCellRenderer
    {
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            UITableViewCell cell = base.GetCell(item, reusableCell, tv);
            if (cell != null)
            {
                // tweak my switchcell here...
                cell.TextLabel.Text = "test test test";
            }

            return cell;
        }
    }

Android X support

Hi and thanks for a great component.

Building with the latest version of Xamarin.Forms for Android gives the following error:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2,2): Error XA2002: Can not resolve reference: Xamarin.Android.Support.v7.AppCompat, referenced by XFGloss. Please add a NuGet package or assembly reference for Xamarin.Android.Support.v7.AppCompat, or remove the reference to XFGloss. (XA2002) (MyApp.Android)

Do you think the library could be updated with proper Android X support?

Thanks!

Make BackgroundColor and BackgroundGradient props aware of cell selection state

Currently, the selection state of cells isn't taken into account when the color/gradient specified in the BackgroundColor and BackgroundGradient properties are applied. This needs to be fixed.

Fixing this may also mean new SelectedColor and SelectedGradient properties would be useful. Investigate the viability of those while fixing this issue.

XFGloss Gradient not working in Release mode for iOS with "Link SDK Assemblies only"

I have tried every manner of configuration I could think of to get this working. I'm only using a Gradient with ContentPageGloss.BackgroundGradient in XAML, but it refuses to render in Release mode with iOS "Linker Behavior" set to "Link SDK Assemblies only". I have tried all of the following, to no avail:

  1. Standard XFGloss.iOS.Library.Init() call in AppDelegate
  2. Reference Gradient and ContentPageGloss classes in preservation class (Similar to how Akavache suggests here).
  3. mtouch arguments --linkskip=XFGloss --linkskip=XFGloss.iOS

Any ideas?

Support portable-net45

The latest version removed support for portable-net45 (.NETPortable,Version=v4.5,Profile=Profile111).
I know you want to move to .netstandard, but we are currently stuck on .NET 4.5 in our portable project.

Is there any reason to not support this anymore?

Could not install package 'Ansuria.XFGloss 1.1.2.89'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Xamarin.iOS: Unable to locate assembly 'XFGloss' (culture: '')

I get this error and the app crash.

Xamarin.iOS: Unable to locate assembly 'XFGloss' (culture: '')
Why?

The xaml file:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
			 xmlns:maps="clr-namespace:Xamarin.Forms.GoogleMaps;assembly=Xamarin.Forms.GoogleMaps"
             xmlns:xfg="clr-namespace:XFGloss;assembly=XFGloss"
             x:Class="ApliPur.SeleccionarRecintePage"
             Title="Recintes">
	<StackLayout>
		<maps:Map x:Name="mapaRecintes"/>
    <ListView x:Name="llistaRecintes" ItemSelected="escollirRecinte">
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell xfg:CellGloss.BackgroundColor="{Binding color}">
            <StackLayout Margin="20,0,0,0" Orientation="Horizontal" HorizontalOptions="FillAndExpand" Style="{StaticResource TextLlista}">
                <Label Text="{Binding nomApp}" VerticalTextAlignment="Center" HorizontalOptions="StartAndExpand" Style="{StaticResource TextLlista}"/>
                <Label Text="{Binding stringDistancia}" VerticalTextAlignment="Center" HorizontalOptions="StartAndExpand" Style="{StaticResource TextLlista}"/>
                <Label Text="{Binding hectarees}" VerticalTextAlignment="Center" HorizontalOptions="StartAndExpand" Style="{StaticResource TextLlista}"/>
                <Label Text="{Binding nitrogenPerTirar}" VerticalTextAlignment="Center" HorizontalOptions="StartAndExpand" Style="{StaticResource TextLlista}"/>     
		    </StackLayout>
		  </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>

  </StackLayout>
  
</ContentPage>

Possible bug with iOS 10+

Hi Tom,

Firstly, fantastic control. I'm planning on using it, but wanted to run something by you before I commit.

While searching for a gradient XF control, I stumbled across the XFLabs Gradient control as well as XFGloss. I fired up the XFLabs version first and notice straight away that it's inferior (supports only two colors to XFGloss, but more importantly, with regards to iOS, I noticed that neither XFLabs or XFGloss work on an iPad Mini 4 running OS 10.2.1. (actual device, not simulator). The gradient does not show, only a white background.

Dug some more which turned up this stackoverflow post:
http://stackoverflow.com/questions/37170276/xamarin-forms-gradient-background-for-button-using-custom-renderer-with-ios

According to that post, it states, "If you are using iOS 10+ with newer version of Xamarin.Forms, the Control.Bounds during calls to LayoutSubViews will all be zeros. You will need to set the gradient layer Frame size during sets to the control's Frame property". Follows up with a code example...

I modified the XFLabs code to match the stackoverflow code sample and it fixes the issue. Ideally I'd rather use XFGloss cause it supports Steps.

Anyway, I thought you'd like to know and possibly give this a try with a device running iOS 10+.

thoughts?

[EDIT]
Ugh! While the XFLabs was a legitimate fix, I'm embarrassed to admit, I left out the Init() in the AppDelegate when testing out XFGLoss. Please close this issue for me.
Sorry for any confusion.

ChildStep is set more than once error?

Hello, I have installed XFGloss and when I try to add a gradient step within my xaml file, i get a XAML error telling me that: "The property 'ChildStep' is set more than once."

must likely I forgot a step or two, any help would be great.
note: It does work in the code behind.

Visual studio 2017
Xamarin Forms 3.5.0.129452

here is my XAML code:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xfg="clr-namespace:XFGloss;assembly=XFGloss"
             NavigationPage.HasNavigationBar="false"
            x:Class="amici.Logon">
    
    <xfg:ContentPageGloss.BackgroundGradient>
        <xfg:Gradient Rotation="150">
            <xfg:GradientStep StepColor="White" StepPercentage="0" />
            <xfg:GradientStep StepColor="White" StepPercentage=".5" />
            <xfg:GradientStep StepColor="#ccd9ff" StepPercentage="1" />
        </xfg:Gradient>
    </xfg:ContentPageGloss.BackgroundGradient>

Does initialize XFGloss in Android project is needed?

Hi,

Adding the following code to my Android project:
// IMPORTANT: Initialize XFGloss AFTER calling LoadApplication on the Android platform XFGloss.Droid.Library.Init(this, savedInstanceState);
results with error "The name 'savedInstanceState' does not exist in the current context".
When deleting this above code XFGloss works on Android project so I wander why the above line of code needed for Android project?

Thanks,
AG

Failed to register the needed AppCompat version of the XFGloss custom renderers

Hi! First of all you have an awesome project ongoing!

Tried to implement XFGloss in my current project with these properties:

  • Target = Android 7.1 (API level 25)
  • Xamarin.Forms = v2.3.5.239-pre3
  • XFGloss = v1.0.6.59

Called Init() after LoadAplication() like this:

public class MainActivity : FormsAppCompatActivity
{
      protected override void OnCreate(Bundle savedInstanceState)
     {
           ...
           Forms.Init(this, savedInstanceState);
           ...
           LoadAplication(new App());

           //XFGloss Call
           XFGloss.Droid.Library.Init(this, savedInstanceState);
     }
}

But I get this error:

System.InvalidOperationException:

XFGloss.Droid.Library.Init(...) failed to register the needed AppCompat version of the XFGloss custom renderers. Please report an issue at https://github.com/tbaggett/xfgloss.
at XFGloss.Droid.Library.RegisterAppCompatRenderers () [0x00081] in <954620044cfa49a0ab8663158f33db77>:0
at XFGloss.Droid.Library.Init (Android.Content.Context context, Android.OS.Bundle bundle) [0x0001f] in <954620044cfa49a0ab8663158f33db77>:0
at MyApp.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0014d] in /Users/me/Projects/MyApp/Droid/Activities/MainActivity.cs:92
at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <7e083afc7c9045f59e01d9c14931060d>:0
at at (wrapper dynamic-method) System.Object:28916aee-0aa7-4db0-90a4-e61bc00c845d (intptr,intptr,intptr)

Any resolution?

Support UWP

If you're making a library for XF, you need/should support all the platforms it supports.

UWP support

it would be great if there iss any UWP support

Object reference error on iPad Only

I'm getting this error on iOS just when I try to deploy to a real device.

For some reason on XFGlossContentPageRenderer.ViewDidLayoutSubviews the NativeView property is null.

Is anyone having this error?

Object reference not set to an instance of an object (System.NullReferenceException)
  at XFGloss.iOS.Views.XFGlossGradientLayer.GetGradientLayer (UIKit.UIView view) [0x00000] in <b880fe36f9644f1bba52b7a93270c77f>:0 
  at XFGloss.iOS.Renderers.XFGlossContentPageRenderer.ViewDidLayoutSubviews () [0x00006] in <b880fe36f9644f1bba52b7a93270c77f>:0 
  at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSend_CGRect (intptr,intptr,CoreGraphics.CGRect)
  at UIKit.UIView.set_Frame (CoreGraphics.CGRect value) [0x00010] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/build/ios/native/UIKit/UIView.g.cs:3137 
  at Xamarin.Forms.Platform.iOS.ChildViewController.ViewDidLayoutSubviews () [0x0000e] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.iOS\Renderers\TabletMasterDetailRenderer.cs:17 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
 
 at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/UIKit/UIApplication.cs:63 
  at Useall.Useall.UseApp.iOS.Application.Main (System.String[] args) [0x00001] in C:\Desenvolvimento\Useall.Useall\Useall.Useall.UseApp\Useall.Useall.UseApp\Useall.Useall.UseApp.iOS\Main.cs:12 

Low-level touch events label:enhancement

Xamarin has never had adequate touch support.
When we [MappingIndustries / LiveCaddie] switched from native (java) to Xamarin development, we developed our own common API and implemented it on iOS and Android.

Now switching from Xamarin.Android + Xamarin.iOS to Xamarin.Forms, I find that we are gradually adding classes like "TouchButton", which is Button + native renderer that maps (on Android) OnTouchEvent(Android.Views.MotionEvent e) and OnInterceptTouchEvent to methods in code behind.

Attached properties look like a great way to do this, and support a broader range of controls without the repetition that I am doing right now.

I posted some preliminary cross-platform code in a Xamarin forum a couple of years ago. Eventually would like to contribute a better solution, and this seems like a good project + technique to add to.

Realistically, I won't be able to collaborate in the next few months, but if I had experience implementing attached properties I might start to migrate the code we have into that format.

Mentioning this in case other people have interest in this topic, and to see whether you think this is a good fit with xfgloss.

Edit I just saw https://michaelridland.com/xamarin/xaml-attached-properties-tricks-in-xamarin-forms/ which shows how easy it is to attach a gesture via attached property, so that might get me started on attaching a cross-platform representation of Android OnTouchEvent.

EDIT 2 For my company, most of our advanced touch needs seem to be met by making a "TouchAwareContentView" which implements our ITouch interface [via platform Renderers], having as its child the custom control that needed advanced touch, and passing it in to custom child constructor as an ITouch. For example, to add touch to an OpenGL view. Or a Pan Gesture Behavior that knows where the original Down location was. A bit of code behind where we need it, but will get us through the next six months. So will revisit "doing it right" sometime in 2019.

-- ToolmakerSteve

BarBackgroundColor

Hi,

Is there any way to use Gradient Background on BarBackgroundColor (NavigationPage)?

Tks

Why .netstandard 2.0?

I use a main Core project that targets netstandard 1.4 as there is a UWP dependency that builds for Anniversary Update. Any chance of dropping the level down as I can't see any use for 2.0 in the code yet?

Thanks

XFGloss incompatible with default Xamarin.Forms setup in Visual Studio 2017

  1. Create a new Xamarin.Forms UWP/mobile app with all the defaults selected.
  2. Install XFGloss

XFGloss appears to install but fails to ever load, indicated by an insidious warning icon on the Nuget Package:
https://imgur.com/a/m8WSSx3

A separate bug, in Visual Studio, prevents getting any more info about what went wrong - but the discussion in this StackOverflow post about the bug implies it's something wrong with how the Nuget Package sets its paths:
https://stackoverflow.com/questions/37208853/net-2015-references-with-yellow-triangle-for-nuget-packages-on-portable-librari

Attempting to use XFGloss in this scenario results in no typeahead on its namespace and build errors if you try to invoke it manually in codebehind or xaml forms.

Type xfg:ContentPageGloss.BackgroundGradient not found

I'm following the example on the example project, but when I try to compile I get the error that xfg:ContentPageGloss.BackgroundGradient not found in xmlns car-namespace:XFGloss;assembly=XFGloss

My full xaml page is

I have XFGloss initialised in both the Android and iOS projects with the target framework set to .NET Standard 2.

I don't have a problem if I'm writing code rather than xaml

Add Gradient to Text Color?

Hi,
Can it add/change Text Color Property of Entry/Button/etc to also have gradient?
I see here only BackgroundGradient. Can you add it please?
I know it can be done on Android:
Text Color Gradient , but i'm looking for Cross Platform solution.
Thanks for your great work!

Page renderer

I have a custom renderer targeting the Page on iOS.
If I add the XFGloss renderer, my renderer stop working. Looks like it isn't fired any more.

Is it normal?
Can I use my custom renderer together with the XFGloss?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.