Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions Example/Shared/View/StepperExample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// StepperExample.swift
// Shared

#if OPENSWIFTUI
import OpenSwiftUI
#else
import SwiftUI
#endif

struct StepperExample: View {
@State private var value: Int
@State private var isEditing = false

init(value: Int = 4) {
_value = State(initialValue: value)
}

var body: some View {
VStack(spacing: 16) {
Stepper(
"Count: \(value)",
value: $value,
in: 0...10,
step: 2,
onEditingChanged: { isEditing = $0 }
)
Text(isEditing ? "Editing" : "Ready")
.foregroundColor(isEditing ? .red : .blue)
}
.padding()
}
}

struct ActionStepperExample: View {
@State private var value = 0

var canIncrement = true
var canDecrement = true

var body: some View {
Stepper(
label: { Text("Count: \(value)") },
onIncrement: canIncrement ? { value += 1 } : nil,
onDecrement: canDecrement ? { value -= 1 } : nil
)
.padding()
}
}

struct FractionalStepperExample: View {
@State private var value = 1.25

var body: some View {
Stepper(value: $value, step: 0.25) {
Text("Value: \(value, specifier: "%.2f")")
}
.padding()
}
}

#Preview("Bounded") {
StepperExample()
}

#Preview("Custom actions") {
ActionStepperExample()
}

#Preview("Fractional steps") {
FractionalStepperExample()
}

#Preview("Hidden labels and disabled") {
VStack {
StepperExample().labelsHidden()
StepperExample().disabled(true)
}
}
70 changes: 70 additions & 0 deletions Example/Tests/OpenSwiftUIUITests/View/StepperUITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// StepperUITests.swift
// OpenSwiftUIUITests

import SnapshotTesting
import Testing
@testable import TestingHost

@MainActor
@Suite(.snapshots(record: .never, diffTool: diffTool))
struct StepperUITests {
@Test(arguments: [0, 4, 10])
func boundedValues(value: Int) {
openSwiftUIAssertSnapshot(
of: StepperExample(value: value),
size: .init(width: 320, height: 120),
named: "\(value)"
)
}

@Test(arguments: [
(true, true),
(true, false),
(false, true),
(false, false),
] as [(Bool, Bool)])
func optionalActions(canIncrement: Bool, canDecrement: Bool) {
openSwiftUIAssertSnapshot(
of: ActionStepperExample(
canIncrement: canIncrement,
canDecrement: canDecrement
),
size: .init(width: 320, height: 100),
named: "increment-\(canIncrement)-decrement-\(canDecrement)"
)
}

@Test
func fractionalSteps() {
openSwiftUIAssertSnapshot(
of: FractionalStepperExample(),
size: .init(width: 320, height: 100)
)
}

@Test
func labelsHidden() {
openSwiftUIAssertSnapshot(
of: StepperExample().labelsHidden(),
size: .init(width: 320, height: 120)
)
}

@Test
func disabled() {
openSwiftUIAssertSnapshot(
of: StepperExample().disabled(true),
size: .init(width: 320, height: 120)
)
}

@Test(arguments: [.mini, .small, .regular, .large, .extraLarge] as [ControlSize])
func controlSizes(size: ControlSize) {
openSwiftUIAssertSnapshot(
of: StepperExample().controlSize(size),
size: .init(width: 320, height: 120),
named: "\(size)"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,39 @@ struct AccessibilityLabelModifier<Content: View>: AccessibilityConfigurationModi
}
}

// TODO: AccessibilityStepperModifier
// MARK: - AccessibilityStepperModifier

struct AccessibilityStepperModifier<Content>: AccessibilityConfigurationModifier where Content: View {
var base: AccessibilityAdjustableModifier<Content, AccessibilityStepperValue>

init(_ configuration: StepperStyleConfiguration, value: AccessibilityBoundedNumber?) {
base = AccessibilityAdjustableModifier(configuration: .init(
value: value.map { AccessibilityStepperValue($0) },
continuous: false,
onIncrement: configuration.onIncrement,
onDecrement: configuration.onDecrement,
onSet: { number in
guard let value else {
return
}
let delta = number.value.doubleValue - value.value.doubleValue
let count = Int(abs((delta / (value.step?.doubleValue ?? 1)).rounded()))
for _ in 0 ..< count {
if delta > 0 {
configuration.onIncrement?()
} else {
configuration.onDecrement?()
}
}
},
onEditingChanged: configuration.onEditingChanged
))
}

func body(content: Content) -> some View {
base.body(content: content)
}
}

// MARK: - AccessibilityAdjustableModifier

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@
// Status: WIP
// ID: 302179F1EB9AE99B83C6A183C0B4143E (?)

#if os(macOS)
@_spi(ForOpenSwiftUIOnly)
import OpenSwiftUICore
public import OpenSwiftUICore

// MARK: - View + allowsWindowActivationEvents [TBA]

@available(OpenSwiftUI_v6_0, *)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
extension View {
nonisolated public func allowsWindowActivationEvents(_ value: Bool? = true) -> some View {
_openSwiftUIUnimplementedWarning()
return self
}
}

#if os(macOS)
// TODO: AllowsWindowActivationEventsResponder
class AllowsWindowActivationEventsResponder: DefaultLayoutViewResponder {
var value: Bool?
Expand Down
Loading
Loading