Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 searchable list voiceover actions failed #577

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Sources/FioriSwiftUICore/Models/ModelDefinitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public protocol KPIProgressItemModel: KpiProgressComponent, SubtitleComponent, F
// sourcery: generated_component
public protocol KeyValueItemModel: KeyComponent, ValueComponent {}

// sourcery: add_env_props = "sharedAction"
// sourcery: generated_component_not_configurable
public protocol ActionModel: ActionComponent {}

Expand Down
22 changes: 21 additions & 1 deletion Sources/FioriSwiftUICore/Views/Action+View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,31 @@ extension Fiori {
extension Action: View {
public var body: some View {
if _actionText != nil {
Button(action: self._didSelectAction ?? {}) {
Button {
self.sharedAction?()
self._didSelectAction?()
} label: {
Text(self._actionText ?? "")
}
} else {
EmptyView()
}
}
}

struct SharedActionKey: EnvironmentKey {
static let defaultValue: (() -> Void)? = nil
}

extension EnvironmentValues {
var sharedAction: (() -> Void)? {
get { self[SharedActionKey.self] }
set { self[SharedActionKey.self] = newValue }
}
}

extension View {
func setSharedAction(_ action: (() -> Void)?) -> some View {
self.environment(\.sharedAction, action)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SwiftUI

public struct Action {
@Environment(\.actionTextModifier) private var actionTextModifier
@Environment(\.sharedAction) var sharedAction

var _actionText: String? = nil
var _didSelectAction: (() -> Void)? = nil
Expand Down