Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,5 @@ dmypy.json
.pytype/

# Cython debug symbols
cython_debug/
cython_debug/
.worktrees/
54 changes: 42 additions & 12 deletions src/com/yusufcihan/DynamicComponents/DynamicComponents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Expand Down Expand Up @@ -321,11 +347,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);
}
Expand All @@ -335,24 +361,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)
Expand Down