Skip to content

Commit 84a8b75

Browse files
Kacper ŻółkiewskiKacper Żółkiewski
authored andcommitted
feat: replace OnLayoutEvent with SvgOnLayoutEvent
1 parent 11a1d87 commit 84a8b75

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

android/src/main/java/com/horcrux/svg/VirtualView.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
import com.facebook.react.bridge.ReadableType;
2121
import com.facebook.react.common.ReactConstants;
2222
import com.facebook.react.uimanager.DisplayMetricsHolder;
23-
import com.facebook.react.uimanager.OnLayoutEvent;
2423
import com.facebook.react.uimanager.PointerEvents;
2524
import com.facebook.react.uimanager.UIManagerHelper;
2625
import com.facebook.react.uimanager.events.EventDispatcher;
2726
import com.facebook.react.views.view.ReactViewGroup;
27+
import com.horcrux.svg.events.SvgOnLayoutEvent;
28+
2829
import java.util.ArrayList;
2930
import javax.annotation.Nullable;
3031

@@ -603,7 +604,7 @@ void setClientRect(RectF rect) {
603604
EventDispatcher eventDispatcher =
604605
UIManagerHelper.getEventDispatcherForReactTag(mContext, getId());
605606
if (eventDispatcher != null) {
606-
eventDispatcher.dispatchEvent(OnLayoutEvent.obtain(this.getId(), left, top, width, height));
607+
eventDispatcher.dispatchEvent(SvgOnLayoutEvent.obtain(this.getId(), left, top, width, height));
607608
}
608609
}
609610

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Comments
 (0)