Skip to content

Commit b484286

Browse files
committed
Git Init
Restart.
0 parents  commit b484286

File tree

10 files changed

+301
-0
lines changed

10 files changed

+301
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/config/registries.json
8+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
9+
.netrc

LICENSE

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2022, Nordic Semiconductor Playground
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Package.swift

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// swift-tools-version: 5.6
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "iOS-Common-Libraries",
8+
platforms: [.iOS(.v15), .macOS(.v12)],
9+
products: [
10+
.library(
11+
name: "iOS-Common-Libraries",
12+
targets: ["iOS-Common-Libraries"]),
13+
],
14+
dependencies: [
15+
// Dependencies declare other packages that this package depends on.
16+
// .package(url: /* package url */, from: "1.0.0"),
17+
],
18+
targets: [
19+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
20+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
21+
.target(
22+
name: "iOS-Common-Libraries",
23+
dependencies: []),
24+
.testTarget(
25+
name: "iOS-Common-LibrariesTests",
26+
dependencies: ["iOS-Common-Libraries"]),
27+
]
28+
)

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# iOS-Common-Libraries
2+
3+
A description of this package.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//
2+
// View.swift
3+
// iOS-Common-Libraries
4+
//
5+
// Created by Dinesh Harjani on 9/8/22.
6+
//
7+
8+
import SwiftUI
9+
10+
// MARK: - FormIniOSListInMacOS
11+
12+
#if os(iOS)
13+
typealias FormIniOSListInMacOS = Form
14+
#elseif os(macOS)
15+
typealias FormIniOSListInMacOS = List
16+
#endif
17+
18+
// MARK: - View
19+
20+
extension View {
21+
22+
@inlinable public func frame(size: CGSize, alignment: Alignment = .center) -> some View {
23+
return frame(width: size.width, height: size.height, alignment: alignment)
24+
}
25+
26+
@inlinable public func centerTextInsideForm() -> some View {
27+
// Hack.
28+
return frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
29+
}
30+
31+
@inlinable public func withoutListRowInsets() -> some View {
32+
return listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
33+
}
34+
35+
// MARK: - NavBar
36+
37+
func setTitle(_ title: String) -> some View {
38+
#if os(iOS)
39+
return navigationBarTitle(title, displayMode: .inline)
40+
#else
41+
return navigationTitle(title)
42+
#endif
43+
}
44+
45+
// MARK: - NavigationView
46+
47+
@ViewBuilder
48+
func wrapInNavigationViewForiOS() -> some View {
49+
#if os(iOS)
50+
NavigationView {
51+
self
52+
}
53+
.setupNavBarBackground()
54+
.setSingleColumnNavigationViewStyle()
55+
.accentColor(.white)
56+
#else
57+
self
58+
#endif
59+
}
60+
61+
// MARK: - UITextField
62+
63+
func disableAllAutocorrections() -> some View {
64+
disableAutocorrection(true)
65+
#if os(iOS)
66+
.autocapitalization(.none)
67+
#endif
68+
}
69+
}
70+
71+
// MARK: - Picker
72+
73+
extension Picker {
74+
75+
@ViewBuilder
76+
func setAsComboBoxStyle() -> some View {
77+
self
78+
#if os(iOS)
79+
.pickerStyle(MenuPickerStyle())
80+
.accentColor(.primary)
81+
#endif
82+
}
83+
84+
func setAsSegmentedControlStyle() -> some View {
85+
self
86+
#if os(iOS)
87+
.pickerStyle(SegmentedPickerStyle())
88+
#endif
89+
}
90+
}
91+
92+
// MARK: - NavigationView
93+
94+
extension NavigationView {
95+
96+
func setSingleColumnNavigationViewStyle() -> some View {
97+
self
98+
#if os(iOS)
99+
.navigationViewStyle(StackNavigationViewStyle())
100+
#endif
101+
}
102+
103+
func setupNavBarBackground() -> NavigationView {
104+
#if os(iOS)
105+
let appearance = UINavigationBarAppearance()
106+
let attributes: [NSAttributedString.Key: Any] = [
107+
.foregroundColor: UIColor.white
108+
]
109+
appearance.titleTextAttributes = attributes
110+
appearance.largeTitleTextAttributes = attributes
111+
appearance.backgroundColor = Assets.navBarBackground.uiColor // Dynamic Color.
112+
UINavigationBar.appearance().compactAppearance = appearance
113+
UINavigationBar.appearance().standardAppearance = appearance
114+
UINavigationBar.appearance().scrollEdgeAppearance = appearance
115+
#endif
116+
return self
117+
}
118+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// Assets.swift
3+
// iOS-Common-Libraries
4+
//
5+
// Created by Dinesh Harjani on 9/8/22.
6+
//
7+
8+
import SwiftUI
9+
10+
// MARK: - Assets
11+
12+
enum Assets: String {
13+
14+
// MARK: - Colors
15+
16+
case navBarBackground = "NavBar"
17+
case textColor = "PrimaryTextColor"
18+
#if os(OSX)
19+
case projectSelectorToolbarBackground = "MacProjectSelectorBackground"
20+
#endif
21+
22+
case blue = "NordicBlue"
23+
case sky = "NordicSky"
24+
case blueslate = "NordicBlueslate"
25+
case lake = "NordicLake"
26+
27+
case grass = "NordicGrass"
28+
case sun = "NordicSun"
29+
case red = "NordicRed"
30+
case fall = "NordicFall"
31+
32+
case lightGrey = "NordicLightGrey"
33+
case middleGrey = "NordicMiddleGrey"
34+
case darkGrey = "NordicDarkGrey"
35+
36+
var color: Color {
37+
Color(rawValue)
38+
}
39+
40+
#if os(iOS)
41+
var uiColor: UIColor! {
42+
UIColor(named: rawValue)
43+
}
44+
#endif
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// Constant.swift
3+
// iOS-Common-Libraries
4+
//
5+
// Created by Dinesh Harjani on 9/8/22.
6+
//
7+
8+
import Foundation
9+
10+
// MARK: - Constant
11+
12+
enum Constant {
13+
14+
// MARK: - Preview
15+
16+
static var isRunningInPreviewMode: Bool {
17+
ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
18+
}
19+
20+
// MARK: - App
21+
22+
static let copyright: String = {
23+
return "Copyright © \(Date.currentYear()) Nordic Semiconductor ASA"
24+
}()
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Date.swift
3+
// iOS-Common-Libraries
4+
//
5+
// Created by Dinesh Harjani on 9/8/22.
6+
//
7+
8+
import Foundation
9+
10+
extension Date {
11+
12+
static func currentYear() -> Int {
13+
guard let calendar = NSCalendar(calendarIdentifier: .gregorian) else {
14+
fatalError("Failed call to NSCalendar with Gregorian Calendar.")
15+
}
16+
return calendar.component(.year, from: Date())
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Preview.swift
3+
// iOS-Common-Libraries
4+
//
5+
// Created by Dinesh Harjani on 9/8/22.
6+
//
7+
8+
import Foundation
9+
10+
#if DEBUG
11+
enum Preview {
12+
13+
static func decode<T: Decodable>(filename: String) throws -> T? {
14+
let path: String! = Bundle.main.path(forResource: filename, ofType: "json")
15+
let content: String! = try? String(contentsOfFile: path)
16+
let contentData: Data! = content.data(using: .utf8)
17+
return try? JSONDecoder().decode(T.self, from: contentData)
18+
}
19+
}
20+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import XCTest
2+
@testable import iOS_Common_Libraries
3+
4+
final class iOS_Common_LibrariesTests: XCTestCase {
5+
6+
}

0 commit comments

Comments
 (0)