Skip to content

Commit

Permalink
SharedUI and WRCore package
Browse files Browse the repository at this point in the history
- Basic SharedUI Design system
- WRCore package for shared utils and core setup
  • Loading branch information
kaulex99 committed Jun 23, 2024
1 parent a1e5836 commit ce9a011
Show file tree
Hide file tree
Showing 53 changed files with 605 additions and 240 deletions.
8 changes: 8 additions & 0 deletions Modules/SharedUI/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
28 changes: 28 additions & 0 deletions Modules/SharedUI/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.10

import PackageDescription

let package = Package(
name: "SharedUI",
platforms: [
.iOS(.v15),
],
products: [
.library(
name: "SharedUI",
targets: ["SharedUI"]
),
],
targets: [
.target(
name: "SharedUI",
resources: [
.process("Resources"),
]
),
.testTarget(
name: "SharedUITests",
dependencies: ["SharedUI"]
),
]
)
21 changes: 21 additions & 0 deletions Modules/SharedUI/Sources/SharedUI/Colors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import SwiftUI

public extension Color {
static var main: Color {
Color(.main)
}

static var accent: Color {
Color(.accent)
}

/// black in light mode, white in dark mode
static var blackWhite: Color {
Color(.blackWhite)
}

/// white in light mode, black in dark mode
static var whiteBlack: Color {
Color(.whiteBlack)
}
}
84 changes: 84 additions & 0 deletions Modules/SharedUI/Sources/SharedUI/Fonts.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import SwiftUI

public enum WrFont {
case h1
case h2
case h3
case h4
case body
case caption1
case caption2

var baseSize: CGFloat {
switch self {
case .h1:
56
case .h2:
48
case .h3:
32
case .h4:
24
case .body:
16
case .caption1:
14
case .caption2:
12
}
}
}

private struct WrTextStyle: ViewModifier {
let fontStyle: WrFont

@ScaledMetric
var fontSize: CGFloat

var font: Font {
.system(size: fontSize)
}

init(fontStyle: WrFont) {
self.fontStyle = fontStyle
_fontSize = ScaledMetric(wrappedValue: fontStyle.baseSize)
}

func body(content: Content) -> some View {
content
.font(font)
}
}

public extension View {
func textStyle(_ font: WrFont) -> some View {
modifier(WrTextStyle(fontStyle: font))
}
}

#Preview {
ScrollView {
VStack {
Text("h1")
.textStyle(.h1)

Text("h2")
.textStyle(.h2)

Text("h3")
.textStyle(.h3)

Text("h4")
.textStyle(.h4)

Text("body")
.textStyle(.body)

Text("caption1")
.textStyle(.caption1)

Text("caption2")
.textStyle(.caption2)
}
}
}
11 changes: 11 additions & 0 deletions Modules/SharedUI/Sources/SharedUI/Images.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import SwiftUI

public extension Image {
static var logoRounded: Image {
Image(.logoRounded)
}

static var logoLaunch: Image {
Image(.logoLaunch)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "0.491",
"red" : "0.375"
"blue" : "0xFF",
"green" : "0x7D",
"red" : "0x60"
}
},
"idiom" : "universal"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xFF",
"green" : "0xBC",
"red" : "0xAC"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x88",
"green" : "0x4C",
"red" : "0x40"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000",
"red" : "1.000"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.000",
"green" : "0.000",
"red" : "0.000"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
20 changes: 20 additions & 0 deletions Modules/SharedUI/Sources/SharedUI/SharedUIExample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import SwiftUI

private struct SharedUIExample: View {
var body: some View {
VStack(alignment: .leading) {
Text("h1")
Text("h2")
Text("h3")
Text("h4")
Text("h5")
Text("h6")
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
}
}

#Preview {
SharedUIExample()
}
12 changes: 12 additions & 0 deletions Modules/SharedUI/Tests/SharedUITests/SharedUITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@testable import SharedUI
import XCTest

final class SharedUITests: XCTestCase {
func testExample() throws {
// XCTest Documentation
// https://developer.apple.com/documentation/xctest

// Defining Test Cases and Test Methods
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
}
}
8 changes: 8 additions & 0 deletions Modules/WRCore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
33 changes: 33 additions & 0 deletions Modules/WRCore/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// swift-tools-version: 5.10

import PackageDescription

let package = Package(
name: "WRCore",
platforms: [
.iOS(.v15),
],
products: [
.library(
name: "WRCore",
targets: ["WRCore"]
),
],
dependencies: [
.package(path: "../SharedUI"),
.package(url: "https://github.com/DatepollSystems/WaiterRobot-Shared-Android.git", from: "1.6.1"),
],
targets: [
.target(
name: "WRCore",
dependencies: [
.product(name: "SharedUI", package: "SharedUI"),
.product(name: "shared", package: "WaiterRobot-Shared-Android"),
]
),
.testTarget(
name: "WRCoreTests",
dependencies: ["WRCore"]
),
]
)
44 changes: 44 additions & 0 deletions Modules/WRCore/Sources/WRCore/Globals.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Foundation
import shared
import UIKit

public var koin: IosKoinComponent { IosKoinComponent.shared }

public var localize: shared.L.Companion { shared.L.Companion.shared }

public enum WRCore {
/// Setup of frameworks and all the other related stuff which is needed everywhere in the app
public static func setup() {
print("started app setup")
var appVersion = readFromInfoPlist(withKey: "CFBundleShortVersionString")
let versionSuffix = readFromInfoPlist(withKey: "VERSION_SUFFIX")
if !versionSuffix.isEmpty {
appVersion += "-\(versionSuffix)"
}

CommonApp.shared.doInit(
appVersion: appVersion,
appBuild: Int32(readFromInfoPlist(withKey: "CFBundleVersion"))!,
phoneModel: UIDevice.current.model,
os: OS.Ios(version: UIDevice.current.systemVersion),
allowedHostsCsv: readFromInfoPlist(withKey: "ALLOWED_HOSTS"),
stripeProvider: nil
)

KoinKt.doInitKoinIos()
let logger = koin.logger(tag: "AppDelegate")
logger.d { "initialized Koin" }

KMMResourcesLocalizationKt.localizationBundle = Bundle(for: shared.L.self)
logger.d { "initialized localization bundle" }
print("finished app setup")
}

private static func readFromInfoPlist(withKey key: String) -> String {
guard let value = Bundle.main.infoDictionary?[key] as? String else {
fatalError("Could not find key '\(key)' in info.plist file.")
}

return value
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import shared

extension KermitLogger {
public extension KermitLogger {
func d(message: @escaping () -> String) {
d(throwable: nil, tag: tag, message: message)
}
Expand Down
12 changes: 12 additions & 0 deletions Modules/WRCore/Sources/WRCore/KotlinArrayWrapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation
import shared

public extension Array where Element: AnyObject {
init(_ kotlinArray: KotlinArray<Element>) {
self.init()
let iterator = kotlinArray.iterator()
while iterator.hasNext() {
append(iterator.next() as! Element)
}
}
}
Loading

0 comments on commit ce9a011

Please sign in to comment.