Skip to content

Commit 351013c

Browse files
committed
Update README to fix issues in example
1 parent 7ff41bf commit 351013c

File tree

3 files changed

+77
-46
lines changed

3 files changed

+77
-46
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ Packages/
22

33
.DS_Store
44

5+
*.rbxl
6+
*.lock
7+
58
sourcemap.json
69
globalTypes.d.lua

README.md

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,44 +40,67 @@ Virtualized lists aren't appropriate for all situations. Here's some caveats:
4040
## Example
4141

4242
```lua
43-
local React = require(...)
44-
local VirtualizedList = require(...)
43+
local ReplicatedStorage = game:GetService("ReplicatedStorage")
44+
local HttpService = game:GetService("HttpService")
45+
local Players = game:GetService("Players")
46+
47+
local Packages = ReplicatedStorage.Packages
48+
49+
local React = require(Packages.React)
50+
local ReactRoblox = require(Packages.ReactRoblox)
51+
local VirtualizedList = require(Packages.VirtualizedList)
4552

4653
local View = VirtualizedList.View
47-
local FlatList = VirtualizedList.FlatView
54+
local FlatList = VirtualizedList.FlatList
4855

4956
local e = React.createElement
5057

51-
local DATA = {
52-
{
53-
id: 'bd7acbea-c1b1-46c2-aed5-3ad53abb28ba',
54-
title: 'First Item',
55-
},
56-
{
57-
id: '3ac68afc-c605-48d3-a4f8-fbd91aa97f63',
58-
title: 'Second Item',
59-
},
60-
{
61-
id: '58694a0f-3da1-471f-bd96-145571e29d72',
62-
title: 'Third Item',
63-
},
64-
}
58+
local ITEM_COUNT = 10_000
59+
local DATA = table.create(ITEM_COUNT)
60+
61+
for i = 1, ITEM_COUNT do
62+
DATA[i] = {
63+
id = HttpService:GenerateGUID(false),
64+
title = `Item {i}`,
65+
}
66+
end
6567

6668
local function Item(props)
67-
return e(View, {}, {
68-
e("TextLabel", {
69-
Size = UDim2.new(1, 0, 0, 40),
70-
Text = props.title,
71-
})
72-
})
69+
return e(View, {}, {
70+
ItemText = e("TextLabel", {
71+
Size = UDim2.new(1, 0, 0, 40),
72+
Text = props.title,
73+
}),
74+
})
7375
end
7476

7577
local function App()
76-
return e(FlatList, {
78+
return e("ScreenGui", {
79+
ResetOnSpawn = false,
80+
ZIndexBehavior = Enum.ZIndexBehavior.Sibling,
81+
}, {
82+
Background = e("Frame", {
83+
AnchorPoint = Vector2.new(0.5, 0.5),
84+
Position = UDim2.fromScale(0.5, 0.5),
85+
Size = UDim2.fromScale(0.25, 0.4),
86+
}, {
87+
List = e(FlatList, {
7788
data = DATA,
78-
renderItem = Item,
79-
})
89+
renderItem = function(entry)
90+
return e(Item, {
91+
title = entry.item.title,
92+
})
93+
end,
94+
keyExtractor = function(entry)
95+
return entry.id
96+
end,
97+
}),
98+
}),
99+
})
80100
end
101+
102+
local root = ReactRoblox.createRoot(Instance.new("Folder"))
103+
root:render(ReactRoblox.createPortal(e(App), Players.LocalPlayer.PlayerGui))
81104
```
82105

83106
## Documentation

dev.project.json

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
{
22
"name": "virtualized-list-lua",
33
"tree": {
4-
"$className": "Folder",
5-
"VirtualizedList": {
6-
"$path": "src/"
7-
},
8-
9-
"_Index": {
10-
"$path": "Packages/_Index"
11-
},
12-
"LuauPolyfill": {
13-
"$path": "Packages/LuauPolyfill.lua"
14-
},
15-
"Flipper": {
16-
"$path": "Packages/Flipper.lua"
17-
},
18-
"Promise": {
19-
"$path": "Packages/Promise.lua"
20-
},
21-
"React": {
22-
"$path": "Packages/React.lua"
4+
"$className": "DataModel",
5+
"ReplicatedStorage": {
6+
"$className": "Folder",
7+
"Packages": {
8+
"$className": "Folder",
9+
"VirtualizedList": {
10+
"$path": "src/"
11+
},
12+
"_Index": {
13+
"$path": "Packages/_Index"
14+
},
15+
"LuauPolyfill": {
16+
"$path": "Packages/LuauPolyfill.lua"
17+
},
18+
"Flipper": {
19+
"$path": "Packages/Flipper.lua"
20+
},
21+
"Promise": {
22+
"$path": "Packages/Promise.lua"
23+
},
24+
"React": {
25+
"$path": "Packages/React.lua"
26+
}
27+
}
2328
}
2429
}
25-
}
30+
}

0 commit comments

Comments
 (0)