Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
duweiwang committed Sep 9, 2022
1 parent 47288cc commit c447f53
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 5 deletions.
8 changes: 8 additions & 0 deletions ios-playground.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
940A8B8528B9CC9D002BF205 /* MarkdownUI in Frameworks */ = {isa = PBXBuildFile; productRef = 940A8B8428B9CC9D002BF205 /* MarkdownUI */; };
940A8D0028BA0384002BF205 /* RichText in Frameworks */ = {isa = PBXBuildFile; productRef = 940A8CFF28BA0384002BF205 /* RichText */; };
9465162328C8D81D00FA3E37 /* NavigationDemo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9465162228C8D81D00FA3E37 /* NavigationDemo.swift */; };
9465162528C8E62000FA3E37 /* DragDropDemo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9465162428C8E62000FA3E37 /* DragDropDemo.swift */; };
9465343728C38E9C0084E3E2 /* TextFieldDemo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9465343628C38E9C0084E3E2 /* TextFieldDemo.swift */; };
9476675828B908E400B56774 /* ImageDemo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9476675728B908E400B56774 /* ImageDemo.swift */; };
9476675A28B908FA00B56774 /* TextDemo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9476675928B908FA00B56774 /* TextDemo.swift */; };
Expand All @@ -35,11 +36,13 @@
94A5E03328B5163100724506 /* ButtonVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94A5E03228B5163100724506 /* ButtonVC.swift */; };
94A5E03628B516F600724506 /* DemoStructure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94A5E03528B516F600724506 /* DemoStructure.swift */; };
94A5E03A28B51BFF00724506 /* TextVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94A5E03928B51BFF00724506 /* TextVC.swift */; };
94D12CB428CAE9EC00517BE7 /* ToolbarDemo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94D12CB328CAE9EC00517BE7 /* ToolbarDemo.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
940A897928B92E14002BF205 /* FrameDemo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FrameDemo.swift; sourceTree = "<group>"; };
9465162228C8D81D00FA3E37 /* NavigationDemo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationDemo.swift; sourceTree = "<group>"; };
9465162428C8E62000FA3E37 /* DragDropDemo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DragDropDemo.swift; sourceTree = "<group>"; };
9465343628C38E9C0084E3E2 /* TextFieldDemo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldDemo.swift; sourceTree = "<group>"; };
9476675728B908E400B56774 /* ImageDemo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageDemo.swift; sourceTree = "<group>"; };
9476675928B908FA00B56774 /* TextDemo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextDemo.swift; sourceTree = "<group>"; };
Expand All @@ -66,6 +69,7 @@
94A5E03228B5163100724506 /* ButtonVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonVC.swift; sourceTree = "<group>"; };
94A5E03528B516F600724506 /* DemoStructure.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoStructure.swift; sourceTree = "<group>"; };
94A5E03928B51BFF00724506 /* TextVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextVC.swift; sourceTree = "<group>"; };
94D12CB328CAE9EC00517BE7 /* ToolbarDemo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolbarDemo.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -175,6 +179,8 @@
949011B728C33931007104EB /* ListDemo.swift */,
9465343628C38E9C0084E3E2 /* TextFieldDemo.swift */,
9465162228C8D81D00FA3E37 /* NavigationDemo.swift */,
9465162428C8E62000FA3E37 /* DragDropDemo.swift */,
94D12CB328CAE9EC00517BE7 /* ToolbarDemo.swift */,
);
path = swiftui;
sourceTree = "<group>";
Expand Down Expand Up @@ -265,6 +271,7 @@
9465343728C38E9C0084E3E2 /* TextFieldDemo.swift in Sources */,
9476675A28B908FA00B56774 /* TextDemo.swift in Sources */,
949013A428C386FE007104EB /* Codable.swift in Sources */,
94D12CB428CAE9EC00517BE7 /* ToolbarDemo.swift in Sources */,
9490F97428BB536D007104EB /* AlignmentDemo.swift in Sources */,
9490F97028BB11D7007104EB /* GridDemo.swift in Sources */,
949011B828C33931007104EB /* ListDemo.swift in Sources */,
Expand All @@ -278,6 +285,7 @@
94767EED28B7645900B02512 /* SwiftWithUikitVC.swift in Sources */,
9490FFA628BE3815007104EB /* UserDefaultsDemo.swift in Sources */,
9465162328C8D81D00FA3E37 /* NavigationDemo.swift in Sources */,
9465162528C8E62000FA3E37 /* DragDropDemo.swift in Sources */,
94767EEF28B7683500B02512 /* VStackDemo.swift in Sources */,
9490124928C351EF007104EB /* ErrorHandle.swift in Sources */,
9476675E28B90E9900B56774 /* HStackDemo.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
169 changes: 169 additions & 0 deletions ios-playground/swiftui/DragDropDemo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
////
//// DragDropDemo.swift
//// ios-playground
////
//// Created by 王杜伟 on 2022/9/7.
////
//
//import SwiftUI
//import Cocoa
//
//class DragDropDemo: SwiftWithUikitVC<DragDropView> {
// override var body: DragDropView {
// DragDropView()
// }
//}
//
//struct DragDropView: View {
// let img1url = Bundle.main.url(forResource: "Images/grapes", withExtension: "png")
// let img2url = Bundle.main.url(forResource: "Images/banana", withExtension: "png")
// let img3url = Bundle.main.url(forResource: "Images/peach", withExtension: "png")
// let img4url = Bundle.main.url(forResource: "Images/kiwi", withExtension: "png")
//
// var body: some View {
// HStack {
// VStack {
// DragableImage(url: img1url!)
//
// DragableImage(url: img3url!)
// }
//
// VStack {
// DragableImage(url: img2url!)
//
// DragableImage(url: img4url!)
// }
//
// DroppableArea()
// }.padding(40)
// }
//
// struct DragableImage: View {
// let url: URL
//
// var body: some View {
// Image(nsImage: NSImage(byReferencing: url))
// .resizable()
// .frame(width: 150, height: 150)
// .clipShape(Circle())
// .overlay(Circle().stroke(Color.white, lineWidth: 2))
// .padding(2)
// .overlay(Circle().strokeBorder(Color.black.opacity(0.1)))
// .shadow(radius: 3)
// .padding(4)
// .onDrag { return NSItemProvider(object: self.url as NSURL) }
// }
// }
//
// struct DroppableArea: View {
// @State private var imageUrls: [Int: URL] = [:]
// @State private var active = 0
//
// var body: some View {
// let dropDelegate = MyDropDelegate(imageUrls: $imageUrls, active: $active)
//
// return VStack {
// HStack {
// GridCell(active: self.active == 1, url: imageUrls[1])
//
// GridCell(active: self.active == 3, url: imageUrls[3])
// }
//
// HStack {
// GridCell(active: self.active == 2, url: imageUrls[2])
//
// GridCell(active: self.active == 4, url: imageUrls[4])
// }
//
// }
// .background(Rectangle().fill(Color.gray))
// .frame(width: 300, height: 300)
// .onDrop(of: ["public.file-url"], delegate: dropDelegate)
//
// }
// }
//
//
// struct GridCell: View {
// let active: Bool
// let url: URL?
//
// var body: some View {
// let img = Image(nsImage: url != nil ? NSImage(byReferencing: url!) : NSImage())
// .resizable()
// .frame(width: 150, height: 150)
//
// return Rectangle()
// .fill(self.active ? Color.green : Color.clear)
// .frame(width: 150, height: 150)
// .overlay(img)
// }
// }
//
//
// struct MyDropDelegate: DropDelegate {
// @Binding var imageUrls: [Int: URL]
// @Binding var active: Int
//
// func validateDrop(info: DropInfo) -> Bool {
// return info.hasItemsConforming(to: ["public.file-url"])
// }
//
// func dropEntered(info: DropInfo) {
// NSSound(named: "Morse")?.play()
// }
//
// func performDrop(info: DropInfo) -> Bool {
// NSSound(named: "Submarine")?.play()
//
// let gridPosition = getGridPosition(location: info.location)
// self.active = gridPosition
//
// if let item = info.itemProviders(for: ["public.file-url"]).first {
// item.loadItem(forTypeIdentifier: "public.file-url", options: nil) { (urlData, error) in
// DispatchQueue.main.async {
// if let urlData = urlData as? Data {
// self.imageUrls[gridPosition] = NSURL(absoluteURLWithDataRepresentation: urlData, relativeTo: nil) as URL
// }
// }
// }
//
// return true
//
// } else {
// return false
// }
//
// }
//
// func dropUpdated(info: DropInfo) -> DropProposal? {
// self.active = getGridPosition(location: info.location)
//
// return nil
// }
//
// func dropExited(info: DropInfo) {
// self.active = 0
// }
//
// func getGridPosition(location: CGPoint) -> Int {
// if location.x > 150 && location.y > 150 {
// return 4
// } else if location.x > 150 && location.y < 150 {
// return 3
// } else if location.x < 150 && location.y > 150 {
// return 2
// } else if location.x < 150 && location.y < 150 {
// return 1
// } else {
// return 0
// }
// }
// }
//}
//
//struct DragDropDemo_Previews: PreviewProvider {
// static var previews: some View {
// DragDropView()
// }
//}
10 changes: 5 additions & 5 deletions ios-playground/swiftui/NavigationDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

import SwiftUI

class NavigationDemo: SwiftWithUikitVC<NavigationView> {
override var body: NavigationView {
NavigationView()
class NavigationDemo: SwiftWithUikitVC<MyNavigationView> {
override var body: MyNavigationView {
MyNavigationView()
}
}

struct NavigationView: View {
struct MyNavigationView: View {
var body: some View {
VStack {
NavigationLink(destination: Animation1()) {
Expand Down Expand Up @@ -292,6 +292,6 @@ struct ModalView: View {

struct NavigationDemo_Previews: PreviewProvider {
static var previews: some View {
NavigationView()
MyNavigationView()
}
}
61 changes: 61 additions & 0 deletions ios-playground/swiftui/ToolbarDemo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// ToolbarDemo.swift
// ios-playground
//
// Created by 王杜伟 on 2022/9/9.
//

import SwiftUI

struct ToolbarView: View {
var body: some View {
NavigationView {
VStack {
Text("小王子的藝想世界")
.font(.largeTitle)
Image("icon_whatsapp")
.resizable()
.scaledToFit()
.frame(width: 100, height: 100)
}
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {} label: {
Text("edit")
}
}

ToolbarItem(placement: .cancellationAction) {
Button("Cancel") {
}
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
Button {} label: {
Text("edit")
}

Button {} label: {
Image(systemName: "plus")
}
}

ToolbarItem(placement: .principal) {
HStack {
Image("test_image_02")
.resizable()
.scaledToFit()
.frame(width: 50, height: 50)
.offset(y: 1)
Text("Peter")
}
}
}
}
}
}

struct ToolbarDemo_Previews: PreviewProvider {
static var previews: some View {
ToolbarView()
}
}

0 comments on commit c447f53

Please sign in to comment.