Skip to content

Commit

Permalink
Fix for SwiftLint
Browse files Browse the repository at this point in the history
  • Loading branch information
ppraveentr committed Oct 25, 2024
1 parent b292aee commit 9487ec5
Show file tree
Hide file tree
Showing 53 changed files with 524 additions and 511 deletions.
17 changes: 10 additions & 7 deletions Example/MobileCoreExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -261,7 +261,7 @@
DE9221C71EF28CDF000C8FC7 /* Resources */,
DEC55DE61EF2A16E00FAE024 /* Headers */,
DE1485561F10C09400A250A6 /* Embed Frameworks */,
D437653C230E8E5B004974CC /* swiftlint Run Script */,
D437653C230E8E5B004974CC /* Swiftlint Run Script */,
);
buildRules = (
);
Expand All @@ -284,11 +284,12 @@
DE9221C11EF28CDF000C8FC7 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
KnownAssetTags = (
Bundle,
);
LastSwiftUpdateCheck = 1030;
LastUpgradeCheck = 1220;
LastUpgradeCheck = 1610;
ORGANIZATIONNAME = "Praveen Prabhakar";
TargetAttributes = {
D44E56FD2341D3B900A0E56C = {
Expand Down Expand Up @@ -357,21 +358,21 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
D437653C230E8E5B004974CC /* swiftlint Run Script */ = {
D437653C230E8E5B004974CC /* Swiftlint Run Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
buildActionMask = 8;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "swiftlint Run Script";
name = "Swiftlint Run Script";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
runOnlyForDeploymentPostprocessing = 1;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n cd ..\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
Expand Down Expand Up @@ -525,6 +526,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
Expand Down Expand Up @@ -590,6 +592,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1610"
version = "2.1">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1610"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
27 changes: 11 additions & 16 deletions Sources/AppTheming/AppearanceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension UIView: AppearanceManagerProtocol {

@discardableResult
@objc public class func setUpAppearance(theme: ThemeModel, containerClass: [UIAppearanceContainer.Type]?) -> UIAppearance {
let appearance = (containerClass == nil) ? self.appearance() : self.appearance(whenContainedInInstancesOf: containerClass!)
let appearance = (containerClass == nil) ? self.appearance() : self.appearance(whenContainedInInstancesOf: containerClass!)
if let tintColor = theme[ThemeKey.tintColor.rawValue] {
appearance.tintColor = ThemesManager.getColor(tintColor as? String)
}
Expand All @@ -62,16 +62,16 @@ extension UIView: AppearanceManagerProtocol {
}
return appearance
}

@objc public class func setBackgroundImage(_ imageTheme: Any) {
self.setBackgroundImage(imageType: ThemeStyle.defaultStyle, imageName: imageTheme)
}

public class func setBackgroundImage(imageType: String?, imageName: Any) {
if let types = imageName as? ThemeModel {
types.forEach { setBackgroundImage(imageType: $0, imageName: $1) }
}

guard let imageType = imageType else { return }
if let image = ThemesManager.getImage(imageName as? String),
let segmentSelf = self as? UISegmentedControl.Type {
Expand All @@ -81,12 +81,7 @@ extension UIView: AppearanceManagerProtocol {
}

extension UISegmentedControl {
override public class func setUpAppearance(theme: ThemeModel, containerClass: [UIAppearanceContainer.Type]?) -> UIAppearance {
super.setUpAppearance(theme: theme, containerClass: containerClass)
// let appearance = (containerClass == nil) ? self.appearance() : self.appearance(whenContainedInInstancesOf: containerClass!)
// return appearance
}


public class func setBackgroundImage(imageType: String, image: UIImage) {
let image = image.withRenderingMode(.alwaysTemplate)
.resizableImage(withCapInsets: UIEdgeInsets(top: 3, left: 3, bottom: 3, right: 3))
Expand All @@ -104,8 +99,8 @@ extension UINavigationBar {
// swiftlint:disable cyclomatic_complexity
override public class func setUpAppearance(theme: ThemeModel, containerClass: [UIAppearanceContainer.Type]?) -> UIAppearance {
super.setUpAppearance(theme: theme, containerClass: containerClass)
let appearance = (containerClass == nil) ? self.appearance() : self.appearance(whenContainedInInstancesOf: containerClass!)
let appearance = (containerClass == nil) ? self.appearance() : self.appearance(whenContainedInInstancesOf: containerClass!)

for type in ThemeKey.allCases {
guard let value = theme[type.rawValue] else { continue }
switch type {
Expand Down Expand Up @@ -145,7 +140,7 @@ extension UINavigationBar {
}
return appearance
}

@available(iOS 13.0, *)
private class func navBarAppearance(theme: ThemeModel, tile: AttributedDictionary?, largeTitle: AttributedDictionary?) -> UINavigationBarAppearance {
let navAppe = UINavigationBarAppearance()
Expand All @@ -162,17 +157,17 @@ extension UINavigationBar {
return navAppe
}
// swiftlint:enable cyclomatic_complexity

override public class func setBackgroundImage(_ image: Any) {
// defaultImage
var defaultImage: UIImage? = ThemesManager.getImage(image)
var landScapeImage: UIImage?

if let imageTheme = image as? ThemeModel {
defaultImage = ThemesManager.getImage(imageTheme[ThemeKey.defaultValue])
landScapeImage = ThemesManager.getImage(imageTheme["landScape"])
}

if defaultImage != nil {
self.applyBackgroundImage(navigationBar: nil, defaultImage: defaultImage!, landScapeImage: landScapeImage)
}
Expand Down
15 changes: 8 additions & 7 deletions Sources/AppTheming/ThemeComponents/UIButton+Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation
import UIKit

@objc
extension UIButton: ControlThemeProtocol {
// check view state, to update style
open func subStyleName() -> String? {
Expand All @@ -21,29 +22,29 @@ extension UIButton: ControlThemeProtocol {
else if self.isHighlighted {
return ThemeStyle.highlightedStyle
}

return ThemeStyle.disabledStyle
}

// For custome key:value pairs
open func update(themeDic: ThemeModel, state: UIControl.State) {
let text = self.title(for: state) ?? ""
let range = NSRange(location: 0, length: text.count)
let attribute = NSMutableAttributedString(string: text)

if let color = ThemesManager.getColor(themeDic[ThemeKey.textcolor] as? String) {
self.setTitleColor(color, for: state)
// For attributed title
attribute.addAttribute(.foregroundColor, value: color, range: range)
}

if let text = themeDic[ThemeKey.textfont] as? String,
let font = ThemesManager.getFont(text) {
self.titleLabel?.font = font
// For attributed title
attribute.addAttribute(.font, value: font, range: range)
}

if let underline = themeDic[ThemeKey.underline] as? ThemeModel {
if let color = ThemesManager.getColor(underline[ThemesType.color] as? String) {
attribute.addAttribute(.underlineColor, value: color, range: range)
Expand All @@ -53,11 +54,11 @@ extension UIButton: ControlThemeProtocol {
attribute.addAttribute(.underlineStyle, value: style, range: range)
}
}

if let image = ThemesManager.getImage(themeDic[ThemeKey.image]) {
self.setImage(image, for: state)
}

self.setAttributedTitle(attribute, for: state)
}
}
2 changes: 1 addition & 1 deletion Sources/AppTheming/ThemeComponents/UILabel+Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension UILabel: ThemeProtocol {
public func subStyleName() -> String? {
self.isEnabled ? nil : ThemeStyle.disabledStyle
}

// Force update theme attibute
public func updateTheme(_ theme: ThemeModel) {
for (kind, value) in theme {
Expand Down
40 changes: 23 additions & 17 deletions Sources/AppTheming/ThemeComponents/UINavigationBar+Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,42 @@
// Copyright © 2017 Praveen Prabhakar. All rights reserved.
//

#if canImport(CoreUtility)
import CoreUtility
#endif
import Foundation
import UIKit

public extension UINavigationBar {

/**
* Configures the navigation bar to use an image as its background.
*/
static func applyBackgroundImage(
navigationBar: UINavigationBar?,
defaultColor: UIColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1),
landScapeColor landScape: UIColor? = nil ) {

self.applyBackgroundImage(
navigationBar: navigationBar,
defaultImage: defaultColor.generateImage(),
landScapeImage: landScape?.generateImage() ?? defaultColor.generateImage()
)
}

/**
* Configures the navigation bar to use an image as its background.
*/
static func applyBackgroundImage(
navigationBar: UINavigationBar?,
defaultImage: UIImage? = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1).generateImage(),
landScapeImage landScape: UIImage? = nil) {

// These background images contain a small pattern which is displayed
// in the lower right corner of the navigation bar.
var defaultImage = defaultImage
var landScape = landScape ?? defaultImage

// Both of the above images are smaller than the navigation bar's
// size. To enable the images to resize gracefully while keeping their
// content pinned to the bottom right corner of the bar, the images are
Expand All @@ -50,38 +53,40 @@ public extension UINavigationBar {
// are empty.
if let localImage = defaultImage {
defaultImage = localImage.resizableImage(
withCapInsets: UIEdgeInsets(top: 0, left: 0, bottom: localImage.size.height - 1, right: localImage.size.width - 1)
withCapInsets: UIEdgeInsets(
top: 0, left: 0, bottom: localImage.size.height - 1, right: localImage.size.width - 1)
)
}

if let localImage = landScape {
landScape = localImage.resizableImage(
withCapInsets: UIEdgeInsets(top: 0, left: 0, bottom: localImage.size.height - 1, right: localImage.size.width - 1)
withCapInsets: UIEdgeInsets(
top: 0, left: 0, bottom: localImage.size.height - 1, right: localImage.size.width - 1)
)
}
let navigationBar = navigationBar ??
UINavigationBar.appearance(whenContainedInInstancesOf: [UINavigationController.self])

// The bar metrics associated with a background image determine when it
// is used. The background image associated with the defaultImage bar metrics
// is used when a more suitable background image can not be found.
navigationBar.setBackgroundImage(defaultImage, for: .default)

// The background image associated with the LandscapePhone bar metrics
// is used by the shorter variant of the navigation bar that is used on
// iPhone when in landscape.
navigationBar.setBackgroundImage(landScape, for: .compact)
}

/**
* Configures the navigation bar to use a transparent background (see-through
* but without any blur).
*/
static func applyTransparentBackground(navigationBar: UINavigationBar?, _ opacity: CGFloat) {

let navigationBar = navigationBar ??
UINavigationBar.appearance(whenContainedInInstancesOf: [UINavigationController.self])

// The background of a navigation bar switches from being translucent
// to transparent when a background image is applied. The intensity of
// the background image's alpha channel is inversely related to the
Expand All @@ -90,20 +95,21 @@ public extension UINavigationBar {
//
// Below, background image is dynamically generated with the desired
// opacity.
if let transparentBackground = UIColor.white.generateImage( opacity: opacity, contentsScale: navigationBar.layer.contentsScale) {
if let transparentBackground = UIColor.white.generateImage(
opacity: opacity, contentsScale: navigationBar.layer.contentsScale) {
navigationBar.setBackgroundImage(transparentBackground, for: .default)
}
}

/**
* Configures the navigation bar to use a custom color as its background.
* The navigation bar remains translucent.
*/
static func applyTintColor(navigationBar: UINavigationBar?, _ color: UIColor) {

let navigationBar = navigationBar ??
UINavigationBar.appearance(whenContainedInInstancesOf: [UINavigationController.self])

navigationBar.barTintColor = color
}
}
Loading

0 comments on commit 9487ec5

Please sign in to comment.