Skip to content

Commit

Permalink
chore: ios sample app improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
programadorthi committed Feb 9, 2024
1 parent 3c9e5a6 commit c4c3271
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 99 deletions.
22 changes: 21 additions & 1 deletion samples/ios-sample/ios-sample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
60452B6A2B768636006BC8CB /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60452B692B768636006BC8CB /* HomeView.swift */; };
60452B6C2B7686C4006BC8CB /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60452B6B2B7686C4006BC8CB /* LoginView.swift */; };
60452B6E2B7687AC006BC8CB /* MyLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60452B6D2B7687AC006BC8CB /* MyLogger.swift */; };
6064E7942B767D1B00F65D52 /* UIKitShared.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6064E7932B767D1B00F65D52 /* UIKitShared.framework */; };
6064E7952B767D1B00F65D52 /* UIKitShared.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6064E7932B767D1B00F65D52 /* UIKitShared.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
606654F42B75A69E00786DA1 /* RoutingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 606654F32B75A69E00786DA1 /* RoutingController.swift */; };
Expand All @@ -32,6 +35,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
60452B692B768636006BC8CB /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
60452B6B2B7686C4006BC8CB /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
60452B6D2B7687AC006BC8CB /* MyLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyLogger.swift; sourceTree = "<group>"; };
6064E7932B767D1B00F65D52 /* UIKitShared.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKitShared.framework; path = "../../integration/uikit/build/xcode-frameworks/Debug/iphonesimulator16.4/UIKitShared.framework"; sourceTree = "<group>"; };
606654F32B75A69E00786DA1 /* RoutingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoutingController.swift; sourceTree = "<group>"; };
606655172B75B21300786DA1 /* SwiftUIController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIController.swift; sourceTree = "<group>"; };
Expand All @@ -54,6 +60,16 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
60452B682B76861C006BC8CB /* View */ = {
isa = PBXGroup;
children = (
609CFD802B73A0600079F82D /* ContentView.swift */,
60452B692B768636006BC8CB /* HomeView.swift */,
60452B6B2B7686C4006BC8CB /* LoginView.swift */,
);
name = View;
sourceTree = "<group>";
};
609CFD722B73A0600079F82D = {
isa = PBXGroup;
children = (
Expand All @@ -74,12 +90,13 @@
609CFD7D2B73A0600079F82D /* ios-sample */ = {
isa = PBXGroup;
children = (
60452B682B76861C006BC8CB /* View */,
609CFD7E2B73A0600079F82D /* ios_sampleApp.swift */,
609CFD802B73A0600079F82D /* ContentView.swift */,
609CFD822B73A0610079F82D /* Assets.xcassets */,
609CFD842B73A0610079F82D /* Preview Content */,
606654F32B75A69E00786DA1 /* RoutingController.swift */,
606655172B75B21300786DA1 /* SwiftUIController.swift */,
60452B6D2B7687AC006BC8CB /* MyLogger.swift */,
);
path = "ios-sample";
sourceTree = "<group>";
Expand Down Expand Up @@ -193,9 +210,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
60452B6C2B7686C4006BC8CB /* LoginView.swift in Sources */,
609CFD812B73A0600079F82D /* ContentView.swift in Sources */,
60452B6E2B7687AC006BC8CB /* MyLogger.swift in Sources */,
609CFD7F2B73A0600079F82D /* ios_sampleApp.swift in Sources */,
606655182B75B21300786DA1 /* SwiftUIController.swift in Sources */,
60452B6A2B768636006BC8CB /* HomeView.swift in Sources */,
606654F42B75A69E00786DA1 /* RoutingController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
12 changes: 3 additions & 9 deletions samples/ios-sample/ios-sample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import UIKitShared

struct ContentView: View {

var router: Routing?
let router: Routing

init(router: Routing? = nil) {
init(router: Routing) {
self.router = router
}

Expand All @@ -26,13 +26,7 @@ struct ContentView: View {
}
.padding()
.onTapGesture {
router?.callUri(uri: "/login", routeMethod: RouteMethodCompanion().Push)
router.callUri(uri: "/login", routeMethod: RouteMethodCompanion().Push)
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
32 changes: 32 additions & 0 deletions samples/ios-sample/ios-sample/HomeView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// HomeView.swift
// ios-sample
//
// Created by Thiago dos Santos on 09/02/24.
//

import SwiftUI
import UIKitShared

struct HomeView : View {

let router: Routing

init(router: Routing) {
self.router = router
}

var body: some View {
VStack {
Text("Hello, Home! Go to Login")
.onTapGesture {
router.callUri(uri: "/login", routeMethod: RouteMethodCompanion().Push)
}
Text("Pop Home!")
.onTapGesture {
router.popController(animated: true)
}
}
}

}
32 changes: 32 additions & 0 deletions samples/ios-sample/ios-sample/LoginView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// LoginView.swift
// ios-sample
//
// Created by Thiago dos Santos on 09/02/24.
//

import SwiftUI
import UIKitShared

struct LoginView : View {

let router: Routing

init(router: Routing) {
self.router = router
}

var body: some View {
VStack {
Text("Hello, Login! Go to Home")
.onTapGesture {
router.callUri(uri: "/home", routeMethod: RouteMethodCompanion().ReplaceAll)
}
Text("Pop Login!")
.onTapGesture {
router.popController(animated: true)
}
}
}

}
58 changes: 58 additions & 0 deletions samples/ios-sample/ios-sample/MyLogger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// MyLogger.swift
// ios-sample
//
// Created by Thiago dos Santos on 09/02/24.
//

import os
import UIKitShared

class MyLogger : UIKitShared.Logger {

private let logger = Logger()

var level: UIKitShared.LogLevel = .trace

init() {}

func debug(message: String) {
logger.debug("\(message)")
}

func debug(message: String, cause: KotlinThrowable) {
logger.debug("\(message) -> \(cause)")
}

func error(message: String) {
logger.error("\(message)")
}

func error(message: String, cause: KotlinThrowable) {
logger.error("\(message) -> \(cause)")
}

func info(message: String) {
logger.info("\(message)")
}

func info(message: String, cause: KotlinThrowable) {
logger.info("\(message) -> \(cause)")
}

func trace(message: String) {
logger.trace("\(message)")
}

func trace(message: String, cause: KotlinThrowable) {
logger.trace("\(message) -> \(cause)")
}

func warn(message: String) {
logger.warning("\(message)")
}

func warn(message: String, cause: KotlinThrowable) {
logger.warning("\(message) -> \(cause)")
}
}
3 changes: 1 addition & 2 deletions samples/ios-sample/ios-sample/RoutingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public struct RoutingController {
extension RoutingController: UIViewControllerRepresentable {

public func makeUIViewController(context _: Context) -> UINavigationController {
router.application_.logger?.debug(message: ">>>> makeUIViewController")
let navigationController = UINavigationController()
navigationController.navigationBar.prefersLargeTitles = prefersLargeTitles

Expand All @@ -45,6 +44,6 @@ extension RoutingController: UIViewControllerRepresentable {
}

public func updateUIViewController(_ uiViewController: UINavigationController, context _: Context) {
router.application_.logger?.debug(message: ">>>> updateUIViewController: \(uiViewController)")
// no-op
}
}
108 changes: 21 additions & 87 deletions samples/ios-sample/ios-sample/ios_sampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Thiago dos Santos on 07/02/24.
//

import os
import SwiftUI
import UIKitShared

Expand All @@ -24,95 +23,30 @@ struct ios_sampleApp: App {
WindowGroup {
RoutingController(router: router)
.onAppear {
router.controller(path: "/home", animated: true) { call in
router.application_.logger?.debug(message: ">>>> home controller: \(call)")
return SwiftUIController {
VStack {
Text("Hello, Home! Go to Login")
.onTapGesture {
router.callUri(uri: "/login", routeMethod: RouteMethodCompanion().Push)
}
Text("Pop Home!")
.onTapGesture {
router.popController(animated: true)
}
}
}
}

router.controller(path: "/login", animated: true) { call in
router.application_.logger?.debug(message: ">>>> login controller: \(call)")
return SwiftUIController {
VStack {
Text("Hello, Login! Go to Home")
.onTapGesture {
router.callUri(uri: "/home", routeMethod: RouteMethodCompanion().ReplaceAll)
}
Text("Pop Login!")
.onTapGesture {
router.popController(animated: true)
}
}
}
}

router.handle(path: "/home") { call in
router.application_.logger?.debug(message: ">>>> home handle: \(call)")
}

router.handle(path: "/login") { call in
router.application_.logger?.debug(message: ">>>> login handle: \(call)")
}
setupRoutes()
}
}
}
}

private class MyLogger : UIKitShared.Logger {

private let logger = Logger()

var level: UIKitShared.LogLevel = .trace

init() {}

func debug(message: String) {
logger.debug("\(message)")
}

func debug(message: String, cause: KotlinThrowable) {
logger.debug("\(message) -> \(cause)")
}

func error(message: String) {
logger.error("\(message)")
}

func error(message: String, cause: KotlinThrowable) {
logger.error("\(message) -> \(cause)")
}

func info(message: String) {
logger.info("\(message)")
}

func info(message: String, cause: KotlinThrowable) {
logger.info("\(message) -> \(cause)")
}

func trace(message: String) {
logger.trace("\(message)")
}

func trace(message: String, cause: KotlinThrowable) {
logger.trace("\(message) -> \(cause)")
}

func warn(message: String) {
logger.warning("\(message)")
}

func warn(message: String, cause: KotlinThrowable) {
logger.warning("\(message) -> \(cause)")
private func setupRoutes() {
router.controller(path: "/home", animated: true) { _ in
SwiftUIController {
HomeView(router: router)
}
}

router.controller(path: "/login", animated: true) { _ in
SwiftUIController {
LoginView(router: router)
}
}

router.handle(path: "/home") { call in
router.application_.logger?.debug(message: ">>>> home handle is called too: \(call)")
}

router.handle(path: "/login") { call in
router.application_.logger?.debug(message: ">>>> login handle is called too: \(call)")
}
}
}

0 comments on commit c4c3271

Please sign in to comment.