Skip to content

Commit

Permalink
Adjusted property mapper to work when the viewhandler doesn't subclas…
Browse files Browse the repository at this point in the history
…s the view.
  • Loading branch information
jonlipsky committed Jul 5, 2019
1 parent 33df813 commit c34ad88
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/HotUI/PropertyMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@

namespace HotUI
{
public class PropertyMapper<TVirtualView, TBaseNativeView, TNativeView> : Dictionary<string, Func<TNativeView, TVirtualView, bool>> where TVirtualView:View where TNativeView:TBaseNativeView
public class PropertyMapper<TVirtualView, TBaseNativeView, TNativeView> : Dictionary<string, Func<TNativeView, TVirtualView, bool>> where TVirtualView:View where TBaseNativeView:class
{
private readonly PropertyMapper<View, TBaseNativeView, TBaseNativeView> _chained;
private readonly Func<TNativeView, TBaseNativeView> _toBase;

public PropertyMapper()
{
}

public PropertyMapper(PropertyMapper<View, TBaseNativeView, TBaseNativeView> chained)
{
_chained = chained;
}

public PropertyMapper(PropertyMapper<View, TBaseNativeView, TBaseNativeView> chained)
public PropertyMapper(PropertyMapper<View, TBaseNativeView, TBaseNativeView> chained, Func<TNativeView, TBaseNativeView> getNative)
{
_chained = chained;
_toBase = getNative;
}

public void UpdateProperties( TNativeView nativeView, TVirtualView virtualView)
Expand All @@ -23,8 +29,11 @@ public void UpdateProperties( TNativeView nativeView, TVirtualView virtualView)
return;

if (_chained != null)
_chained.UpdateProperties(nativeView, virtualView);

{
TBaseNativeView native = _toBase?.Invoke(nativeView) ?? nativeView as TBaseNativeView;
_chained.UpdateProperties(native, virtualView);
}

foreach (var entry in this)
entry.Value.Invoke(nativeView, virtualView);
}
Expand Down

0 comments on commit c34ad88

Please sign in to comment.