From e7d8f68f28282d956a0e61f1e164e7393b4f4485 Mon Sep 17 00:00:00 2001 From: Andy Tsui Date: Mon, 1 Jun 2026 11:14:15 +0100 Subject: [PATCH 1/3] fix: resolve AndroidViewComponent cast error on sprite / Ball removal --- .../DynamicComponents/DynamicComponents.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java index d107347..73678c2 100644 --- a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java +++ b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java @@ -321,11 +321,11 @@ public void Move(AndroidViewComponent arrangement, AndroidViewComponent componen "so its ID can be reused for other components that are going to be created later." ) public void Remove(String id) { - Object component = COMPONENTS.get(id); + Component component = COMPONENTS.get(id); if (component == null) { return; } - RemoveComponent((AndroidViewComponent)component); + RemoveComponent(component); COMPONENTS.remove(id); COMPONENT_IDS.remove(component); } @@ -335,24 +335,28 @@ public void Remove(String id) { "But if the given component is dynamically created by this extension, this block will also " + "de-register its ID so its ID can be reused for other components that are going to be created later." ) - public void RemoveComponent(AndroidViewComponent component) { + public void RemoveComponent(Component component) { try { Method mMethod = Utils.getMethod(component, "getView"); if (mMethod != null) { final View mComponent = (View) mMethod.invoke(component); - final ViewGroup mParent = (ViewGroup) mComponent.getParent(); - if (postOnUiThread) { - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { + if (mComponent != null) { + final ViewGroup mParent = (ViewGroup) mComponent.getParent(); + if (mParent != null) { + if (postOnUiThread) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + mParent.removeView(mComponent); + } + }); + } else { mParent.removeView(mComponent); } - }); - } else { - mParent.removeView(mComponent); + } } } - final String[] closeMethods = new String[] { "onPause", "onDestroy" }; + final String[] closeMethods = new String[] { "onPause", "onDestroy", "onDelete" }; for (String methodName : closeMethods) { final Method invokeMethod = Utils.getMethod(component, methodName); if (invokeMethod != null) From 1cb6e2ec3aa3b8ebc017560d85e1b5d8d101bae8 Mon Sep 17 00:00:00 2001 From: Andy Tsui Date: Mon, 1 Jun 2026 11:50:24 +0100 Subject: [PATCH 2/3] feat: add CreateSync method for synchronous component creation --- .../DynamicComponents/DynamicComponents.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java index 73678c2..62fb857 100644 --- a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java +++ b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java @@ -188,6 +188,32 @@ public void run() { } } + @SimpleFunction(description = + "Creates a new dynamic component synchronously in the given container (arrangement/canvas), " + + "registers it internally, and returns the component object directly. " + + "If the ID is empty, a unique ID will be automatically generated." + ) + public Component CreateSync(final AndroidViewComponent in, Object componentName, String id) throws Exception { + String actualId = id; + if (actualId == null || actualId.trim().isEmpty()) { + actualId = GenerateID(); + } + + if (!COMPONENTS.containsKey(actualId)) { + lastUsedId = actualId; + Class mClass = Class.forName(Utils.getClassName(componentName)); + final Constructor mConstructor = mClass.getConstructor(ComponentContainer.class); + Component mComponent = Utils.createInstance(mConstructor, in); + COMPONENT_IDS.put(mComponent, actualId); + COMPONENTS.put(actualId, mComponent); + notifyListenersOfCreation(mComponent, actualId); + ComponentBuilt(mComponent, actualId, mComponent.getClass().getSimpleName()); + return mComponent; + } else { + throw new YailRuntimeError("All component IDs must be unique, the component ID '" + actualId + "' has already used before.", TAG); + } + } + @SimpleFunction(description = "Creates a new dynamic component in given container (arrangement/canvas) and return it without saving it to the " + "created components list, so it won't be attached to an ID. Note that you can't create components " + From 0c6dcee3d0742b88a150668bb4d922b388e97548 Mon Sep 17 00:00:00 2001 From: Andy Tsui Date: Mon, 1 Jun 2026 12:00:36 +0100 Subject: [PATCH 3/3] Ignore .worktrees/ directory --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ebc6e53..4a36175 100644 --- a/.gitignore +++ b/.gitignore @@ -172,4 +172,5 @@ dmypy.json .pytype/ # Cython debug symbols -cython_debug/ \ No newline at end of file +cython_debug/ +.worktrees/ \ No newline at end of file