mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 00:24:43 +02:00
MESSENGER-5410 add room federation setting
This commit is contained in:
@@ -18,11 +18,28 @@
|
||||
import SwiftUI
|
||||
import Foundation
|
||||
|
||||
/// model for swiftui cell
|
||||
@objcMembers class BWIToggleWithLabelAndSubLabelCellData: NSObject, ObservableObject {
|
||||
@Published var toggleValue: Bool = false
|
||||
@Published var isToggleDisabled: Bool = false
|
||||
@Published var toggleText: String
|
||||
@Published var subText: String
|
||||
let initalToggleValue: Bool
|
||||
|
||||
init(initalToggleValue: Bool, isToggleDisabled: Bool, toggleText: String, subText: String) {
|
||||
self.initalToggleValue = initalToggleValue
|
||||
self.toggleValue = initalToggleValue
|
||||
self.isToggleDisabled = isToggleDisabled
|
||||
self.toggleText = toggleText
|
||||
self.subText = subText
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper class for making our SwiftUI view available to ObjectiveC
|
||||
@objcMembers class TableViewCellWithLabelSubLabelAndSwitch: MXKTableViewCell {
|
||||
private var parentViewController: UIViewController?
|
||||
private var hostingController: UIHostingController<TableViewCellWithLabelSubLabelAndSwitchView>?
|
||||
@Published var toggleValue: Bool = false
|
||||
private var cellToggleData: BWIToggleWithLabelAndSubLabelCellData?
|
||||
private var theme: Theme!
|
||||
|
||||
public func makeViewController(parent: UIViewController, rootView: TableViewCellWithLabelSubLabelAndSwitchView) {
|
||||
@@ -30,16 +47,13 @@ import Foundation
|
||||
setupView(parent: parent)
|
||||
}
|
||||
|
||||
// support objective c vc
|
||||
func makeViewController(parent: UIViewController, toggleText: String, subText: String, initalToggleValue: Bool,onValueChanged:((_ newValue: Bool)-> Void)?) {
|
||||
self.toggleValue = initalToggleValue
|
||||
hostingController = UIHostingController(rootView: TableViewCellWithLabelSubLabelAndSwitchView(toggleValue: Binding(get: {
|
||||
return self.toggleValue
|
||||
}, set: { newValue in
|
||||
self.toggleValue = newValue
|
||||
onValueChanged?(newValue)
|
||||
}), toggleText: toggleText, subText: subText))
|
||||
setupView(parent: parent)
|
||||
// support for objective c vc
|
||||
func makeViewController(parent: UIViewController, toggleData: BWIToggleWithLabelAndSubLabelCellData, onValueChanged:((_ newValue: Bool)-> Void)?) {
|
||||
self.cellToggleData = toggleData
|
||||
if let cellToggleData = self.cellToggleData {
|
||||
hostingController = UIHostingController(rootView: TableViewCellWithLabelSubLabelAndSwitchView(toggleData: bwiToggle, onValueChanged: onValueChanged))
|
||||
setupView(parent: parent)
|
||||
}
|
||||
}
|
||||
|
||||
override init!(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
||||
@@ -88,6 +102,10 @@ import Foundation
|
||||
hostingController.view.backgroundColor = theme.headerBackgroundColor
|
||||
}
|
||||
}
|
||||
|
||||
func hasBeenInitialized() -> Bool {
|
||||
return self.hostingController != nil
|
||||
}
|
||||
|
||||
deinit {
|
||||
removeController()
|
||||
@@ -104,21 +122,24 @@ import Foundation
|
||||
}
|
||||
|
||||
struct TableViewCellWithLabelSubLabelAndSwitchView: View {
|
||||
@Binding var toggleValue: Bool
|
||||
var toggleText: String
|
||||
var subText: String
|
||||
@ObservedObject var toggleData: BWIToggleWithLabelAndSubLabelCellData
|
||||
@Environment(\.theme) private var theme
|
||||
var onValueChanged:((_ newValue: Bool)-> Void)?
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Toggle(isOn: $toggleValue) {
|
||||
Text(toggleText)
|
||||
Toggle(isOn: $toggleData.toggleValue) {
|
||||
Text(toggleData.toggleText)
|
||||
.lineLimit(nil)
|
||||
}
|
||||
.onChange(of: toggleData.toggleValue) { newValue in
|
||||
onValueChanged?(newValue)
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: Color(ThemeService.shared().theme.tintColor)))
|
||||
.disabled(toggleData.isToggleDisabled)
|
||||
}
|
||||
Text(subText)
|
||||
Text(toggleData.subText)
|
||||
.font(.system(size: 15))
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
.lineLimit(nil)
|
||||
|
||||
Reference in New Issue
Block a user