-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f02a0e5
commit 905e60c
Showing
3 changed files
with
47 additions
and
7 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
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,32 @@ | ||
import SwiftUI | ||
import SwiftUtil | ||
|
||
struct EnumView: View { | ||
let description: String | ||
@ObservedObject private var viewModel: OptionViewModel<String> | ||
let options: [(String, String)] | ||
|
||
init(data: [String: Any], onUpdate: @escaping (String) -> Void) { | ||
description = data["Description"] as! String | ||
let original = data["Enum"] as! [String: String] | ||
let translation = data["EnumI18n"] as? [String: String] ?? original | ||
options = original.reduce(into: [(String, String)]()) { result, pair in | ||
result.append((pair.value, translation[pair.key] ?? pair.value)) | ||
} | ||
viewModel = OptionViewModel( | ||
value: data["Value"] as! String, | ||
defaultValue: data["DefaultValue"] as! String, | ||
onUpdate: { value in | ||
onUpdate(value) | ||
} | ||
) | ||
} | ||
|
||
var body: some View { | ||
Picker(description, selection: $viewModel.value) { | ||
ForEach(options, id: \.0) { pair in | ||
Text(pair.1).tag(pair.0) | ||
} | ||
}.resettable(viewModel) | ||
} | ||
} |
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