1+ package com .horcrux .svg .events ;
2+
3+ import androidx .core .util .Pools .SynchronizedPool ;
4+
5+ import com .facebook .react .bridge .Arguments ;
6+ import com .facebook .react .bridge .WritableMap ;
7+ import com .facebook .react .common .annotations .internal .LegacyArchitectureLogLevel ;
8+ import com .facebook .react .common .annotations .internal .LegacyArchitectureLogger ;
9+ import com .facebook .react .uimanager .PixelUtil ;
10+ import com .facebook .react .uimanager .events .Event ;
11+
12+ public class SvgOnLayoutEvent extends Event <SvgOnLayoutEvent > {
13+
14+ public int x = 0 ;
15+ public int y = 0 ;
16+ public int width = 0 ;
17+ public int height = 0 ;
18+
19+ private SvgOnLayoutEvent () {}
20+
21+ @ Override
22+ public void onDispose () {
23+ EVENTS_POOL .release (this );
24+ }
25+
26+ protected void init (int surfaceId , int viewTag , int x , int y , int width , int height ) {
27+ super .init (surfaceId , viewTag );
28+ this .x = x ;
29+ this .y = y ;
30+ this .width = width ;
31+ this .height = height ;
32+ }
33+
34+ @ Override
35+ public String getEventName () {
36+ return "topLayout" ;
37+ }
38+
39+ @ Override
40+ public WritableMap getEventData () {
41+ WritableMap layout = Arguments .createMap ();
42+ layout .putDouble ("x" , (double ) PixelUtil .toDIPFromPixel ((float ) x ));
43+ layout .putDouble ("y" , (double ) PixelUtil .toDIPFromPixel ((float ) y ));
44+ layout .putDouble ("width" , (double ) PixelUtil .toDIPFromPixel ((float ) width ));
45+ layout .putDouble ("height" , (double ) PixelUtil .toDIPFromPixel ((float ) height ));
46+
47+ WritableMap event = Arguments .createMap ();
48+ event .putMap ("layout" , layout );
49+ event .putInt ("target" , getViewTag ());
50+
51+ return event ;
52+ }
53+
54+ private static final SynchronizedPool <SvgOnLayoutEvent > EVENTS_POOL =
55+ new SynchronizedPool <SvgOnLayoutEvent >(20 );
56+
57+ static {
58+ LegacyArchitectureLogger .assertLegacyArchitecture ("SvgOnLayoutEvent" , LegacyArchitectureLogLevel .WARNING );
59+ }
60+
61+ /**
62+ * @deprecated Use {@link #obtain(int,int,int,int,int,int)} instead.
63+ */
64+ @ Deprecated
65+ public static SvgOnLayoutEvent obtain (int viewTag , int x , int y , int width , int height ) {
66+ return obtain (-1 , viewTag , x , y , width , height );
67+ }
68+
69+ public static SvgOnLayoutEvent obtain (int surfaceId , int viewTag , int x , int y , int width , int height ) {
70+ SvgOnLayoutEvent event = EVENTS_POOL .acquire ();
71+ if (event == null ) {
72+ event = new SvgOnLayoutEvent ();
73+ }
74+ event .init (surfaceId , viewTag , x , y , width , height );
75+ return event ;
76+ }
77+ }
0 commit comments