Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ios-sample/EnvConfig.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// EnvConfig.xcconfig
// ios-sample
//
// Created by Koji Osugi on 24/01/23.
// Copyright © 2023 orgName. All rights reserved.
//

// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974


API_KEY = // YOUR API KEY
11 changes: 11 additions & 0 deletions ios-sample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# YChat GPT iOS Sample

## Setup

You need to supply an API key for running this sample successfully.

### Steps

1. Go to the `EnvConfig.xcconfig` file located in the root folder of this sample project;

2. Set your API key in the `API_KEY` variable. Click [here](https://beta.openai.com/docs/api-reference/authentication) to get more information on how to get the api key.
248 changes: 240 additions & 8 deletions ios-sample/ios-sample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

126 changes: 126 additions & 0 deletions ios-sample/ios-sample/App/Presenter/Main/MainView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//
// MainView.swift
// ios-sample
//
// Created by Koji Osugi on 22/01/23.
// Copyright © 2023 orgName. All rights reserved.
//

import SwiftUI

internal struct MainView: View {

@ObservedObject
private var mainRouter: MainRouter = MainRouter.shared

@State private var showSidebar: Bool = false

private var topBarTitle: String {
switch mainRouter.navGraph.destination {
case .completion: return "Completion"
}
}

var body: some View {
NavigationStack {
ZStack() {
VStack(alignment: .leading) {
TopBar()
Group {
switch mainRouter.navGraph.destination {
case .completion: CompletionView()
}
}
.transition(mainRouter.navGraph.animation)
.animation(.default, value: mainRouter.navGraph.destination)
}
.fullScreen()
SideMenu(isVisible: $showSidebar) {
SideMenuContent()
}
}
}
}

@ViewBuilder
private func TopBar() -> some View {
HStack(spacing: 0) {
ImageButton(
.menu,
color: .accentColor,
action: { showSidebar.toggle() }
)
Text(topBarTitle)
.style(.title)
.padding(.leading, 16)
Spacer()
}
.padding(16)
.frame(maxWidth: .infinity)
.compositingGroup()
}

@ViewBuilder
private func SideMenuContent() -> some View {
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 8) {
Image(uiImage: .logo)
Text("YChat GPT")
.style(.bodyBold)
}
.padding(.horizontal, 16)
.padding(.vertical, 16)
Divider()
.padding(.bottom, 16)
MenuItem(
icon: .chat,
text: "Completion",
destination: .completion
)
}
.frame(
maxWidth: .infinity,
maxHeight: .infinity,
alignment: .topLeading
)
}

@ViewBuilder
private func MenuItem(
icon: UIImage,
text: String,
destination: MainRouter.Destination
) -> some View {
let isSelected: Bool = mainRouter.navGraph.destination == destination
let bgColor = isSelected ? Color.primaryExtraLight : .background
let foregroundColor = isSelected ? Color.accentColor : .grayDark
Button(
action: {
mainRouter.replace(destination)
showSidebar.toggle()
}
) {
HStack(spacing: 8) {
Image(uiImage: icon)
.renderingMode(.template)
.foregroundColor(foregroundColor)
Text(text)
.foregroundColor(foregroundColor)
.style(.caption)
Spacer()
}
.padding(.vertical, 12)
.padding(.horizontal, 16)
.frame(maxWidth: .infinity)
.background(bgColor)
.cornerRadius(20, corners: [.topRight, .bottomRight])
.padding(.trailing, 16)
}
}
}

internal struct MainView_Previews: PreviewProvider {
static var previews: some View {
MainView()
}
}
43 changes: 43 additions & 0 deletions ios-sample/ios-sample/App/Presenter/Splash/SplashView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// SplashView.swift
// ios-sample
//
// Created by Koji Osugi on 22/01/23.
// Copyright © 2023 orgName. All rights reserved.
//

import SwiftUI

internal struct SplashView: View {

private let appRouter: AppRouter

init(appRouter: AppRouter = AppRouter.shared) {
self.appRouter = appRouter
}

var body: some View {
VStack {
HStack(spacing: 8) {
Image(uiImage: .logoBig)
Text("YChat GPT")
.font(.system(size: 24))
.foregroundColor(.grayDark)
.bold()
}
}
.fullScreen(alignment: .center)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
appRouter.push(.main)
}
}
}
}

internal struct SplashView_Previews: PreviewProvider {
static var previews: some View {
SplashView()
}
}

27 changes: 27 additions & 0 deletions ios-sample/ios-sample/App/Router/AppRouter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// AppRouter.swift
// ios-sample
//
// Created by Koji Osugi on 22/01/23.
// Copyright © 2023 orgName. All rights reserved.
//

import Foundation

internal final class AppRouter: ObservableObject {

static var shared = AppRouter()

private init() {}

enum Destination: Equatable {
case splash
case main
}

@Published var navGraph: NavGraph<Destination> = .init(destination: .splash)

func push(_ destination: Destination) {
navGraph.push(destination: destination)
}
}
26 changes: 26 additions & 0 deletions ios-sample/ios-sample/App/Router/MainRouter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// MainRouter.swift
// ios-sample
//
// Created by Koji Osugi on 22/01/23.
// Copyright © 2023 orgName. All rights reserved.
//

import Foundation

internal final class MainRouter: ObservableObject {

static var shared = MainRouter()

private init() {}

enum Destination: Equatable {
case completion
}

@Published var navGraph: NavGraph<Destination> = .init(destination: .completion)

func replace(_ destination: Destination) {
navGraph.replace(destination, animation: .opacity)
}
}
21 changes: 21 additions & 0 deletions ios-sample/ios-sample/App/iOSApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import SwiftUI

@main
struct iOSApp: App {

@ObservedObject
private var appRouter: AppRouter = AppRouter.shared

var body: some Scene {
WindowGroup {
Group {
switch appRouter.navGraph.destination {
case .splash: SplashView()
case .main: MainView()
}
}
.transition(appRouter.navGraph.animation)
.animation(.default, value: appRouter.navGraph.destination)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xFF",
"green" : "0x8A",
"red" : "0x44"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xFF",
"green" : "0xFF",
"red" : "0xFF"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions ios-sample/ios-sample/Assets.xcassets/Colors/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x21",
"green" : "0x21",
"red" : "0x21"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xF5",
"green" : "0xF5",
"red" : "0xF5"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xE0",
"green" : "0xE0",
"red" : "0xE0"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading