Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Build element from existing gui object suggestion #384

Open
BlueMond opened this issue Mar 28, 2023 · 1 comment
Open

Build element from existing gui object suggestion #384

BlueMond opened this issue Mar 28, 2023 · 1 comment

Comments

@BlueMond
Copy link

BlueMond commented Mar 28, 2023

I am new to Roact, so correct me if I have any misunderstandings of the library, but I noticed there doesn't seem to be a built in way to create an element from an existing roblox gui object, in the case where you would want to prebuild your GUIs in roblox studio and use them as a template for a Roact based gui library.

I suggest that the library is extended to include this functionality. I have not tested this code, but I am attempting to do it in my code, using a function like this:


local function createRoactElement(guiObject)
    local props = {}

    for k, v in pairs(guiObject) do
        if typeof(v) ~= "function" and k ~= "Parent" and k ~= "ClassName" then
            props[k] = v
        end
    end

    return Roact.createElement(guiObject.ClassName, props)
end
@BlueMond
Copy link
Author

I'm now realizing that you cannot access the table of an instance directly like this. It would have to use a library such as this: https://github.com/astriaInight/GetProperties

This library uses the latest API dump from roblox to obtain the properties. It is also capable of filtering out properties set to their default, ignoring any assignment of those properties, as it would be redundant.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant