-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add performance stress testing example for future expansion
- Loading branch information
1 parent
1eca2bd
commit b4293a5
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import GtkBackend | ||
import SwiftCrossUI | ||
|
||
class StressTestState: Observable { | ||
@Observed | ||
var tab = 0 | ||
|
||
@Observed | ||
var values: [Int: [String]] = [:] | ||
|
||
let options: [String] = [ | ||
"red", | ||
"green", | ||
"blue", | ||
"tower", | ||
"power", | ||
"flower", | ||
"one", | ||
"two", | ||
"three", | ||
"foo", | ||
"bar", | ||
"baz", | ||
] | ||
} | ||
|
||
@main | ||
struct StressTestApp: App { | ||
typealias Backend = GtkBackend | ||
|
||
let identifier = "dev.stackotter.StressTestApp" | ||
|
||
let state = StressTestState() | ||
|
||
let windowProperties = WindowProperties( | ||
title: "StressTestApp", | ||
defaultSize: WindowProperties.Size(400, 400), | ||
resizable: true | ||
) | ||
|
||
var body: some View { | ||
NavigationSplitView { | ||
VStack { | ||
Button("List 1") { state.tab = 0 } | ||
Button("List 2") { state.tab = 1 } | ||
}.padding(10) | ||
} detail: { | ||
VStack { | ||
Button("Generate") { | ||
var values: [String] = [] | ||
for _ in 0..<1000 { | ||
values.append(state.options.randomElement()!) | ||
} | ||
|
||
state.values[state.tab] = values | ||
} | ||
if let values = state.values[state.tab] { | ||
ScrollView { | ||
ForEach(values) { value in | ||
Text(value) | ||
} | ||
} | ||
} | ||
}.padding(10) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters