1111using PlatformView = System . Object ;
1212#endif
1313
14+ using System . Runtime . CompilerServices ;
1415using Microsoft . Maui . Graphics ;
1516
1617namespace Microsoft . Maui . Handlers
@@ -86,13 +87,29 @@ public static void MapBackground(IBorderHandler handler, IBorderView border)
8687 ( ( PlatformView ? ) handler . PlatformView ) ? . UpdateBackground ( border ) ;
8788 }
8889
90+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
91+ private static bool ShouldSkipStrokeMappings ( IBorderHandler handler ) {
92+ #if __IOS__ || MACCATALYST || ANDROID
93+ // During the initial connection, the `MapBackground` takes care of updating the stroke properties
94+ // so we can skip the stroke mappings to avoid repetitive and useless updates.
95+ return handler . IsConnectingHandler ( ) ;
96+ #else
97+ return false ;
98+ #endif
99+ }
100+
89101 /// <summary>
90102 /// Maps the abstract <see cref="IBorderStroke.Shape"/> property to the platform-specific implementations.
91103 /// </summary>
92104 /// <param name="handler">The associated handler.</param>
93105 /// <param name="border">The associated <see cref="IBorderView"/> instance.</param>
94106 public static void MapStrokeShape ( IBorderHandler handler , IBorderView border )
95107 {
108+ if ( ShouldSkipStrokeMappings ( handler ) )
109+ {
110+ return ;
111+ }
112+
96113 ( ( PlatformView ? ) handler . PlatformView ) ? . UpdateStrokeShape ( border ) ;
97114 MapBackground ( handler , border ) ;
98115 }
@@ -104,6 +121,11 @@ public static void MapStrokeShape(IBorderHandler handler, IBorderView border)
104121 /// <param name="border">The associated <see cref="IBorderView"/> instance.</param>
105122 public static void MapStroke ( IBorderHandler handler , IBorderView border )
106123 {
124+ if ( ShouldSkipStrokeMappings ( handler ) )
125+ {
126+ return ;
127+ }
128+
107129 ( ( PlatformView ? ) handler . PlatformView ) ? . UpdateStroke ( border ) ;
108130 MapBackground ( handler , border ) ;
109131 }
@@ -115,6 +137,11 @@ public static void MapStroke(IBorderHandler handler, IBorderView border)
115137 /// <param name="border">The associated <see cref="IBorderView"/> instance.</param>
116138 public static void MapStrokeThickness ( IBorderHandler handler , IBorderView border )
117139 {
140+ if ( ShouldSkipStrokeMappings ( handler ) )
141+ {
142+ return ;
143+ }
144+
118145 ( ( PlatformView ? ) handler . PlatformView ) ? . UpdateStrokeThickness ( border ) ;
119146 MapBackground ( handler , border ) ;
120147 }
@@ -126,6 +153,11 @@ public static void MapStrokeThickness(IBorderHandler handler, IBorderView border
126153 /// <param name="border">The associated <see cref="IBorderView"/> instance.</param>
127154 public static void MapStrokeLineCap ( IBorderHandler handler , IBorderView border )
128155 {
156+ if ( ShouldSkipStrokeMappings ( handler ) )
157+ {
158+ return ;
159+ }
160+
129161 ( ( PlatformView ? ) handler . PlatformView ) ? . UpdateStrokeLineCap ( border ) ;
130162 }
131163
@@ -136,6 +168,11 @@ public static void MapStrokeLineCap(IBorderHandler handler, IBorderView border)
136168 /// <param name="border">The associated <see cref="IBorderView"/> instance.</param>
137169 public static void MapStrokeLineJoin ( IBorderHandler handler , IBorderView border )
138170 {
171+ if ( ShouldSkipStrokeMappings ( handler ) )
172+ {
173+ return ;
174+ }
175+
139176 ( ( PlatformView ? ) handler . PlatformView ) ? . UpdateStrokeLineJoin ( border ) ;
140177 }
141178
@@ -146,6 +183,11 @@ public static void MapStrokeLineJoin(IBorderHandler handler, IBorderView border)
146183 /// <param name="border">The associated <see cref="IBorderView"/> instance.</param>
147184 public static void MapStrokeDashPattern ( IBorderHandler handler , IBorderView border )
148185 {
186+ if ( ShouldSkipStrokeMappings ( handler ) )
187+ {
188+ return ;
189+ }
190+
149191 ( ( PlatformView ? ) handler . PlatformView ) ? . UpdateStrokeDashPattern ( border ) ;
150192 }
151193
@@ -156,6 +198,11 @@ public static void MapStrokeDashPattern(IBorderHandler handler, IBorderView bord
156198 /// <param name="border">The associated <see cref="IBorderView"/> instance.</param>
157199 public static void MapStrokeDashOffset ( IBorderHandler handler , IBorderView border )
158200 {
201+ if ( ShouldSkipStrokeMappings ( handler ) )
202+ {
203+ return ;
204+ }
205+
159206 ( ( PlatformView ? ) handler . PlatformView ) ? . UpdateStrokeDashOffset ( border ) ;
160207 }
161208
@@ -166,6 +213,11 @@ public static void MapStrokeDashOffset(IBorderHandler handler, IBorderView borde
166213 /// <param name="border">The associated <see cref="IBorderView"/> instance.</param>
167214 public static void MapStrokeMiterLimit ( IBorderHandler handler , IBorderView border )
168215 {
216+ if ( ShouldSkipStrokeMappings ( handler ) )
217+ {
218+ return ;
219+ }
220+
169221 ( ( PlatformView ? ) handler . PlatformView ) ? . UpdateStrokeMiterLimit ( border ) ;
170222 }
171223
0 commit comments