Skip to content

Commit

Permalink
feat: 🎸 [JIRA:HCPSDKFIORIUIKIT-2707] Resolve review comments
Browse files Browse the repository at this point in the history
✅ Closes: JIRA:HCPSDKFIORIUIKIT-2707
  • Loading branch information
janhuachu committed Sep 11, 2024
1 parent a6bc4f4 commit 5b5e5bf
Show file tree
Hide file tree
Showing 31 changed files with 1,744 additions and 337 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

73 changes: 18 additions & 55 deletions Sources/FioriSwiftUICore/DataTypes/RatingControl+DataType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ extension RatingControlConfiguration {
continue
}
let diff = averageRating - CGFloat(i)
if diff < 0.3 {
if diff < 0.25 {
items.append(RatingItem(isOn: false, isHalf: false))
} else if diff < 0.7 {
} else if diff < 0.75 {
items.append(RatingItem(isOn: false, isHalf: true))
} else {
items.append(RatingItem(isOn: true, isHalf: false))
Expand All @@ -93,9 +93,6 @@ extension RatingControlConfiguration {
}

func getOnColor() -> Color {
if let onColor {
return onColor
}
switch self.ratingControlStyle {
case .editable:
return .preferredColor(.tintColor)
Expand All @@ -109,9 +106,6 @@ extension RatingControlConfiguration {
}

func getOffColor() -> Color {
if let offColor {
return offColor
}
switch self.ratingControlStyle {
case .editable:
return .preferredColor(.tintColor)
Expand All @@ -124,55 +118,24 @@ extension RatingControlConfiguration {
}
}

func getOnImageView() -> some View {
self.getOnImage()
.resizable()
.scaledToFit()
.frame(width: self.getItemSize().width, height: self.getItemSize().height)
.font(.body)
.fontWeight(.light)
.imageScale(self.getScale())
.foregroundColor(self.getOnColor())
}

func getOffImageView() -> some View {
self.getOffImage()
.resizable()
.scaledToFit()
.frame(width: self.getItemSize().width, height: self.getItemSize().height)
.font(.body)
.fontWeight(.light)
.imageScale(self.getScale())
.foregroundColor(self.getOffColor())
}

func getHalfImageView() -> some View {
self.getHalfImage()
.resizable()
.scaledToFit()
.frame(width: self.getItemSize().width, height: self.getItemSize().height)
.font(.body)
.fontWeight(.light)
.imageScale(self.getScale())
.foregroundColor(self.getOnColor())
}

func getOnImage() -> Image {
let image: Image = (onImage ?? FioriIcon.actions.favorite)
.renderingMode(.template)
return image
}

func getOffImage() -> Image {
let image: Image = (offImage ?? FioriIcon.actions.unfavorite)
.renderingMode(.template)
return image
func getDefaultLabelFont() -> Font {
switch ratingControlStyle {
case .editable, .editableDisabled, .standardLarge, .accentedLarge:
return .fiori(forTextStyle: .body)
case .standard, .accented:
return .fiori(forTextStyle: .subheadline)
}
}

func getHalfImage() -> Image {
let image: Image = (halfImage ?? FioriIcon.actions.halfStar)
.renderingMode(.template)
return image
func getDefaultLabelColor() -> Color {
switch ratingControlStyle {
case .editable:
return .preferredColor(.primaryLabel)
case .editableDisabled:
return .preferredColor(.quaternaryLabel)
case .standard, .standardLarge, .accented, .accentedLarge:
return .preferredColor(.tertiaryLabel)
}
}

func getScale() -> Image.Scale {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,36 @@ protocol _AvatarsTitleComponent {
// sourcery: @ViewBuilder
var avatarsTitle: AttributedString? { get }
}

// sourcery: BaseComponent
protocol _ReviewCountLabelComponent {
// sourcery: @ViewBuilder
var reviewCountLabel: AttributedString? { get }
}

// sourcery: BaseComponent
// sourcery: importFrameworks = ["FioriThemeManager"]
protocol _OnStarImageComponent {
/// The image to be used for "On" rating star.
// sourcery: @ViewBuilder
// sourcery: defaultValue = "FioriIcon.actions.favorite.renderingMode(.template).resizable()"
var onStarImage: Image { get }
}

// sourcery: BaseComponent
// sourcery: importFrameworks = ["FioriThemeManager"]
protocol _OffStarImageComponent {
//// The image to be used for "Off" rating star.
// sourcery: @ViewBuilder
// sourcery: defaultValue = "FioriIcon.actions.unfavorite.renderingMode(.template).resizable()"
var offStarImage: Image { get }
}

// sourcery: BaseComponent
// sourcery: importFrameworks = ["FioriThemeManager"]
protocol _HalfStarImageComponent {
//// The image to be used for "half" rating star.
// sourcery: @ViewBuilder
// sourcery: defaultValue = "FioriIcon.actions.halfStar.renderingMode(.template).resizable()"
var halfStarImage: Image { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ protocol _BannerMessageComponent: _IconComponent, _TitleComponent, _CloseActionC
/// The default "On" image is a filled star while the default "Off" inmage
/// is an unfilled star.
// sourcery: CompositeComponent
protocol _RatingControlComponent {
// sourcery: importFrameworks = ["FioriThemeManager"]
protocol _RatingControlComponent: _ValueLabelComponent, _OnStarImageComponent, _OffStarImageComponent, _HalfStarImageComponent, _ReviewCountLabelComponent {
// sourcery: @Binding
/// The rating value.
var rating: Int { get }
Expand All @@ -308,24 +309,9 @@ protocol _RatingControlComponent {
// sourcery: defaultValue = 0...5
var ratingBounds: ClosedRange<Int> { get }

/// The custom image to be used for "On".
var onImage: Image? { get }

/// The custom image to be used for "Off".
var offImage: Image? { get }

/// The custom image to be used for half On image.
var halfImage: Image? { get }

/// The custom fixed size of each item image view.
var itemSize: CGSize? { get }

/// The custom color for the ON image.
var onColor: Color? { get }

/// The custom color for the OFF image.
var offColor: Color? { get }

/// The custom spacing between images.
var interItemSpacing: CGFloat? { get }

Expand All @@ -334,14 +320,6 @@ protocol _RatingControlComponent {
// sourcery: defaultValue = "nil"
var ratingValueFormat: String? { get }

/// The custom font for value label.
// sourcery: defaultValue = "nil"
var valueLabelFont: Font? { get }

/// The custom text color for value label.
// sourcery: defaultValue = "nil"
var valueLabelColor: Color? { get }

/// This property indicates if the value label is to be displayed or not. The default value is `false` for backward compatibility.
// sourcery: defaultValue = "false"
var showsValueLabel: Bool { get }
Expand Down Expand Up @@ -440,6 +418,7 @@ protocol _TimelineNowIndicatorComponent: _NowIndicatorNodeComponent {}

/// The form view which contains a title, rating control, and a subtitle
// sourcery: CompositeComponent
// sourcery: importFrameworks = ["FioriThemeManager"]
protocol _RatingControlFormViewComponent: _TitleComponent, _RatingControlComponent, _SubtitleComponent {
/// Indicates if the axis for displaying the title and rating control.
// sourcery: defaultValue = .horizontal
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import FioriThemeManager
import Foundation
import SwiftUI

// Base Layout style
public struct HalfStarImageBaseStyle: HalfStarImageStyle {
@ViewBuilder
public func makeBody(_ configuration: HalfStarImageConfiguration) -> some View {
// Add default layout here
configuration.halfStarImage
}
}

// Default fiori styles
public struct HalfStarImageFioriStyle: HalfStarImageStyle {
@ViewBuilder
public func makeBody(_ configuration: HalfStarImageConfiguration) -> some View {
HalfStarImage(configuration)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import FioriThemeManager
import Foundation
import SwiftUI

// Base Layout style
public struct OffStarImageBaseStyle: OffStarImageStyle {
@ViewBuilder
public func makeBody(_ configuration: OffStarImageConfiguration) -> some View {
// Add default layout here
configuration.offStarImage
}
}

// Default fiori styles
public struct OffStarImageFioriStyle: OffStarImageStyle {
@ViewBuilder
public func makeBody(_ configuration: OffStarImageConfiguration) -> some View {
OffStarImage(configuration)
}
}
20 changes: 20 additions & 0 deletions Sources/FioriSwiftUICore/_FioriStyles/OnStarImageStyle.fiori.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import FioriThemeManager
import Foundation
import SwiftUI

// Base Layout style
public struct OnStarImageBaseStyle: OnStarImageStyle {
@ViewBuilder
public func makeBody(_ configuration: OnStarImageConfiguration) -> some View {
// Add default layout here
configuration.onStarImage
}
}

// Default fiori styles
public struct OnStarImageFioriStyle: OnStarImageStyle {
@ViewBuilder
public func makeBody(_ configuration: OnStarImageConfiguration) -> some View {
OnStarImage(configuration)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,46 @@ extension RatingControlFormViewFioriStyle {
}
}

struct ValueLabelFioriStyle: ValueLabelStyle {
let ratingControlFormViewConfiguration: RatingControlFormViewConfiguration

func makeBody(_ configuration: ValueLabelConfiguration) -> some View {
ValueLabel(configuration)
}
}

struct OnStarImageFioriStyle: OnStarImageStyle {
let ratingControlFormViewConfiguration: RatingControlFormViewConfiguration

func makeBody(_ configuration: OnStarImageConfiguration) -> some View {
OnStarImage(configuration)
}
}

struct OffStarImageFioriStyle: OffStarImageStyle {
let ratingControlFormViewConfiguration: RatingControlFormViewConfiguration

func makeBody(_ configuration: OffStarImageConfiguration) -> some View {
OffStarImage(configuration)
}
}

struct HalfStarImageFioriStyle: HalfStarImageStyle {
let ratingControlFormViewConfiguration: RatingControlFormViewConfiguration

func makeBody(_ configuration: HalfStarImageConfiguration) -> some View {
HalfStarImage(configuration)
}
}

struct ReviewCountLabelFioriStyle: ReviewCountLabelStyle {
let ratingControlFormViewConfiguration: RatingControlFormViewConfiguration

func makeBody(_ configuration: ReviewCountLabelConfiguration) -> some View {
ReviewCountLabel(configuration)
}
}

struct SubtitleFioriStyle: SubtitleStyle {
let ratingControlFormViewConfiguration: RatingControlFormViewConfiguration

Expand Down
Loading

0 comments on commit 5b5e5bf

Please sign in to comment.