Skip to content

Commit

Permalink
onboarding screen implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Murat ŞENOL committed Nov 6, 2022
1 parent 4cde8dd commit 93e52d5
Show file tree
Hide file tree
Showing 24 changed files with 374 additions and 73 deletions.
12 changes: 0 additions & 12 deletions shoppingApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
D92AE1FC2914051900CDA738 /* ProductCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D92AE1FA2914051900CDA738 /* ProductCell.swift */; };
D92AE1FD2914051900CDA738 /* ProductCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D92AE1FB2914051900CDA738 /* ProductCell.xib */; };
D92AE20029140ED100CDA738 /* DoubleExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D92AE1FF29140ED100CDA738 /* DoubleExtensions.swift */; };
D93B6870291111A000A22842 /* OnboardingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D93B686F291111A000A22842 /* OnboardingViewModel.swift */; };
D9401CB02917CAF500861D4C /* IQKeyboardManagerSwift in Frameworks */ = {isa = PBXBuildFile; productRef = D9401CAF2917CAF500861D4C /* IQKeyboardManagerSwift */; };
D95DBCB02911103F0019EE17 /* OnboardingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D95DBCAE2911103F0019EE17 /* OnboardingViewController.swift */; };
D98B82912912B5CF002B63CB /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = D98B82902912B5CF002B63CB /* Kingfisher */; };
Expand Down Expand Up @@ -118,7 +117,6 @@
D92AE1FA2914051900CDA738 /* ProductCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductCell.swift; sourceTree = "<group>"; };
D92AE1FB2914051900CDA738 /* ProductCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ProductCell.xib; sourceTree = "<group>"; };
D92AE1FF29140ED100CDA738 /* DoubleExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DoubleExtensions.swift; sourceTree = "<group>"; };
D93B686F291111A000A22842 /* OnboardingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingViewModel.swift; sourceTree = "<group>"; };
D95DBCAE2911103F0019EE17 /* OnboardingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingViewController.swift; sourceTree = "<group>"; };
D9B5B9A7291515430039E881 /* ProductsDetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductsDetailViewModel.swift; sourceTree = "<group>"; };
D9B5B9A9291515560039E881 /* ProductsDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductsDetailViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -528,19 +526,10 @@
children = (
D9EC3A4029110D4B00049C9C /* View */,
D9EC3A3F29110D4600049C9C /* Controller */,
D9EC3A3E29110D3900049C9C /* ViewModel */,
);
path = Onboarding;
sourceTree = "<group>";
};
D9EC3A3E29110D3900049C9C /* ViewModel */ = {
isa = PBXGroup;
children = (
D93B686F291111A000A22842 /* OnboardingViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
};
D9EC3A3F29110D4600049C9C /* Controller */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -678,7 +667,6 @@
D9069320290FB78500BB779D /* AuthViewController.swift in Sources */,
D9069343290FC4CB00BB779D /* UIColor+Extensions.swift in Sources */,
D9BF7AB2291120990090E715 /* ProductsViewModel.swift in Sources */,
D93B6870291111A000A22842 /* OnboardingViewModel.swift in Sources */,
D9BF7A97291115E40090E715 /* OnboardingView.swift in Sources */,
D9BF7AB5291120A80090E715 /* ProductsViewController.swift in Sources */,
D9BF7AAF291120600090E715 /* MainViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<VariablesViewState
version = "1.0">
<ContextStates>
<ContextState
contextName = "MainViewController.didFetchBasket(response:):MainViewController.swift">
</ContextState>
<ContextState
contextName = "SearchViewController.viewDidLoad():SearchViewController.swift">
<PersistentStrings>
Expand All @@ -21,6 +24,17 @@
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "OnboardingViewController.onboardingViews.didset:OnboardingViewController.swift">
<PersistentStrings>
<PersistentString
value = "onboardingViews">
</PersistentString>
<PersistentString
value = "contentView">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "SearchViewController.didGetSearch(response:):SearchViewController.swift">
<PersistentStrings>
Expand Down
12 changes: 12 additions & 0 deletions shoppingApp/Assets.xcassets/basketScreen.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "basket.jpeg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions shoppingApp/Assets.xcassets/productDetail.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "productDetail.jpeg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions shoppingApp/Assets.xcassets/productDetail2.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "productDetail2.jpeg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions shoppingApp/Assets.xcassets/productsScreen.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "productsScreen.jpeg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "productsScreenDelete.jpeg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions shoppingApp/Assets.xcassets/profile.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "profile.jpeg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions shoppingApp/Assets.xcassets/signUpScreen.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "signUpScreen.jpeg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
153 changes: 153 additions & 0 deletions shoppingApp/Core/Extensions/UIImage/UIImageExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@

import Foundation
import UIKit
import ImageIO

fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let (l?, r?):
return l < r
case (nil, _?):
return true
default:
return false
}
}

extension UIImage {
func scalePreservingAspectRatio(targetSize: CGSize) -> UIImage {
Expand Down Expand Up @@ -42,4 +54,145 @@ extension UIImage {
return UIImage(ciImage: CIImage.empty())
}
}

public class func gifImageWithData(_ data: Data) -> UIImage? {
guard let source = CGImageSourceCreateWithData(data as CFData, nil) else {
print("image doesn't exist")
return nil
}

return UIImage.animatedImageWithSource(source)
}

public class func gifImageWithName(_ name: String) -> UIImage? {
guard let bundleURL = Bundle.main
.url(forResource: name, withExtension: "gif") else {
print("SwiftGif: This image named \"\(name)\" does not exist")
return nil
}
guard let imageData = try? Data(contentsOf: bundleURL) else {
print("SwiftGif: Cannot turn image named \"\(name)\" into NSData")
return nil
}

return gifImageWithData(imageData)
}

class func delayForImageAtIndex(_ index: Int, source: CGImageSource!) -> Double {
var delay = 0.1

let cfProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil)
let gifProperties: CFDictionary = unsafeBitCast(
CFDictionaryGetValue(cfProperties,
Unmanaged.passUnretained(kCGImagePropertyGIFDictionary).toOpaque()),
to: CFDictionary.self)

var delayObject: AnyObject = unsafeBitCast(
CFDictionaryGetValue(gifProperties,
Unmanaged.passUnretained(kCGImagePropertyGIFUnclampedDelayTime).toOpaque()),
to: AnyObject.self)
if delayObject.doubleValue == 0 {
delayObject = unsafeBitCast(CFDictionaryGetValue(gifProperties,
Unmanaged.passUnretained(kCGImagePropertyGIFDelayTime).toOpaque()), to: AnyObject.self)
}

delay = delayObject as! Double

if delay < 0.1 {
delay = 0.1
}

return delay
}

class func gcdForPair(_ a: Int?, _ b: Int?) -> Int {
var a = a
var b = b
if b == nil || a == nil {
if b != nil {
return b!
} else if a != nil {
return a!
} else {
return 0
}
}

if a < b {
let c = a
a = b
b = c
}

var rest: Int
while true {
rest = a! % b!

if rest == 0 {
return b!
} else {
a = b
b = rest
}
}
}

class func gcdForArray(_ array: Array<Int>) -> Int {
if array.isEmpty {
return 1
}

var gcd = array[0]

for val in array {
gcd = UIImage.gcdForPair(val, gcd)
}

return gcd
}

class func animatedImageWithSource(_ source: CGImageSource) -> UIImage? {
let count = CGImageSourceGetCount(source)
var images = [CGImage]()
var delays = [Int]()

for i in 0..<count {
if let image = CGImageSourceCreateImageAtIndex(source, i, nil) {
images.append(image)
}

let delaySeconds = UIImage.delayForImageAtIndex(Int(i),
source: source)
delays.append(Int(delaySeconds * 1000.0)) // Seconds to ms
}

let duration: Int = {
var sum = 0

for val: Int in delays {
sum += val
}

return sum
}()

let gcd = gcdForArray(delays)
var frames = [UIImage]()

var frame: UIImage
var frameCount: Int
for i in 0..<count {
frame = UIImage(cgImage: images[Int(i)])
frameCount = Int(delays[Int(i)] / gcd)

for _ in 0..<frameCount {
frames.append(frame)
}
}

let animation = UIImage.animatedImage(with: frames,
duration: Double(duration) / 1000.0)

return animation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ final class AuthViewController: UIViewController {
super.viewDidLoad()

viewModel.delegate = self
credentionTextField.text = "[email protected]"

/*
self.showLoadingIndicator()
Expand Down
Loading

0 comments on commit 93e52d5

Please sign in to comment.