3
3
using ReactNative . UIManager . Annotations ;
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using Windows . Foundation ;
6
7
using Windows . UI . Xaml ;
7
8
using Windows . UI . Xaml . Automation ;
8
9
using Windows . UI . Xaml . Automation . Peers ;
@@ -24,8 +25,8 @@ public abstract class BaseViewManager<TFrameworkElement, TLayoutShadowNode> :
24
25
where TFrameworkElement : FrameworkElement
25
26
where TLayoutShadowNode : LayoutShadowNode
26
27
{
27
- private readonly IDictionary < TFrameworkElement , Action < TFrameworkElement , Dimensions > > _transforms =
28
- new Dictionary < TFrameworkElement , Action < TFrameworkElement , Dimensions > > ( ) ;
28
+ private readonly IDictionary < TFrameworkElement , DimensionBoundProperties > _dimensionBoundProperties =
29
+ new Dictionary < TFrameworkElement , DimensionBoundProperties > ( ) ;
29
30
30
31
/// <summary>
31
32
/// Set's the <typeparamref name="TFrameworkElement"/> styling layout
@@ -36,14 +37,20 @@ public abstract class BaseViewManager<TFrameworkElement, TLayoutShadowNode> :
36
37
[ ReactProp ( "transform" ) ]
37
38
public void SetTransform ( TFrameworkElement view , JArray transforms )
38
39
{
39
- if ( transforms == null && _transforms . Remove ( view ) )
40
+ if ( transforms == null )
40
41
{
41
- ResetProjectionMatrix ( view ) ;
42
- ResetRenderTransform ( view ) ;
42
+ var dimensionBoundProperties = GetDimensionBoundProperties ( view ) ;
43
+ if ( dimensionBoundProperties ? . MatrixTransform != null )
44
+ {
45
+ dimensionBoundProperties . MatrixTransform = null ;
46
+ ResetProjectionMatrix ( view ) ;
47
+ ResetRenderTransform ( view ) ;
48
+ }
43
49
}
44
50
else
45
51
{
46
- _transforms [ view ] = ( v , d ) => SetProjectionMatrix ( v , d , transforms ) ;
52
+ var dimensionBoundProperties = GetOrCreateDimensionBoundProperties ( view ) ;
53
+ dimensionBoundProperties . MatrixTransform = transforms ;
47
54
var dimensions = GetDimensions ( view ) ;
48
55
SetProjectionMatrix ( view , dimensions , transforms ) ;
49
56
}
@@ -70,11 +77,19 @@ public void SetOverflow(TFrameworkElement view, string overflow)
70
77
{
71
78
if ( overflow == "hidden" )
72
79
{
73
- WinRTXamlToolkit . Controls . Extensions . FrameworkElementExtensions . SetClipToBounds ( view , true ) ;
80
+ var dimensionBoundProperties = GetOrCreateDimensionBoundProperties ( view ) ;
81
+ dimensionBoundProperties . OverflowHidden = true ;
82
+ var dimensions = GetDimensions ( view ) ;
83
+ SetOverflowHidden ( view , dimensions ) ;
74
84
}
75
85
else
76
86
{
77
- WinRTXamlToolkit . Controls . Extensions . FrameworkElementExtensions . SetClipToBounds ( view , false ) ;
87
+ var dimensionBoundProperties = GetDimensionBoundProperties ( view ) ;
88
+ if ( dimensionBoundProperties != null && dimensionBoundProperties . OverflowHidden )
89
+ {
90
+ dimensionBoundProperties . OverflowHidden = false ;
91
+ SetOverflowVisible ( view ) ;
92
+ }
78
93
}
79
94
}
80
95
@@ -147,7 +162,7 @@ public override void OnDropViewInstance(ThemedReactContext reactContext, TFramew
147
162
{
148
163
view . PointerEntered -= OnPointerEntered ;
149
164
view . PointerExited -= OnPointerExited ;
150
- _transforms . Remove ( view ) ;
165
+ _dimensionBoundProperties . Remove ( view ) ;
151
166
}
152
167
153
168
/// <summary>
@@ -157,10 +172,17 @@ public override void OnDropViewInstance(ThemedReactContext reactContext, TFramew
157
172
/// <param name="dimensions">The dimensions.</param>
158
173
public override void SetDimensions ( TFrameworkElement view , Dimensions dimensions )
159
174
{
160
- Action < TFrameworkElement , Dimensions > applyTransform ;
161
- if ( _transforms . TryGetValue ( view , out applyTransform ) )
175
+ var dimensionBoundProperties = GetDimensionBoundProperties ( view ) ;
176
+ var matrixTransform = dimensionBoundProperties ? . MatrixTransform ;
177
+ var overflowHidden = dimensionBoundProperties ? . OverflowHidden ?? false ;
178
+ if ( matrixTransform != null )
179
+ {
180
+ SetProjectionMatrix ( view , dimensions , matrixTransform ) ;
181
+ }
182
+
183
+ if ( overflowHidden )
162
184
{
163
- applyTransform ( view , dimensions ) ;
185
+ SetOverflowHidden ( view , dimensions ) ;
164
186
}
165
187
166
188
base . SetDimensions ( view , dimensions ) ;
@@ -197,6 +219,29 @@ private void OnPointerExited(object sender, PointerRoutedEventArgs e)
197
219
TouchHandler . OnPointerExited ( view , e ) ;
198
220
}
199
221
222
+ private DimensionBoundProperties GetDimensionBoundProperties ( TFrameworkElement view )
223
+ {
224
+ DimensionBoundProperties properties ;
225
+ if ( ! _dimensionBoundProperties . TryGetValue ( view , out properties ) )
226
+ {
227
+ properties = null ;
228
+ }
229
+
230
+ return properties ;
231
+ }
232
+
233
+ private DimensionBoundProperties GetOrCreateDimensionBoundProperties ( TFrameworkElement view )
234
+ {
235
+ DimensionBoundProperties properties ;
236
+ if ( ! _dimensionBoundProperties . TryGetValue ( view , out properties ) )
237
+ {
238
+ properties = new DimensionBoundProperties ( ) ;
239
+ _dimensionBoundProperties . Add ( view , properties ) ;
240
+ }
241
+
242
+ return properties ;
243
+ }
244
+
200
245
private static void SetProjectionMatrix ( TFrameworkElement view , Dimensions dimensions , JArray transforms )
201
246
{
202
247
var transformMatrix = TransformHelper . ProcessTransform ( transforms ) ;
@@ -224,12 +269,11 @@ private static void ApplyProjection(TFrameworkElement view, Matrix3D projectionM
224
269
if ( IsSimpleTranslationOnly ( projectionMatrix ) )
225
270
{
226
271
ResetProjectionMatrix ( view ) ;
227
- var transform = new MatrixTransform ( ) ;
272
+ var transform = EnsureMatrixTransform ( view ) ;
228
273
var matrix = transform . Matrix ;
229
274
matrix . OffsetX = projectionMatrix . OffsetX ;
230
275
matrix . OffsetY = projectionMatrix . OffsetY ;
231
276
transform . Matrix = matrix ;
232
- view . RenderTransform = transform ;
233
277
}
234
278
else
235
279
{
@@ -271,6 +315,24 @@ private static void ResetRenderTransform(TFrameworkElement view)
271
315
view . RenderTransform = null ;
272
316
}
273
317
318
+ private static MatrixTransform EnsureMatrixTransform ( FrameworkElement view )
319
+ {
320
+ var transform = view . RenderTransform ;
321
+ var matrixTransform = transform as MatrixTransform ;
322
+ if ( transform != null && matrixTransform == null )
323
+ {
324
+ throw new InvalidOperationException ( "Unknown transform set on framework element." ) ;
325
+ }
326
+
327
+ if ( matrixTransform == null )
328
+ {
329
+ matrixTransform = new MatrixTransform ( ) ;
330
+ view . RenderTransform = matrixTransform ;
331
+ }
332
+
333
+ return matrixTransform ;
334
+ }
335
+
274
336
private static Matrix3DProjection EnsureProjection ( FrameworkElement view )
275
337
{
276
338
var projection = view . Projection ;
@@ -288,5 +350,38 @@ private static Matrix3DProjection EnsureProjection(FrameworkElement view)
288
350
289
351
return matrixProjection ;
290
352
}
353
+
354
+ private static void SetOverflowHidden ( TFrameworkElement element , Dimensions dimensions )
355
+ {
356
+ if ( double . IsNaN ( dimensions . Width ) || double . IsNaN ( dimensions . Height ) )
357
+ {
358
+ element . Clip = null ;
359
+ }
360
+ else
361
+ {
362
+ element . Clip = new RectangleGeometry
363
+ {
364
+ Rect = new Rect
365
+ {
366
+ X = 0 ,
367
+ Y = 0 ,
368
+ Width = dimensions . Width ,
369
+ Height = dimensions . Height ,
370
+ } ,
371
+ } ;
372
+ }
373
+ }
374
+
375
+ private static void SetOverflowVisible ( TFrameworkElement element )
376
+ {
377
+ element . Clip = null ;
378
+ }
379
+
380
+ class DimensionBoundProperties
381
+ {
382
+ public bool OverflowHidden { get ; set ; }
383
+
384
+ public JArray MatrixTransform { get ; set ; }
385
+ }
291
386
}
292
387
}
0 commit comments