Skip to content

Commit

Permalink
chore: Elm theme improvement on Course Discussions (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedbashir authored Oct 31, 2024
1 parent 5a6ad08 commit 0d13558
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
9 changes: 6 additions & 3 deletions Core/Core/Configuration/Config/ThemeConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@

import Foundation

private enum ThemeKeys: String {
private enum ThemeKeys: String, RawStringExtractable {
case isRoundedCorners = "ROUNDED_CORNERS_STYLE"
case buttonCornersRadius = "BUTTON_CORNERS_RADIUS"
}

public final class ThemeConfig: NSObject {
public var isRoundedCorners: Bool

public var buttonCornersRadius: Double

init(dictionary: [String: AnyObject]) {
isRoundedCorners = dictionary[ThemeKeys.isRoundedCorners.rawValue] as? Bool != false
isRoundedCorners = dictionary[ThemeKeys.isRoundedCorners] as? Bool != false
buttonCornersRadius = dictionary[ThemeKeys.buttonCornersRadius] as? Double ?? 8.0
super.init()
}
}
Expand Down
10 changes: 5 additions & 5 deletions Core/Core/View/Base/AlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public struct AlertView: View {
.fill(Theme.Colors.warning)
)
.overlay(
RoundedRectangle(cornerRadius: 8)
Theme.Shapes.buttonShape
.stroke(style: .init(
lineWidth: 1,
lineCap: .round,
Expand Down Expand Up @@ -334,7 +334,7 @@ public struct AlertView: View {
.fill(Theme.Colors.accentColor)
)
.overlay(
RoundedRectangle(cornerRadius: 8)
Theme.Shapes.buttonShape
.stroke(style: .init(
lineWidth: 1,
lineCap: .round,
Expand Down Expand Up @@ -362,7 +362,7 @@ public struct AlertView: View {
.fill(Theme.Colors.background)
)
.overlay(
RoundedRectangle(cornerRadius: 8)
Theme.Shapes.buttonShape
.stroke(style: .init(
lineWidth: 1,
lineCap: .round,
Expand Down Expand Up @@ -448,7 +448,7 @@ public struct AlertView: View {
.fill(Theme.Colors.accentColor)
)
.overlay(
RoundedRectangle(cornerRadius: 8)
Theme.Shapes.buttonShape
.stroke(style: .init(
lineWidth: 1,
lineCap: .round,
Expand Down Expand Up @@ -476,7 +476,7 @@ public struct AlertView: View {
.fill(Theme.Colors.background)
)
.overlay(
RoundedRectangle(cornerRadius: 8)
Theme.Shapes.buttonShape
.stroke(style: .init(
lineWidth: 1,
lineCap: .round,
Expand Down
19 changes: 13 additions & 6 deletions Discussion/Discussion/Presentation/Comments/Base/CommentCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public struct CommentCell: View {
.resizable()
.frame(width: 32, height: 32)
.cornerRadius(16)
.overlay {
Circle()
.stroke(Theme.Colors.avatarStroke, lineWidth: 1)
}
})

VStack(alignment: .leading) {
Expand All @@ -67,16 +71,18 @@ public struct CommentCell: View {
Button(action: {
onReportTap()
}, label: {
comment.abuseFlagged
let icon = comment.abuseFlagged
? CoreAssets.reported.swiftUIImage
: CoreAssets.report.swiftUIImage
icon.renderingMode(.template)

Text(comment.abuseFlagged
? DiscussionLocalization.Comment.unreport
: DiscussionLocalization.Comment.report)
.font(Theme.Fonts.labelMedium)
}).foregroundColor(comment.abuseFlagged
? Theme.Colors.alert
: Theme.Colors.textSecondary)
? Theme.Colors.irreversibleAlert
: Theme.Colors.textSecondaryLight)
}
Text(comment.postBodyHtml.hideHtmlTagsAndUrls())
.font(Theme.Fonts.bodyMedium)
Expand Down Expand Up @@ -122,15 +128,16 @@ public struct CommentCell: View {
: CoreAssets.vote.swiftUIImage.renderingMode(.template)
Text("\(comment.votesCount)")
Text(DiscussionLocalization.votesCount(comment.votesCount))
.font(Theme.Fonts.labelLarge)
}).foregroundColor(comment.voted
? Theme.Colors.accentXColor
: Theme.Colors.textSecondary)
? Theme.Colors.accentColor
: Theme.Colors.textSecondaryLight)
.font(Theme.Fonts.labelLarge)

Spacer()
if addCommentAvailable {
HStack {
Image(systemName: "message.fill")
.renderingMode(.template)
Text("\(comment.responsesCount)")
Text(DiscussionLocalization.commentsCount(comment.responsesCount))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ public struct ParentCommentView: View {
KFImage(URL(string: comments.authorAvatar))
.onFailureImage(KFCrossPlatformImage(systemName: "person"))
.resizable()
.background(Color.gray)
.frame(width: 48, height: 48)
.cornerRadius(isThread ? 8 : 24)
.cornerRadius(24)
.overlay {
Circle()
.stroke(Theme.Colors.avatarStroke, lineWidth: 1)
}

})
VStack(alignment: .leading) {
Text(comments.authorName)
Expand All @@ -65,6 +69,7 @@ public struct ParentCommentView: View {
onFollowTap()
}, label: {
Image(systemName: comments.followed ? "star.fill" : "star")
.renderingMode(.template)
Text(comments.followed
? DiscussionLocalization.Comment.unfollow
: DiscussionLocalization.Comment.follow)
Expand Down Expand Up @@ -108,29 +113,31 @@ public struct ParentCommentView: View {
}, label: {
comments.voted
? (CoreAssets.voted.swiftUIImage.renderingMode(.template))
: (CoreAssets.vote.swiftUIImage.renderingMode(.template))
: CoreAssets.vote.swiftUIImage.renderingMode(.template)

Text("\(comments.votesCount)")
.foregroundColor(Theme.Colors.textPrimary)
Text(DiscussionLocalization.votesCount(comments.votesCount))
.font(Theme.Fonts.labelLarge)
.foregroundColor(Theme.Colors.textPrimary)

}).foregroundColor(comments.voted
? Theme.Colors.accentXColor
? Theme.Colors.accentColor
: Theme.Colors.textSecondaryLight)
Spacer()
Button(action: {
onReportTap()
}, label: {
comments.abuseFlagged
let icon = comments.abuseFlagged
? CoreAssets.reported.swiftUIImage
: CoreAssets.report.swiftUIImage
icon.renderingMode(.template)

Text(comments.abuseFlagged
? DiscussionLocalization.Comment.unreport
: DiscussionLocalization.Comment.report)
})
}
.accentColor(comments.abuseFlagged
? Theme.Colors.alert
? Theme.Colors.irreversibleAlert
: Theme.Colors.textSecondaryLight)
.font(Theme.Fonts.labelLarge)
}
Expand Down
1 change: 1 addition & 0 deletions OpenEdX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

if let config = Container.shared.resolve(ConfigProtocol.self) {
Theme.Shapes.isRoundedCorners = config.theme.isRoundedCorners
Theme.Shapes.buttonCornersRadius = config.theme.buttonCornersRadius

if config.facebook.enabled {
ApplicationDelegate.shared.application(
Expand Down
3 changes: 2 additions & 1 deletion Theme/Theme/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,15 @@ public struct Theme {

public struct Shapes {
public static var isRoundedCorners: Bool = true
public static var buttonCornersRadius: Double = 8.0
public static let screenBackgroundRadius = 24.0
public static let cardImageRadius = 10.0
public static let textInputShape = {
let radius: CGFloat = isRoundedCorners ? 8 : 0
return RoundedRectangle(cornerRadius: radius)
}()
public static let buttonShape = {
let radius: CGFloat = isRoundedCorners ? 8 : 0
let radius: CGFloat = isRoundedCorners ? buttonCornersRadius : 0
return RoundedCorners(tl: radius, tr: radius, bl: radius, br: radius)
}()
public static let unitButtonShape = RoundedCorners(tl: 21, tr: 21, bl: 21, br: 21)
Expand Down

0 comments on commit 0d13558

Please sign in to comment.