-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Unified Customization to EntryWidget
Add Unified Customization to EntryWidget, as well as add missing UI elements to accompany the customization options MOB-3592
- Loading branch information
1 parent
996e729
commit e86aa46
Showing
15 changed files
with
537 additions
and
78 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
88 changes: 88 additions & 0 deletions
88
GliaWidgets/Sources/EntryWidget/EntryWidgetStyle.RemoteConfig.swift
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,88 @@ | ||
import UIKit | ||
|
||
extension EntryWidgetStyle { | ||
mutating func apply( | ||
configuration: RemoteConfiguration.EntryWidget?, | ||
assetsBuilder: RemoteConfiguration.AssetsBuilder | ||
) { | ||
applyBackground(configuration: configuration?.background) | ||
applyDivider(configuration: configuration?.mediaTypeItems?.dividerColor) | ||
applyErrorTitle( | ||
configuration: configuration?.errorTitle, | ||
assetsBuilder: assetsBuilder | ||
) | ||
applyErrorMessage( | ||
configuration: configuration?.errorMessage, | ||
assetsBuilder: assetsBuilder | ||
) | ||
errorButton.apply( | ||
configuration: configuration?.errorButton, | ||
assetsBuilder: assetsBuilder | ||
) | ||
mediaTypeItem.apply( | ||
configuration: configuration?.mediaTypeItems?.mediaTypeItem, | ||
assetsBuilder: assetsBuilder | ||
) | ||
} | ||
} | ||
|
||
private extension EntryWidgetStyle { | ||
mutating func applyBackground(configuration: RemoteConfiguration.Layer?) { | ||
configuration?.color.unwrap { | ||
switch $0.type { | ||
case .fill: | ||
$0.value | ||
.map { UIColor(hex: $0) } | ||
.first | ||
.unwrap { backgroundColor = .fill(color: $0) } | ||
case .gradient: | ||
let colors = $0.value.convertToCgColors() | ||
backgroundColor = .gradient(colors: colors) | ||
} | ||
} | ||
configuration?.cornerRadius.unwrap { | ||
cornerRadius = $0 | ||
} | ||
} | ||
|
||
mutating func applyErrorMessage( | ||
configuration: RemoteConfiguration.Text?, | ||
assetsBuilder: RemoteConfiguration.AssetsBuilder | ||
) { | ||
configuration.unwrap { | ||
UIFont.convertToFont( | ||
uiFont: assetsBuilder.fontBuilder($0.font), | ||
textStyle: errorMessageStyle | ||
).unwrap { errorMessageFont = $0 } | ||
|
||
$0.foreground?.value | ||
.map { UIColor(hex: $0) } | ||
.first | ||
.unwrap { errorMessageColor = $0 } | ||
} | ||
} | ||
|
||
mutating func applyErrorTitle( | ||
configuration: RemoteConfiguration.Text?, | ||
assetsBuilder: RemoteConfiguration.AssetsBuilder | ||
) { | ||
configuration.unwrap { | ||
UIFont.convertToFont( | ||
uiFont: assetsBuilder.fontBuilder($0.font), | ||
textStyle: errorTitleStyle | ||
).unwrap { errorTitleFont = $0 } | ||
|
||
$0.foreground?.value | ||
.map { UIColor(hex: $0) } | ||
.first | ||
.unwrap { errorTitleColor = $0 } | ||
} | ||
} | ||
|
||
mutating func applyDivider(configuration: RemoteConfiguration.Color?) { | ||
configuration?.value | ||
.map { UIColor(hex: $0) } | ||
.first | ||
.unwrap { dividerColor = $0 } | ||
} | ||
} |
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 |
---|---|---|
@@ -1,71 +1,80 @@ | ||
import UIKit | ||
|
||
public struct EntryWidgetStyle { | ||
/// Engagement channel style. | ||
public var channel: EntryWidgetChannelStyle | ||
/// The style of a media type item. | ||
public var mediaTypeItem: MediaTypeItemStyle | ||
|
||
/// Background color of the view. | ||
public var backgroundColor: UIColor | ||
/// The background color of the view. | ||
public var backgroundColor: ColorType | ||
|
||
/// Style of 'powered by' view. | ||
/// The corner radius of the view. | ||
public var cornerRadius: CGFloat | ||
|
||
/// The style of 'powered by' view. | ||
public var poweredBy: PoweredByStyle | ||
|
||
/// The color of the dragger | ||
public var draggerColor: UIColor | ||
/// The color of the divider. | ||
public var dividerColor: UIColor | ||
|
||
/// - Parameters: | ||
/// - channel: Engagement channel style. | ||
/// - backgroundColor: Background color of the view. | ||
/// - poweredBy: Style of 'powered by' view. | ||
/// - draggerColor: The color of the dragger | ||
/// | ||
public init( | ||
channel: EntryWidgetChannelStyle, | ||
backgroundColor: UIColor, | ||
poweredBy: PoweredByStyle, | ||
draggerColor: UIColor | ||
) { | ||
self.channel = channel | ||
self.backgroundColor = backgroundColor | ||
self.poweredBy = poweredBy | ||
self.draggerColor = draggerColor | ||
} | ||
} | ||
/// The font for the title of the error message. | ||
public var errorTitleFont: UIFont | ||
|
||
/// The text style for the title of the error message. | ||
public var errorTitleStyle: UIFont.TextStyle | ||
|
||
public struct EntryWidgetChannelStyle { | ||
/// Font of the headline text. | ||
public var headlineFont: UIFont | ||
/// The color for the title of the error message. | ||
public var errorTitleColor: UIColor | ||
|
||
/// Color of the headline text. | ||
public var headlineColor: UIColor | ||
/// The error message string. | ||
public var errorMessageFont: UIFont | ||
|
||
/// Font of the subheadline text. | ||
public var subheadlineFont: UIFont | ||
/// The text style for the error message. | ||
public var errorMessageStyle: UIFont.TextStyle | ||
|
||
/// Color of the subheadline text. | ||
public var subheadlineColor: UIColor | ||
/// The color for the error message. | ||
public var errorMessageColor: UIColor | ||
|
||
/// Color of the icon. | ||
public var iconColor: UIColor | ||
/// The style of the error button. | ||
public var errorButton: ActionButtonStyle | ||
|
||
/// - Parameters: | ||
/// - headlineFont: Font of the headline text. | ||
/// - headlineColor: Color of the headline text. | ||
/// - subheadlineFont: Font of the subheadline text. | ||
/// - subheadlineColor: Color of the subheadline text. | ||
/// - iconColor: Color of the icon. | ||
/// | ||
/// - mediaTypeItem: The style of a media type item. | ||
/// - backgroundColor: The background color of the view. | ||
/// - cornerRadius: The corner radius of the view. | ||
/// - poweredBy: The style of the 'powered by' view. | ||
/// - dividerColor: The color of the divider. | ||
/// - errorTitleFont: The font for the title of the error message. | ||
/// - errorTitleStyle: The text style for the title of the error message. | ||
/// - errorTitleColor: The color for the title of the error message. | ||
/// - errorMessage: The error message string. | ||
/// - errorMessageStyle: The text style for the error message. | ||
/// - errorMessageColor: The color for the error message. | ||
/// - errorButton: The style of the error button. | ||
public init( | ||
headlineFont: UIFont, | ||
headlineColor: UIColor, | ||
subheadlineFont: UIFont, | ||
subheadlineColor: UIColor, | ||
iconColor: UIColor | ||
mediaTypeItem: MediaTypeItemStyle, | ||
backgroundColor: ColorType, | ||
cornerRadius: CGFloat, | ||
poweredBy: PoweredByStyle, | ||
dividerColor: UIColor, | ||
errorTitleFont: UIFont, | ||
errorTitleStyle: UIFont.TextStyle, | ||
errorTitleColor: UIColor, | ||
errorMessageFont: UIFont, | ||
errorMessageStyle: UIFont.TextStyle, | ||
errorMessageColor: UIColor, | ||
errorButton: ActionButtonStyle | ||
) { | ||
self.headlineFont = headlineFont | ||
self.headlineColor = headlineColor | ||
self.subheadlineFont = subheadlineFont | ||
self.subheadlineColor = subheadlineColor | ||
self.iconColor = iconColor | ||
self.mediaTypeItem = mediaTypeItem | ||
self.backgroundColor = backgroundColor | ||
self.cornerRadius = cornerRadius | ||
self.poweredBy = poweredBy | ||
self.dividerColor = dividerColor | ||
self.errorTitleFont = errorTitleFont | ||
self.errorTitleStyle = errorTitleStyle | ||
self.errorTitleColor = errorTitleColor | ||
self.errorMessageFont = errorMessageFont | ||
self.errorMessageStyle = errorMessageStyle | ||
self.errorMessageColor = errorMessageColor | ||
self.errorButton = errorButton | ||
} | ||
} |
Oops, something went wrong.