Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add demo project #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
615 changes: 615 additions & 0 deletions AlertToastDemo/AlertToastDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "alerttoast",
"kind" : "remoteSourceControl",
"location" : "https://github.com/elai950/AlertToast.git",
"state" : {
"revision" : "a4f4267f6454259ba4ed8f9dadb87334a789c26c",
"version" : "1.3.7"
}
}
],
"version" : 2
}
17 changes: 17 additions & 0 deletions AlertToastDemo/AlertToastDemo/AlertToastDemoApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// AlertToastDemoApp.swift
// AlertToastDemo
//
// Created by Peace Cho on 10/14/22.
//

import SwiftUI

@main
struct AlertToastDemoApp: App {
var body: some Scene {
WindowGroup {
ContentView().environmentObject(AlertViewModel())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions AlertToastDemo/AlertToastDemo/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
80 changes: 80 additions & 0 deletions AlertToastDemo/AlertToastDemo/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// ContentView.swift
// AlertToastDemo
//
// Created by Peace Cho on 10/14/22.
//

import AlertToast
import SwiftUI


struct ContentView: View {

@EnvironmentObject var viewModel: AlertViewModel

var body: some View {
NavigationView{

Group{
NavigationLink("Move to Second View", destination: SecondView().environmentObject(viewModel))
}

}
.toast(isPresenting: $viewModel.show, duration: 2){
//Return AlertToast from ObservableObject
viewModel.alertToast
}
}
}

struct SecondView: View{

@EnvironmentObject var viewModel: AlertViewModel

var body: some View{
VStack{

//Presenting alert from ObservableObject
Button("Show Alert"){
viewModel.show.toggle()
}

//You can also change the alert type, present
//a different one and show (because of didSet)
Button("Change Alert Type to complete"){
viewModel.alertToast = AlertToast(type: .complete(.green), title: "Completed!", subTitle: nil)
}

Button("Change Alert Type to error"){
viewModel.alertToast = AlertToast(type: .error(.red), title: "Error occur", subTitle: "Try again later.")
}

Button("Change Alert Type to loading"){
viewModel.alertToast = AlertToast(type: .loading, title: "Loading..", subTitle: nil)
}



}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}


//Create an ObservableObject:
class AlertViewModel: ObservableObject{

@Published var show = false
@Published var alertToast = AlertToast(type: .regular, title: "this is regular alert!"){
didSet{
show.toggle()
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
36 changes: 36 additions & 0 deletions AlertToastDemo/AlertToastDemoTests/AlertToastDemoTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AlertToastDemoTests.swift
// AlertToastDemoTests
//
// Created by Peace Cho on 10/14/22.
//

import XCTest
@testable import AlertToastDemo

class AlertToastDemoTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}
41 changes: 41 additions & 0 deletions AlertToastDemo/AlertToastDemoUITests/AlertToastDemoUITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// AlertToastDemoUITests.swift
// AlertToastDemoUITests
//
// Created by Peace Cho on 10/14/22.
//

import XCTest

class AlertToastDemoUITests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()

// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testLaunchPerformance() throws {
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
// This measures how long it takes to launch your application.
measure(metrics: [XCTApplicationLaunchMetric()]) {
XCUIApplication().launch()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// AlertToastDemoUITestsLaunchTests.swift
// AlertToastDemoUITests
//
// Created by Peace Cho on 10/14/22.
//

import XCTest

class AlertToastDemoUITestsLaunchTests: XCTestCase {

override class var runsForEachTargetApplicationUIConfiguration: Bool {
true
}

override func setUpWithError() throws {
continueAfterFailure = false
}

func testLaunch() throws {
let app = XCUIApplication()
app.launch()

// Insert steps here to perform after app launch but before taking a screenshot,
// such as logging into a test account or navigating somewhere in the app

let attachment = XCTAttachment(screenshot: app.screenshot())
attachment.name = "Launch Screen"
attachment.lifetime = .keepAlways
add(attachment)
}
}