Skip to content
This repository has been archived by the owner on Nov 12, 2020. It is now read-only.

Commit

Permalink
[CF] a generic says what?
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaseFlorell committed Apr 3, 2017
1 parent af4c8f1 commit 6fe3409
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Xfx.Controls.Droid/Renderers/XfxEntryRendererDroid.cs
Expand Up @@ -156,7 +156,7 @@ private void ControlOnFocusChange(object sender, FocusChangeEventArgs args)
100);
}

var isFocusedPropertyKey = Element.GetInternalPropertyKey("IsFocusedPropertyKey");
var isFocusedPropertyKey = Element.GetInternalField<BindablePropertyKey>("IsFocusedPropertyKey");
((IElementController) Element).SetValueFromRenderer(isFocusedPropertyKey, args.HasFocus);
}

Expand Down
6 changes: 2 additions & 4 deletions src/Xfx.Controls.iOS/Renderers/XfxEntryRendererTouch.cs
@@ -1,7 +1,6 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using CoreGraphics;
using UIKit;
using Xamarin.Forms;
Expand Down Expand Up @@ -112,16 +111,15 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE

private void OnEditingDidEnd(object sender, EventArgs eventArgs)
{
var isFocusedPropertyKey = Element.GetInternalPropertyKey("IsFocusedPropertyKey");

var isFocusedPropertyKey = Element.GetInternalField<BindablePropertyKey>("IsFocusedPropertyKey");
ElementController.SetValueFromRenderer(isFocusedPropertyKey, false);
_hasFocus = false;
Control.UnderlineColor = GetUnderlineColorForState();
}

private void OnEditingDidBegin(object sender, EventArgs eventArgs)
{
var isFocusedPropertyKey = Element.GetInternalPropertyKey("IsFocusedPropertyKey");
var isFocusedPropertyKey = Element.GetInternalField<BindablePropertyKey>("IsFocusedPropertyKey");
ElementController.SetValueFromRenderer(isFocusedPropertyKey, true);
_hasFocus = true;
Control.UnderlineColor = GetUnderlineColorForState();
Expand Down
4 changes: 2 additions & 2 deletions src/Xfx.Controls/Extensions/XamarinFormsExtensions.cs
Expand Up @@ -5,11 +5,11 @@ namespace Xfx.Extensions
{
public static class XamarinFormsExtensions
{
public static BindablePropertyKey GetInternalPropertyKey(this BindableObject element, string propertyKeyName)
public static T GetInternalField<T>(this BindableObject element, string propertyKeyName) where T:class
{
// reflection stinks, but hey, what can you do?
var pi = element.GetType().GetField(propertyKeyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
var key = pi?.GetValue(element) as BindablePropertyKey;
var key = (T) pi?.GetValue(element);

return key;
}
Expand Down

0 comments on commit 6fe3409

Please sign in to comment.