Skip to content

Instantly share code, notes, and snippets.

@Nimblz
Created October 31, 2019 17:52
Show Gist options
  • Save Nimblz/2e7c7f8b4755ae66be1bb85a1579fd72 to your computer and use it in GitHub Desktop.
Save Nimblz/2e7c7f8b4755ae66be1bb85a1579fd72 to your computer and use it in GitHub Desktop.
Wierd component
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local common = ReplicatedStorage:WaitForChild("common")
local util = common:WaitForChild("util")
local lib = ReplicatedStorage:WaitForChild("lib")
local component = script:FindFirstAncestor("uiComponents")
local Dictionary = require(util:WaitForChild("Dictionary"))
local Roact = require(lib:WaitForChild("Roact"))
local ScreenScaler = require(component:WaitForChild("ScreenScaler"))
local function withScale(kind)
return function(props)
local children = props[Roact.Children]
local prunedProps = Dictionary.join(props, {
[Roact.Children] = Dictionary.None,
})
local joinedChildren = Dictionary.join(children, {
["scaler"] = Roact.createElement(ScreenScaler, ScreenScaler.defaultProps)
})
return Roact.createElement(kind, prunedProps, joinedChildren)
end
end
return withScale
@Nimblz
Copy link
Author

Nimblz commented Oct 31, 2019

Intended usage:

return Roact.createComponent(withScale(SomeComponent), props, children)

this is so I dont have to do this whenever I want a component that reacts to screen size changes

local childrenWithScale = Dictionary.join(props[Roact.Children], {
    scale = Roact.createElement(ScreenScaler, ScreenScaler.defaultProps)
}
return Roact.createComponent(SomeComponent, props, childrenWithScale)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment