diff --git a/Sources/FioriSwiftUICore/DataTypes/RatingControl+DataType.swift b/Sources/FioriSwiftUICore/DataTypes/RatingControl+DataType.swift index 5990d4a58..8fab74bab 100644 --- a/Sources/FioriSwiftUICore/DataTypes/RatingControl+DataType.swift +++ b/Sources/FioriSwiftUICore/DataTypes/RatingControl+DataType.swift @@ -51,7 +51,7 @@ public extension RatingControl { } internal static func getAccessibilityLabelString(_ rating: Int, ratingBounds: ClosedRange) -> String { - let labelFormat = NSLocalizedString("%d out of %d stars", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") + let labelFormat = NSLocalizedString("Rating Control %d of %d", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") return String(format: labelFormat, rating, ratingBounds.count - 1) } } @@ -184,4 +184,42 @@ extension RatingControlConfiguration { return self.ratingBounds.lowerBound + n } } + + func getAccessbilityLabelString() -> String { + switch ratingControlStyle { + case .editable, .editableDisabled: + let format = NSLocalizedString("Rating Control %d of %d", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") + return String(format: format, rating, ratingBounds.count - 1) + default: + // read-only + if let averageRating { + if let reviewCount { + if let reviewCountCeiling, reviewCount > reviewCountCeiling { + // review count > review count ceiling + let format = NSLocalizedString("Rating Control, average rating %.1f of %d, %d plus reviews", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") + return String(format: format, averageRating, ratingBounds.count - 1, reviewCountCeiling) + } else { + // review count < review count ceiling + let format = NSLocalizedString("Rating Control, average rating %.1f of %d, %d reviews", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") + return String(format: format, averageRating, ratingBounds.count - 1, reviewCount) + } + } else { + // no review count + let format = NSLocalizedString("Rating Control, average rating %.1f of %d", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") + return String(format: format, averageRating, ratingBounds.count - 1) + } + } else { + // no average rating + if let reviewCount { + // has review count + let format = NSLocalizedString("Rating Control, rating %d of %d, %d reviews", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") + return String(format: format, rating, ratingBounds.count - 1, reviewCount) + } else { + // no review count + let format = NSLocalizedString("Rating Control %d of %d", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") + return String(format: format, rating, ratingBounds.count - 1) + } + } + } + } } diff --git a/Sources/FioriSwiftUICore/_FioriStyles/RatingControlFormViewStyle.fiori.swift b/Sources/FioriSwiftUICore/_FioriStyles/RatingControlFormViewStyle.fiori.swift index a9a9b28a8..38943ca43 100644 --- a/Sources/FioriSwiftUICore/_FioriStyles/RatingControlFormViewStyle.fiori.swift +++ b/Sources/FioriSwiftUICore/_FioriStyles/RatingControlFormViewStyle.fiori.swift @@ -54,6 +54,7 @@ public struct RatingControlFormViewBaseStyle: RatingControlFormViewStyle { } } } + .disabled(configuration.ratingControlStyle == .editableDisabled) } func setRatingValue(_ configuration: RatingControlFormViewConfiguration, newRating: Int) { diff --git a/Sources/FioriSwiftUICore/_FioriStyles/RatingControlStyle.fiori.swift b/Sources/FioriSwiftUICore/_FioriStyles/RatingControlStyle.fiori.swift index 7bd546859..ef30964d6 100644 --- a/Sources/FioriSwiftUICore/_FioriStyles/RatingControlStyle.fiori.swift +++ b/Sources/FioriSwiftUICore/_FioriStyles/RatingControlStyle.fiori.swift @@ -22,7 +22,7 @@ public struct RatingControlBaseStyle: RatingControlStyle { } ) .accessibilityElement() - .accessibilityLabel(self.getAccessibilityLabel(configuration)) + .accessibilityLabel(configuration.getAccessbilityLabelString()) .setAccessibilityAdjustable(configuration.ratingControlStyle == .editable) { direction in if configuration.ratingControlStyle == .editable { switch direction { @@ -39,6 +39,7 @@ public struct RatingControlBaseStyle: RatingControlStyle { } } } + .disabled(configuration.ratingControlStyle == .editableDisabled) } @ViewBuilder func getMainBody(_ configuration: RatingControlConfiguration) -> some View { @@ -111,14 +112,10 @@ public struct RatingControlBaseStyle: RatingControlStyle { func setRatingValue(_ configuration: RatingControlConfiguration, newRating: Int) { if configuration.rating != newRating { configuration.rating = newRating - UIAccessibility.post(notification: .announcement, argument: self.getAccessibilityLabel(configuration)) + UIAccessibility.post(notification: .announcement, argument: RatingControl.getAccessibilityLabelString(newRating, ratingBounds: configuration.ratingBounds)) } } - func getAccessibilityLabel(_ configuration: RatingControlConfiguration) -> String { - RatingControl.getAccessibilityLabelString(configuration.rating, ratingBounds: configuration.ratingBounds) - } - func getReadOnly(_ configuration: RatingControlConfiguration) -> Bool { switch configuration.ratingControlStyle { case .editable, .editableDisabled: diff --git a/Sources/FioriSwiftUICore/_localization/en.lproj/FioriSwiftUICore.strings b/Sources/FioriSwiftUICore/_localization/en.lproj/FioriSwiftUICore.strings index 9a882ce20..5c12484b2 100644 --- a/Sources/FioriSwiftUICore/_localization/en.lproj/FioriSwiftUICore.strings +++ b/Sources/FioriSwiftUICore/_localization/en.lproj/FioriSwiftUICore.strings @@ -201,3 +201,18 @@ /* XFLD: RatingControl review count over ceiling format */ "%d+ reviews" = "%d+ reviews"; + +/* XACT: RatingControl accessibility label */ +"Rating Control %d of %d" = "Rating Control %d of %d"; + +/* XACT: read-only RatingControl accessibility label: rating with review count */ +"Rating Control, rating %d of %d, %d reviews" = "Rating Control, rating %d of %d, %d reviews"; + +/* XACT: read-only RatingControl accessibility label: average rating only */ +"Rating Control, average rating %.1f of %d" = "Rating Control, average rating %.1f of %d"; + +/* XACT: read-only RatingControl accessibility label: average rating with review count */ +"Rating Control, average rating %.1f of %d, %d reviews" = "Rating Control, average rating %.1f of %d, %d reviews"; + +/* XACT: read-only RatingControl accessibility label: average rating with review count over ceiling */ +"Rating Control, average rating %.1f of %d, %d plus reviews" = "Rating Control, average rating %.1f of %d, %d plus reviews";