Skip to content

Commit

Permalink
Added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanis Plumit committed Nov 11, 2022
1 parent 0184afc commit e0b1f8d
Show file tree
Hide file tree
Showing 18 changed files with 881 additions and 0 deletions.
402 changes: 402 additions & 0 deletions Examples/Examples.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" : "zpopuppresenter",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Jnis/ZPopupPresenter.git",
"state" : {
"branch" : "main",
"revision" : "0184afcf9d40cd71a082bc53b4d58258db1d3e73"
}
}
],
"version" : 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
63 changes: 63 additions & 0 deletions Examples/Examples/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Examples/Examples/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"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 Examples/Examples/Assets.xcassets/pig.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : " pig.jpg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
37 changes: 37 additions & 0 deletions Examples/Examples/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// ContentView.swift
// Examples
//
// Created by Yanis Plumit on 11.11.2022.
//

import SwiftUI
import ZPopupPresenter


struct ContentView: View {
let zPopupPresenterModel = ZPopupPresenterModel() // 1. model

var body: some View {
ZStack {
NavigationView {
TabView {
MenuView()
.tabItem {
Label("Menu", systemImage: "list.dash")
}
.environmentObject(zPopupPresenterModel) // 2. inject model for subviews
//
}
}

ZPopupPresenterView(model: zPopupPresenterModel) // 3. popups place
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
76 changes: 76 additions & 0 deletions Examples/Examples/Demo1View.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// Demo1View.swift
// Examples
//
// Created by Yanis Plumit on 11.11.2022.
//

import SwiftUI
import ZPopupPresenter

struct Demo1View: View {
@EnvironmentObject var zPopupPresenterModel: ZPopupPresenterModel

let buttonsOffset: CGFloat
let close: () -> Void

var body: some View {
VStack {
Spacer().frame(height: buttonsOffset)

HStack {
showPopupWithAnimationButton

Button(action: {
close()
}, label: {
HStack {
Spacer()
Text("Close popup")
.padding()
.foregroundColor(.blue)
.background(Capsule().foregroundColor(.yellow))
Spacer()
}
})
}

Spacer()
}
.background(Color.gray.opacity(0.8))
}

var showPopupWithAnimationButton: some View {
Button(action: {
withAnimation {
zPopupPresenterModel.showPopup({ close in
AnyView(
Demo1View(buttonsOffset: buttonsOffset + 50, close: {
withAnimation {
close()
}
})
.environmentObject(zPopupPresenterModel)
.transition(.slide)
)
})
}
}, label: {
HStack {
Spacer()
Text("With Animation")
.padding()
.foregroundColor(.blue)
.background(Capsule().foregroundColor(.white))
Spacer()
}
})
}

}

struct Demo1View_Previews: PreviewProvider {
static var previews: some View {
Demo1View(buttonsOffset: 0, close: {})
}
}
79 changes: 79 additions & 0 deletions Examples/Examples/Demo2DetailsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// Demo2DetaisView.swift
// Examples
//
// Created by Yanis Plumit on 11.11.2022.
//

import SwiftUI

struct Demo2DetailsView: View {
enum AnimationIDs {
static let image = "image"
static let title = "title"
static let bg = "bg"
}

var namespace: Namespace.ID
let close: () -> Void

var body: some View {
ZStack {
ScrollView {
VStack {
Image("pig")
.resizable()
.scaledToFit()
.matchedGeometryEffect(id: Demo2DetailsView.AnimationIDs.image, in: namespace)

HStack {
Text("Run Pig Run!")
.font(.title)
.padding(.bottom, 16)
.matchedGeometryEffect(id: Demo2DetailsView.AnimationIDs.title, in: namespace, properties: .position)
Spacer()
}.padding()

HStack {
Text(description)
.padding(.bottom, 16)
Spacer()
}.padding()
}
}

VStack {
HStack {
Spacer()
Button(action: {
close()
}, label: {
Text("Close popup")
.padding()
.foregroundColor(.blue)
.background(Capsule().foregroundColor(.yellow))
})
}
Spacer()
}
}
.background(.white)
.matchedGeometryEffect(id: Demo2DetailsView.AnimationIDs.bg, in: namespace)
}

let description = """
The piggy escaped from cage and he are waiting your help!
Only you can help out the little pig to escape slaughterhouse, where prepare amazing pork. And we don't promise you, that it will be easy, but it will be interesting and exciting!!
The success of the little piggy only in your hands.
"""
}

struct Demo2DetailsView_Previews: PreviewProvider {
@Namespace static var namespace

static var previews: some View {
Demo2DetailsView(namespace: namespace, close: {})
}
}
58 changes: 58 additions & 0 deletions Examples/Examples/Demo2ItemView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Demo2ItemView.swift
// Examples
//
// Created by Yanis Plumit on 11.11.2022.
//

import SwiftUI
import ZPopupPresenter

struct Demo2ItemView: View {
@Namespace var namespace
@EnvironmentObject var zPopupPresenterModel: ZPopupPresenterModel

var body: some View {
VStack {
Image("pig")
.resizable()
.scaledToFit()
.padding(.top, 20)
.matchedGeometryEffect(id: Demo2DetailsView.AnimationIDs.image, in: namespace)

Text("Run Pig Run!")
.font(.title)
.padding(.bottom, 16)
.matchedGeometryEffect(id: Demo2DetailsView.AnimationIDs.title, in: namespace, properties: .position)
}
.background(Color.white.cornerRadius(20))
.onTapGesture {
withAnimation(.spring()) {
zPopupPresenterModel.showPopup({ close in
AnyView(
Demo2DetailsView(namespace: namespace, close: {
withAnimation(.spring()) {
close()
}
})
)
})
}
}
.overlay(content: {
Color.clear
.matchedGeometryEffect(id: Demo2DetailsView.AnimationIDs.bg, in: namespace)
})
}
}

struct Demo2ItemView_Previews: PreviewProvider {
static var previews: some View {
VStack {
Spacer()
Demo2ItemView()
Spacer()
}
.background(.black)
}
}
Loading

0 comments on commit e0b1f8d

Please sign in to comment.