Dynamically Adding New Components To Screens/Containers

814 views
Skip to first unread message

Yash Patel

unread,
Mar 9, 2015, 3:43:46 PM3/9/15
to app-inventor-o...@googlegroups.com
Hey,

So I want to start working on a way to dynamically add new components to screens/containers. I've played around with this idea kind of minimally, but enough to make me think that it is possible. I wanted to know what you all thought about the concept and ideas on how to implement it. Some ideas I have right now:

1. Have a method in any Screen/Container that says "AddNewComponent" and that takes some component, duplicates it through reflection, and then calls an event "NewComponentAddedToScreen" so that the user can get the component and store it to a variable. And then if they want to use it, they could probably use the blocks under "Any Component".

2. Have a new component specifically to add new items. Then, for each type of item we would want to add to the screen, we can have a method in that component to add that new component and an event so that the user could get the component (so like AddButton and ButtonAdded).

I'm sure there are other ways to solve it and problems with these ways of solving it, and I look forward to hearing some feedback/ideas.

-Yash

Yash Patel

unread,
Mar 10, 2015, 4:37:29 PM3/10/15
to app-inventor-o...@googlegroups.com

So here are some screenshots on beginning work I have for those two ideas:

1. Have a method in any Screen/Container that says "AddNewComponent" and that takes some component, duplicates it through reflection, and then calls an event "NewComponentAddedToScreen" so that the user can get the component and store it to a variable. And then if they want to use it, they could probably use the blocks under "Any Component".

























So for this idea, anything that implements ComponentContainer, can have a method to add a component to it. The way I do it know, is by giving it some component that already exists and creating a new component of that type through reflection. Then, after the new component is added, an event will be triggered so that the developer can get the new component and if they wanted, store it to a global variable so they can interact with it later. Then, you can interact with the new component, by using the methods for the general component type. One thing I didn't have here, but would, is another field in the event saying "componentType", so they can case on the new type of component added.


2. Have a new component specifically to add new items. Then, for each type of item we would want to add to the screen, we can have a method in that component to add that new component and an event so that the user could get the component (so like AddButton and ButtonAdded).

This concept is pretty similar, except you have a new component, and you specifically have a new method/event pair for each type of component you want to add. Currently, it simply adds the new component to whatever container the "ComponentAdder" is in, because I ran into problems having an argument of type ComponentContainer.


Let me know what you think.

-Yash


Yash Patel

unread,
Mar 10, 2015, 4:44:58 PM3/10/15
to app-inventor-o...@googlegroups.com
Oh also, one problem with these ideas as they stand are that the general component methods don't include anything for events. Like you can dynamically add a button and you can use the methods available for the new component's properties/methods, but there is no currently available way to interact with events of the new component.

Toni Schuh

unread,
Mar 10, 2015, 5:27:34 PM3/10/15
to app-inventor-o...@googlegroups.com
I am no programmer, so i cannot give you advices on what you do.
But i am an user and as that i like to say: adding stuff dynamicly is something i realy miss here. So i am very thankfull for the job you do!
For your concern about using the events: i would be very happy if adding lables dynamicly would work - even if i cannot interact with them like buttons.
I hope you will finish your project and make it available for everyone :-)

Abraham Getzler

unread,
Mar 10, 2015, 7:24:03 PM3/10/15
to app-inventor-o...@googlegroups.com
If there were an Any Button Clicked event, with a local value for the choice of button clicked, for example, that would be  place to pick up events for new button components.  Buttons with explicit event blocks for them could be serviced by their explicit event blocks.
ABG


On Tue, Mar 10, 2015 at 4:44 PM, Yash Patel <ycpa...@gmail.com> wrote:
Oh also, one problem with these ideas as they stand are that the general component methods don't include anything for events. Like you can dynamically add a button and you can use the methods available for the new component's properties/methods, but there is no currently available way to interact with events of the new component.

--
You received this message because you are subscribed to the Google Groups "App Inventor Open Source Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to app-inventor-open-so...@googlegroups.com.
To post to this group, send email to app-inventor-o...@googlegroups.com.
Visit this group at http://groups.google.com/group/app-inventor-open-source-dev.
For more options, visit https://groups.google.com/d/optout.

Gareth Haylings

unread,
Mar 11, 2015, 7:06:50 PM3/11/15
to app-inventor-o...@googlegroups.com
Hi Yash

I've want to add something like dynamic components myself for age but have got round to looking at it yet.

For the events and methods adding these to the Any Blocks is the way I would do it as Abraham said.

When you add a dynamic component is the new component name allocated automatically?
What you could do is add a property to the function Screen1.addComponentToScreen(component, componentName) you might also what to add another function Screen1.removeComponentFromScreen(componentName) to delete a dynamically created component.



On Tuesday, 10 March 2015 23:24:03 UTC, Abraham Getzler wrote:
If there were an Any Button Clicked event, with a local value for the choice of button clicked, for example, that would be  place to pick up events for new button components.  Buttons with explicit event blocks for them could be serviced by their explicit event blocks.
ABG

On Tue, Mar 10, 2015 at 4:44 PM, Yash Patel <ycpa...@gmail.com> wrote:
Oh also, one problem with these ideas as they stand are that the general component methods don't include anything for events. Like you can dynamically add a button and you can use the methods available for the new component's properties/methods, but there is no currently available way to interact with events of the new component.

--
You received this message because you are subscribed to the Google Groups "App Inventor Open Source Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to app-inventor-open-source-dev+unsub...@googlegroups.com.

Yash Patel

unread,
Mar 13, 2015, 8:47:44 PM3/13/15
to app-inventor-o...@googlegroups.com
Hey,

Thanks for ideas. I just created a pull request for generic event handlers and I am still working on the adding components part. The removing components concept is also a good idea, thanks for that.

-Yash

Alok Kuchlous

unread,
Mar 13, 2015, 9:48:00 PM3/13/15
to app-inventor-o...@googlegroups.com
Hi Yash,

Why wouldn't you have the AddComponentToScreen itself return a value that the user could store in a var? Is this method expected to take time in certain
cases?

- Alok

Yash Patel

unread,
Mar 13, 2015, 10:08:06 PM3/13/15
to app-inventor-o...@googlegroups.com
There is no reason, I just had some misconception in my head when I was originally thinking about this. That is the way that it should/will be I implement it. Thanks for that note.

-Yash
Reply all
Reply to author
Forward
0 new messages