11using System ;
22using System . Collections . Generic ;
3+ using System . Linq ;
34
45#if IOS || MACCATALYST
56using PlatformView = UIKit . UIView ;
@@ -17,6 +18,10 @@ public abstract class PropertyMapper : IPropertyMapper
1718 {
1819 protected readonly Dictionary < string , Action < IElementHandler , IElement > > _mapper = new ( StringComparer . Ordinal ) ;
1920
21+ #pragma warning disable RS0016 // Add public types and members to the declared API
22+ protected internal readonly Dictionary < string , Func < IElement , bool > > _initSkipChecks = new ( StringComparer . Ordinal ) ;
23+ #pragma warning restore RS0016 // Add public types and members to the declared API
24+
2025 IPropertyMapper [ ] ? _chained ;
2126
2227 // Keep a distinct list of the keys so we don't run any duplicate (overridden) updates more than once
@@ -32,6 +37,14 @@ public PropertyMapper(params IPropertyMapper[]? chained)
3237 Chained = chained ;
3338 }
3439
40+ #pragma warning disable RS0016 // Add public types and members to the declared API
41+ public PropertyMapper ( Dictionary < string , Func < IElement , bool > > initSkipChecks , params IPropertyMapper [ ] ? chained )
42+ {
43+ _initSkipChecks = initSkipChecks ;
44+ Chained = chained ;
45+ }
46+ #pragma warning restore RS0016 // Add public types and members to the declared API
47+
3548 protected virtual void SetPropertyCore ( string key , Action < IElementHandler , IElement > action )
3649 {
3750 _mapper [ key ] = action ;
@@ -50,14 +63,19 @@ protected virtual void UpdatePropertyCore(string key, IElementHandler viewHandle
5063 public virtual Action < IElementHandler , IElement > ? GetProperty ( string key )
5164 {
5265 if ( _mapper . TryGetValue ( key , out var action ) )
66+ {
5367 return action ;
68+ }
5469 else if ( Chained is not null )
5570 {
5671 foreach ( var ch in Chained )
5772 {
5873 var returnValue = ch . GetProperty ( key ) ;
74+
5975 if ( returnValue != null )
76+ {
6077 return returnValue ;
78+ }
6179 }
6280 }
6381
@@ -67,21 +85,35 @@ protected virtual void UpdatePropertyCore(string key, IElementHandler viewHandle
6785 public void UpdateProperty ( IElementHandler viewHandler , IElement ? virtualView , string property )
6886 {
6987 if ( virtualView == null )
88+ {
7089 return ;
90+ }
7191
7292 UpdatePropertyCore ( property , viewHandler , virtualView ) ;
7393 }
7494
75- public void UpdateProperties ( IElementHandler viewHandler , IElement ? virtualView )
95+ #pragma warning disable RS0016 // Add public types and members to the declared API
96+ public void UpdateProperties ( IElementHandler viewHandler , IElement ? virtualView , bool initial = false )
7697 {
7798 if ( virtualView == null )
99+ {
78100 return ;
101+ }
79102
80103 foreach ( var key in UpdateKeys )
81104 {
105+ if ( initial )
106+ {
107+ if ( _initSkipChecks . TryGetValue ( key , out Func < IElement , bool > ? skipCheck ) && skipCheck ( virtualView ) )
108+ {
109+ continue ;
110+ }
111+ }
112+
82113 UpdatePropertyCore ( key , viewHandler , virtualView ) ;
83114 }
84115 }
116+ #pragma warning restore RS0016 // Add public types and members to the declared API
85117
86118 public IPropertyMapper [ ] ? Chained
87119 {
@@ -130,7 +162,7 @@ public interface IPropertyMapper
130162
131163 IEnumerable < string > GetKeys ( ) ;
132164
133- void UpdateProperties ( IElementHandler elementHandler , IElement virtualView ) ;
165+ void UpdateProperties ( IElementHandler elementHandler , IElement virtualView , bool initial = false ) ;
134166
135167 void UpdateProperty ( IElementHandler elementHandler , IElement virtualView , string property ) ;
136168 }
@@ -155,6 +187,13 @@ public PropertyMapper(params IPropertyMapper[] chained)
155187 {
156188 }
157189
190+ #pragma warning disable RS0016 // Add public types and members to the declared API
191+ public PropertyMapper ( Dictionary < string , Func < IElement , bool > > initSkipChecks , params IPropertyMapper [ ] chained )
192+ : base ( initSkipChecks : initSkipChecks , chained : chained )
193+ {
194+ }
195+ #pragma warning restore RS0016 // Add public types and members to the declared API
196+
158197 public Action < TViewHandler , TVirtualView > this [ string key ]
159198 {
160199 get
@@ -169,7 +208,9 @@ public void Add(string key, Action<TViewHandler, TVirtualView> action) =>
169208 SetPropertyCore ( key , ( h , v ) =>
170209 {
171210 if ( v is TVirtualView vv )
211+ {
172212 action ? . Invoke ( ( TViewHandler ) h , vv ) ;
213+ }
173214 else if ( Chained != null )
174215 {
175216 foreach ( var chain in Chained )
0 commit comments