Skip to content

Commit

Permalink
feat(demo): add slugify demo in app
Browse files Browse the repository at this point in the history
  • Loading branch information
dirtyhenry committed Jul 15, 2024
1 parent ab210c1 commit 4b9026e
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 48 deletions.
6 changes: 6 additions & 0 deletions Examples/BlocksApp/BlocksApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
002136DF2B57DDD40031AE9A /* TaskStateDemoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 002136DE2B57DDD40031AE9A /* TaskStateDemoView.swift */; };
0030C2522A99047F00AB2087 /* WatchState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0030C2512A99047F00AB2087 /* WatchState.swift */; };
0030C2542A99077400AB2087 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 0030C2532A99077400AB2087 /* Settings.bundle */; };
00333CCB2C45682900A58365 /* SlugifyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00333CCA2C45682900A58365 /* SlugifyView.swift */; };
0038EF682C00F1F0004BF4FB /* LoggingPlaygroundView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0038EF672C00F1F0004BF4FB /* LoggingPlaygroundView.swift */; };
003995752AFBF4680051BFCE /* BackgroundTaskView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 003995742AFBF4680051BFCE /* BackgroundTaskView.swift */; };
007314A72AF00BFC0092F234 /* FontsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 007314A62AF00BFC0092F234 /* FontsView.swift */; };
Expand Down Expand Up @@ -52,6 +53,7 @@
002136DE2B57DDD40031AE9A /* TaskStateDemoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskStateDemoView.swift; sourceTree = "<group>"; };
0030C2512A99047F00AB2087 /* WatchState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchState.swift; sourceTree = "<group>"; };
0030C2532A99077400AB2087 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
00333CCA2C45682900A58365 /* SlugifyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SlugifyView.swift; sourceTree = "<group>"; };
0038EF672C00F1F0004BF4FB /* LoggingPlaygroundView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggingPlaygroundView.swift; sourceTree = "<group>"; };
003995742AFBF4680051BFCE /* BackgroundTaskView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundTaskView.swift; sourceTree = "<group>"; };
006E38742A370C0600B4142B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -121,6 +123,7 @@
002136DC2B57C2570031AE9A /* PlainDateDemoView.swift */,
002136DE2B57DDD40031AE9A /* TaskStateDemoView.swift */,
0038EF672C00F1F0004BF4FB /* LoggingPlaygroundView.swift */,
00333CCA2C45682900A58365 /* SlugifyView.swift */,
);
path = Features;
sourceTree = "<group>";
Expand Down Expand Up @@ -328,6 +331,7 @@
003995752AFBF4680051BFCE /* BackgroundTaskView.swift in Sources */,
008D62CE2A56C96E00254FD9 /* MailComposeView.swift in Sources */,
002136DD2B57C2570031AE9A /* PlainDateDemoView.swift in Sources */,
00333CCB2C45682900A58365 /* SlugifyView.swift in Sources */,
00D1E24A2A36327100E8D275 /* ContentView.swift in Sources */,
007314A72AF00BFC0092F234 /* FontsView.swift in Sources */,
0030C2522A99047F00AB2087 /* WatchState.swift in Sources */,
Expand Down Expand Up @@ -503,6 +507,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -537,6 +542,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
104 changes: 56 additions & 48 deletions Examples/BlocksApp/BlocksApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct ContentView: View {
case fileSystemExplorer = "FileSystem Explorer"
case plainDateDemo = "PlainDate demo"
case loggingPlayground = "Logging Playground"
case slugifyPlayground = "Slugify Playground"

var id: String {
rawValue
Expand Down Expand Up @@ -52,60 +53,67 @@ struct ContentView: View {
}
}
} detail: {
if let selectedSectionId, let section = Section(rawValue: selectedSectionId) {
switch section {
case .misc:
VStack {
Text("Is a watch paired with this iPhone?")
Text(model.state.rawValue)
Spacer().frame(height: 16)
#if os(iOS) || os(tvOS)
Button("Photo", role: nil) {
isShowingCamera = true
}.fullScreenCover(isPresented: $isShowingCamera) {
// In order to use this, `NSCameraUsageDescription` must be set.
ImagePickerView(sourceType: .camera, mediaTypes: [UTType.image.identifier])
.edgesIgnoringSafeArea(.all)
}
Spacer().frame(height: 16)
#endif

#if canImport(MessageUI)
if MailComposeView.canSendMail() {
Button("Mail", role: nil) {
isShowingComposer = true
}.fullScreenCover(isPresented: $isShowingComposer) {
MailComposeView()
Group {
if let selectedSectionId, let section = Section(rawValue: selectedSectionId) {
switch section {
case .misc:
VStack {
Text("Is a watch paired with this iPhone?")
Text(model.state.rawValue)
Spacer().frame(height: 16)
#if os(iOS) || os(tvOS)
Button("Photo", role: nil) {
isShowingCamera = true
}.fullScreenCover(isPresented: $isShowingCamera) {
// In order to use this, `NSCameraUsageDescription` must be set.
ImagePickerView(sourceType: .camera, mediaTypes: [UTType.image.identifier])
.edgesIgnoringSafeArea(.all)
}
} else {
Text("Can not send mail in-app.")
}
#endif
Spacer().frame(height: 16)
#endif

Link("Alternative mailto", destination: mailtoURL())
}
.padding()
case .fonts:
FontsView()
#if os(iOS)
case .bg:
BackgroundTaskView()
#endif
case .fileSystemExplorer:
Button("Explore") {
explore()
#if canImport(MessageUI)
if MailComposeView.canSendMail() {
Button("Mail", role: nil) {
isShowingComposer = true
}.fullScreenCover(isPresented: $isShowingComposer) {
MailComposeView()
.edgesIgnoringSafeArea(.all)
}
} else {
Text("Can not send mail in-app.")
}
#endif

Link("Alternative mailto", destination: mailtoURL())
}
.padding()
case .fonts:
FontsView()
#if os(iOS)
case .bg:
BackgroundTaskView()
#endif
case .fileSystemExplorer:
Button("Explore") {
explore()
}
case .plainDateDemo:
PlainDateDemoView()
case .taskStateDemo:
TaskStateDemoView()
case .loggingPlayground:
LoggingPlaygroundView()
case .slugifyPlayground:
SlugifyView()
}
case .plainDateDemo:
PlainDateDemoView()
case .taskStateDemo:
TaskStateDemoView()
case .loggingPlayground:
LoggingPlaygroundView()
} else {
Text("Select a section")
}
} else {
Text("Select a section")
}
#if os(macOS)
.scenePadding()
#endif
}
.onAppear {
model.start()
Expand Down
39 changes: 39 additions & 0 deletions Examples/BlocksApp/BlocksApp/Features/SlugifyView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Blocks
import os
import OSLog
import SwiftUI

struct SlugifyView: View {
@State private var input: String = ""
@State private var slug: String = "".slugify()

private let pasteboard = Pasteboard()

var body: some View {
Form {
TextField(text: $input, prompt: Text("Input to Slugify")) {
Text("Input")
}.disableAutocorrection(true)
#if os(macOS)
LabeledContent {
Text(slug)
} label: {
Text("Slug")
}
#else
Text(slug)
#endif
Button("Copy") {
pasteboard.copy(text: slug)
}
}
.onChange(of: input) { _, newValue in
slug = newValue.slugify()
}
.navigationTitle("Slugify")
}
}

#Preview {
SlugifyView()
}

0 comments on commit 4b9026e

Please sign in to comment.