|
46 | 46 | helpUrl = "https://github.com/ysfchn/DynamicComponents-AI2/blob/main/README.md", |
47 | 47 | iconName = "aiwebres/icon.png", |
48 | 48 | nonVisible = true, |
49 | | - version = 7, |
50 | | - versionName = "2.2.0" |
| 49 | + version = 8, |
| 50 | + versionName = "2.2.1" |
51 | 51 | ) |
52 | 52 | @SimpleObject(external = true) |
53 | 53 | public class DynamicComponents extends AndroidNonvisibleComponent { |
@@ -84,6 +84,21 @@ public boolean exists(Component component) { |
84 | 84 | public boolean exists(String id) { |
85 | 85 | return COMPONENTS.containsKey(id); |
86 | 86 | } |
| 87 | + |
| 88 | + public String getClassName(Object componentName) { |
| 89 | + String regex = "[^.$@a-zA-Z0-9]"; |
| 90 | + String componentNameString = componentName.toString().replaceAll(regex, ""); |
| 91 | + |
| 92 | + if (componentName instanceof String && componentNameString.contains(".")) { |
| 93 | + return componentNameString; |
| 94 | + } else if (componentName instanceof String) { |
| 95 | + return BASE + componentNameString; |
| 96 | + } else if (componentName instanceof Component) { |
| 97 | + return componentName.getClass().getName().replaceAll(regex, ""); |
| 98 | + } else { |
| 99 | + throw new YailRuntimeError("Component is invalid.", "DynamicComponents"); |
| 100 | + } |
| 101 | + } |
87 | 102 |
|
88 | 103 | public Method getMethod(Method[] methods, String name, int parameterCount) { |
89 | 104 | name = name.replaceAll("[^a-zA-Z0-9]", ""); |
@@ -188,11 +203,10 @@ public void ChangeId(String id, String newId) { |
188 | 203 |
|
189 | 204 | @SimpleFunction(description = "Creates a new dynamic component.") |
190 | 205 | public void Create(final AndroidViewComponent in, Object componentName, final String id) throws Exception { |
191 | | - componentName = componentName.toString().replaceAll("[^a-zA-Z0-9]", ""); |
192 | 206 | if (!COMPONENTS.containsKey(id)) { |
193 | 207 | lastUsedId = id; |
194 | 208 |
|
195 | | - String mClassName = BASE + componentName; |
| 209 | + String mClassName = UTIL_INSTANCE.getClassName(componentName); |
196 | 210 | Class<?> mClass = Class.forName(mClassName); |
197 | 211 | final Constructor<?> mConstructor = mClass.getConstructor(ComponentContainer.class); |
198 | 212 |
|
|
0 commit comments