1
- using ReactNative . UIManager . Events ;
1
+ using Newtonsoft . Json . Linq ;
2
+ using ReactNative . UIManager . Events ;
2
3
using System ;
3
4
using static System . FormattableString ;
4
5
@@ -25,16 +26,35 @@ public class ReactImageLoadEvent : Event
25
26
public const int OnLoadStart = 3 ;
26
27
27
28
private readonly int _eventType ;
29
+ private readonly string _imageUri ;
30
+ private readonly int _width ;
31
+ private readonly int _height ;
28
32
29
33
/// <summary>
30
34
/// Instantiates a <see cref="ReactImageLoadEvent"/>.
31
35
/// </summary>
32
36
/// <param name="viewId">The view identifier.</param>
33
37
/// <param name="eventType">The event identifier.</param>
34
- public ReactImageLoadEvent ( int viewId , int eventType )
38
+ public ReactImageLoadEvent ( int viewId , int eventType )
39
+ : this ( viewId , eventType , null , 0 , 0 )
40
+ {
41
+ }
42
+
43
+ /// <summary>
44
+ /// Instantiates a <see cref="ReactImageLoadEvent"/>.
45
+ /// </summary>
46
+ /// <param name="viewId">The view identifier.</param>
47
+ /// <param name="eventType">The event identifier.</param>
48
+ /// <param name="imageUri">The image URI.</param>
49
+ /// <param name="width">The image width.</param>
50
+ /// <param name="height">The image height.</param>
51
+ public ReactImageLoadEvent ( int viewId , int eventType , string imageUri , int width , int height )
35
52
: base ( viewId , TimeSpan . FromTicks ( Environment . TickCount ) )
36
53
{
37
54
_eventType = eventType ;
55
+ _imageUri = imageUri ;
56
+ _width = width ;
57
+ _height = height ;
38
58
}
39
59
40
60
/// <summary>
@@ -76,7 +96,35 @@ public override short CoalescingKey
76
96
/// <param name="eventEmitter">The event emitter.</param>
77
97
public override void Dispatch ( RCTEventEmitter eventEmitter )
78
98
{
79
- eventEmitter . receiveEvent ( ViewTag , EventName , null ) ;
99
+ var eventData = default ( JObject ) ;
100
+
101
+ if ( _imageUri != null || _eventType == OnLoad )
102
+ {
103
+ eventData = new JObject ( ) ;
104
+
105
+ if ( _imageUri != null )
106
+ {
107
+ eventData . Add ( "uri" , _imageUri ) ;
108
+ }
109
+
110
+ if ( _eventType == OnLoad )
111
+ {
112
+ var sourceData = new JObject
113
+ {
114
+ { "width" , _width } ,
115
+ { "height" , _height } ,
116
+ } ;
117
+
118
+ if ( _imageUri != null )
119
+ {
120
+ sourceData . Add ( "url" , _imageUri ) ;
121
+ }
122
+
123
+ eventData . Add ( "source" , sourceData ) ;
124
+ }
125
+ }
126
+
127
+ eventEmitter . receiveEvent ( ViewTag , EventName , eventData ) ;
80
128
}
81
129
}
82
130
}
0 commit comments