-
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.
Merge pull request #10 from MFB-Technologies-Inc/feature/segmented-pi…
…cker-animation Feature/segmented picker animation
- Loading branch information
Showing
10 changed files
with
390 additions
and
2 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
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,65 @@ | ||
// SegmentedUITests.swift | ||
// PickBetter | ||
// | ||
// Copyright © 2024 MFB Technologies, Inc. All rights reserved. All rights reserved. | ||
// | ||
// This source code is licensed under the MIT license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
|
||
import XCTest | ||
#if os(iOS) | ||
import Example | ||
#elseif os(macOS) | ||
import Example_macOS | ||
#endif | ||
|
||
final class SegmentedUITests: ExampleUITestCase { | ||
@MainActor | ||
override var _sectionNavItem: (@MainActor () throws -> XCUIElement)? { | ||
segmentedNavItem | ||
} | ||
|
||
@MainActor | ||
override var _picker: (@MainActor () throws -> XCUIElement)? { | ||
segmentedPicker | ||
} | ||
|
||
func testSelectSegmentedPickerItems() async throws { | ||
_ = try sectionNavItem().waitForExistence(timeout: 1) | ||
XCTAssert(try sectionNavItem().exists, "Navigation link/tab for 'Segmented' picker must exist") | ||
try sectionNavItem().trigger() | ||
|
||
_ = try picker().waitForExistence(timeout: 1) | ||
XCTAssert(try picker().exists, "Segmented picker must exist") | ||
_ = try segmentedButtonZero().waitForExistence(timeout: 1) | ||
_ = try segmentedButtonOne().waitForExistence(timeout: 1) | ||
|
||
XCTAssert(try segmentedButtonZero().exists, "Cell Zero must exist") | ||
XCTAssert(try segmentedButtonOne().exists, "Cell One must exist") | ||
XCTAssert( | ||
try segmentedButtonZero().isSelected && (!segmentedButtonOne().isSelected), | ||
"Initial state should have cell Zero selected" | ||
) | ||
|
||
try segmentedButtonOne().trigger() | ||
XCTAssert(try segmentedButtonOne().isSelected, "'1' should be selected after being tapped") | ||
XCTAssert(try !segmentedButtonZero().isSelected, "'0' should not be selected before being tapped.") | ||
|
||
try segmentedButtonTwo().trigger() | ||
XCTAssert( | ||
try segmentedButtonTwo().isSelected, | ||
"'2' should still be selected without being tapped again to deselect" | ||
) | ||
XCTAssert(try !segmentedButtonOne().isSelected, "'1' should be selected after being tapped.") | ||
|
||
try segmentedButtonOne().trigger() | ||
XCTAssert( | ||
try segmentedButtonOne().isSelected, | ||
"'1' should still be selected without being tapped again to deselect" | ||
) | ||
XCTAssert( | ||
try !segmentedButtonTwo().isSelected, | ||
"'2' should no longer be selected after being tapped again to deselect" | ||
) | ||
} | ||
} |
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,44 @@ | ||
// SegmentedPicker.swift | ||
// PickBetter | ||
// | ||
// Copyright © 2024 MFB Technologies, Inc. All rights reserved. All rights reserved. | ||
// | ||
// This source code is licensed under the MIT license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
|
||
import Foundation | ||
import PickBetter | ||
import SwiftUI | ||
|
||
public struct SegmentedPickerView: View { | ||
private let items: [Item] | ||
@State private var selection: Item.ID = 0 | ||
|
||
public init(items: [Item]) { | ||
self.items = items | ||
} | ||
|
||
// MARK: Accessibility Ids | ||
|
||
private var segmentedPickerString: String { "segmentedPicker" } | ||
|
||
public struct SegmentedItemLabel: View { | ||
private let itemId: Int | ||
|
||
public init(itemId: Int) { | ||
self.itemId = itemId | ||
} | ||
|
||
public var body: some View { | ||
Text("Segmented \(itemId)") | ||
} | ||
} | ||
|
||
public var body: some View { | ||
LazyView( | ||
BetterPicker(items, selection: $selection, content: { SegmentedItemLabel(itemId: $0.id) }) | ||
.betterPickerStyle(SegmentedBetterPickerStyle(frameWidth: 500.0)) | ||
.accessibilityIdentifier(segmentedPickerString) | ||
) | ||
} | ||
} |
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
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
Oops, something went wrong.