mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 16:24:11 +00:00
2d486ece33
* use observation in unit and preview tests instead of the async stream * use a parsing approach that is independent of the sourcery annotation * Fix observation deferred fulfillments not receiving the initial value Observation's observe only emits transitions, not the value present at subscription time. Drop the leading initial value from the affected transitionValues sequences and assert it directly with #expect instead. * improved docs
73 lines
2.5 KiB
Swift
73 lines
2.5 KiB
Swift
//
|
|
// Copyright 2025 Element Creations Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
import Compound
|
|
import SwiftUI
|
|
|
|
struct TemplateScreen: View {
|
|
@Bindable var context: TemplateScreenViewModel.Context
|
|
|
|
var body: some View {
|
|
Form {
|
|
Section {
|
|
ListRow(label: .plain(title: context.viewState.placeholder),
|
|
kind: .textField(text: $context.composerText))
|
|
|
|
ListRow(label: .centeredAction(title: L10n.actionDone,
|
|
icon: \.leave),
|
|
kind: .button { context.send(viewAction: .done) })
|
|
}
|
|
|
|
Section {
|
|
ListRow(label: .default(title: "Counter", icon: \.chart),
|
|
details: .counter(context.viewState.counter),
|
|
kind: .label)
|
|
ListRow(label: .default(title: "Increment", icon: \.plus),
|
|
kind: .button { context.send(viewAction: .incrementCounter) })
|
|
ListRow(label: .default(title: "Decrement", icon: \.minus),
|
|
kind: .button { context.send(viewAction: .decrementCounter) })
|
|
}
|
|
}
|
|
.compoundList()
|
|
.navigationTitle(context.viewState.title)
|
|
.onChange(of: context.composerText) {
|
|
context.send(viewAction: .textChanged)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Previews
|
|
|
|
@available(iOS 26.0, *)
|
|
struct TemplateScreen_Previews: PreviewProvider, TestablePreview {
|
|
static let viewModel = makeViewModel()
|
|
static let incrementedViewModel = makeViewModel(counterValue: 1)
|
|
|
|
static var previews: some View {
|
|
ElementNavigationStack {
|
|
TemplateScreen(context: viewModel.context)
|
|
}
|
|
.previewDisplayName("Initial")
|
|
|
|
ElementNavigationStack {
|
|
TemplateScreen(context: incrementedViewModel.context)
|
|
}
|
|
.previewDisplayName("Incremented")
|
|
.snapshotPreferences(expect: incrementedViewModel.context.observe(\.viewState.counter).map { $0 == 1 })
|
|
}
|
|
|
|
static func makeViewModel(counterValue: Int = 0) -> TemplateScreenViewModel {
|
|
let viewModel = TemplateScreenViewModel()
|
|
|
|
for _ in 0..<counterValue {
|
|
viewModel.context.send(viewAction: .incrementCounter)
|
|
}
|
|
|
|
return viewModel
|
|
}
|
|
}
|