Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 238669a

Browse files
committed
Sliding panel for preview
1 parent 7ec810a commit 238669a

File tree

10 files changed

+106
-16
lines changed

10 files changed

+106
-16
lines changed

Snip.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
79BC1D3524D17142008FD16E /* CodeViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79BC1D3424D17142008FD16E /* CodeViewer.swift */; };
5252
79BC1D3724D17151008FD16E /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79BC1D3624D17151008FD16E /* SearchBar.swift */; };
5353
79C463CE24F43E17009B2DA3 /* Ink in Frameworks */ = {isa = PBXBuildFile; productRef = 79C463CD24F43E17009B2DA3 /* Ink */; };
54+
79C463D024F44233009B2DA3 /* MarkdownHTMLViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79C463CF24F44233009B2DA3 /* MarkdownHTMLViewer.swift */; };
5455
79DBD4CA24D1CBE500568364 /* CodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79DBD4C924D1CBE500568364 /* CodeView.swift */; };
55-
79DBD4CD24D1CEFD00568364 /* data.json in Resources */ = {isa = PBXBuildFile; fileRef = 79DBD4CC24D1CEFD00568364 /* data.json */; };
5656
79F07A2324D2F3DC00469324 /* ModeSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79F07A2224D2F3DC00469324 /* ModeSelectionView.swift */; };
5757
79F07A2524D2F9C700469324 /* CodeActionsTopBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79F07A2424D2F9C700469324 /* CodeActionsTopBar.swift */; };
5858
79F07A2724D3028C00469324 /* VisualEffectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79F07A2624D3028C00469324 /* VisualEffectView.swift */; };
@@ -104,8 +104,8 @@
104104
79BC1D3224D17124008FD16E /* Sidebar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar.swift; sourceTree = "<group>"; };
105105
79BC1D3424D17142008FD16E /* CodeViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeViewer.swift; sourceTree = "<group>"; };
106106
79BC1D3624D17151008FD16E /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = "<group>"; };
107+
79C463CF24F44233009B2DA3 /* MarkdownHTMLViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkdownHTMLViewer.swift; sourceTree = "<group>"; };
107108
79DBD4C924D1CBE500568364 /* CodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeView.swift; sourceTree = "<group>"; };
108-
79DBD4CC24D1CEFD00568364 /* data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = data.json; path = "../../Downloads/CodeMirror-Swift-master/example/CodeMirror-Swift-Example/CodeMirror-Swift-Example/data.json"; sourceTree = "<group>"; };
109109
79F07A2224D2F3DC00469324 /* ModeSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModeSelectionView.swift; sourceTree = "<group>"; };
110110
79F07A2424D2F9C700469324 /* CodeActionsTopBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeActionsTopBar.swift; sourceTree = "<group>"; };
111111
79F07A2624D3028C00469324 /* VisualEffectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisualEffectView.swift; sourceTree = "<group>"; };
@@ -245,7 +245,6 @@
245245
79DBD4C824D1CBBD00568364 /* Representables */,
246246
79BC1D2124D16E67008FD16E /* SnipViewApp.swift */,
247247
79BC1D1F24D16E67008FD16E /* AppDelegate.swift */,
248-
79DBD4CC24D1CEFD00568364 /* data.json */,
249248
79BC1D2324D16E6A008FD16E /* Assets.xcassets */,
250249
79BC1D2824D16E6A008FD16E /* Main.storyboard */,
251250
79BC1D2B24D16E6A008FD16E /* Info.plist */,
@@ -298,6 +297,7 @@
298297
79A6F64B24D20B8C0037C5FF /* CodeMirrorViewController.swift */,
299298
79F07A2624D3028C00469324 /* VisualEffectView.swift */,
300299
791B8D7724E2C6C200851E2A /* SharePicker.swift */,
300+
79C463CF24F44233009B2DA3 /* MarkdownHTMLViewer.swift */,
301301
);
302302
path = Representables;
303303
sourceTree = "<group>";
@@ -382,7 +382,6 @@
382382
796B093124D1B8F5006904C4 /* CodeMirrorView.bundle in Resources */,
383383
79BC1D2A24D16E6A008FD16E /* Main.storyboard in Resources */,
384384
79BC1D2724D16E6A008FD16E /* Preview Assets.xcassets in Resources */,
385-
79DBD4CD24D1CEFD00568364 /* data.json in Resources */,
386385
79BC1D2424D16E6A008FD16E /* Assets.xcassets in Resources */,
387386
);
388387
runOnlyForDeploymentPostprocessing = 0;
@@ -399,6 +398,7 @@
399398
79BC1D3524D17142008FD16E /* CodeViewer.swift in Sources */,
400399
796B093724D1BA1F006904C4 /* Date.swift in Sources */,
401400
7936F89F24DA02DD00F09AE7 /* TextField.swift in Sources */,
401+
79C463D024F44233009B2DA3 /* MarkdownHTMLViewer.swift in Sources */,
402402
79956A4724E57AC700B823E1 /* Dictionary.swift in Sources */,
403403
79BC1D2224D16E67008FD16E /* SnipViewApp.swift in Sources */,
404404
791B8D7624E28EF800851E2A /* AppState.swift in Sources */,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"filename" : "eye-slash-regular-1.png",
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"filename" : "eye-slash-regular.png",
14+
"idiom" : "universal",
15+
"scale" : "3x"
16+
}
17+
],
18+
"info" : {
19+
"author" : "xcode",
20+
"version" : 1
21+
}
22+
}
897 Bytes
Loading
897 Bytes
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"filename" : "eye-regular-1.png",
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"filename" : "eye-regular.png",
14+
"idiom" : "universal",
15+
"scale" : "3x"
16+
}
17+
],
18+
"info" : {
19+
"author" : "xcode",
20+
"version" : 1
21+
}
22+
}
788 Bytes
Loading
788 Bytes
Loading

Snip/Components/CodeViewer/CodeActionsTopBar.swift

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ struct CodeActionsTopBar: View {
1212

1313
@ObservedObject var syncManager = SyncManager.shared
1414
@ObservedObject var viewModel: CodeActionsViewModel
15-
@State var showSharingActions = false
16-
@State var showInfos = false
15+
@State private var showSharingActions = false
16+
@State private var showInfos = false
1717
@State private var moveRightLeft = false
18+
@State private var isPreviewEnabled = false
1819

1920
var body: some View {
2021
HStack{
@@ -56,6 +57,18 @@ struct CodeActionsTopBar: View {
5657
}
5758
}
5859

60+
if viewModel.onPreviewToggle != nil {
61+
ImageButton(imageName: isPreviewEnabled ? "ic_preview_hide" : "ic_preview_show",
62+
action: {
63+
self.viewModel.onPreviewToggle?()
64+
65+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
66+
self.isPreviewEnabled.toggle()
67+
}
68+
},
69+
content: { EmptyView() })
70+
}
71+
5972
ImageButton(imageName: viewModel.isSnipFavorite ? "ic_fav_selected" : "ic_fav",
6073
action: viewModel.onToggleFavorite,
6174
content: { EmptyView() })
@@ -109,6 +122,7 @@ final class CodeActionsViewModel: ObservableObject {
109122
var onToggleFavorite: () -> Void
110123
var onDelete: () -> Void
111124
var onUpload: () -> Void
125+
var onPreviewToggle: (() -> Void)?
112126

113127
init(name: String,
114128
code: String,
@@ -118,17 +132,19 @@ final class CodeActionsViewModel: ObservableObject {
118132
onRename: @escaping (String) -> Void,
119133
onToggleFavorite: @escaping () -> Void,
120134
onDelete: @escaping () -> Void,
121-
onUpload: @escaping () -> Void) {
135+
onUpload: @escaping () -> Void,
136+
onPreviewToggle: (() -> Void)?) {
122137

123-
snipName = name
124-
snipCode = code
125-
isSnipFavorite = isFavorite
126-
snipLastUpdate = lastUpdate
138+
self.snipName = name
139+
self.snipCode = code
140+
self.isSnipFavorite = isFavorite
141+
self.snipLastUpdate = lastUpdate
127142
self.syncState = syncState
128143
self.onRename = onRename
129144
self.onToggleFavorite = onToggleFavorite
130145
self.onDelete = onDelete
131146
self.onUpload = onUpload
147+
self.onPreviewToggle = onPreviewToggle
132148
}
133149

134150
}
@@ -143,7 +159,8 @@ struct CodeActionsTopBar_Previews: PreviewProvider {
143159
onRename: { _ in print("action")},
144160
onToggleFavorite: {},
145161
onDelete: {},
146-
onUpload: {})
162+
onUpload: {},
163+
onPreviewToggle: {})
147164
)
148165
}
149166
}

Snip/Components/CodeViewer/CodeViewer.swift

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ struct CodeViewer: View {
1515
@EnvironmentObject var appState: AppState
1616
@EnvironmentObject var snipItem: SnipItem
1717

18+
@State private var shouldShowPreview = false
19+
1820
var body: some View {
1921

2022
VStack(alignment: .leading) {
@@ -36,7 +38,13 @@ struct CodeViewer: View {
3638
},
3739
onUpload: {
3840
self.viewModel.onTrigger(.createGist(id: self.snipItem.id))
39-
}))
41+
},
42+
onPreviewToggle: self.snipItem.mode == CodeMode.html.mode() ? {
43+
withAnimation(Animation.easeOut(duration: 0.6)) { () -> () in
44+
self.shouldShowPreview.toggle()
45+
}
46+
} : nil
47+
))
4048

4149
ModeSelectionView(viewModel: ModeSelectionViewModel(snippetMode: snipItem.mode,
4250
snippetTags: snipItem.tags,
@@ -50,15 +58,27 @@ struct CodeViewer: View {
5058
tag: tag))
5159
}))
5260

53-
CodeView(code: .constant(snipItem.snippet),
54-
mode: .constant(snipItem.mode),
61+
CodeView(code: .constant(self.snipItem.snippet),
62+
mode: .constant(self.snipItem.mode),
5563
onContentChange: { newCode in
5664
self.viewModel.onTrigger(.updateCode(id: self.snipItem.id, code: newCode))
5765
})
5866
.frame(minWidth: 100,
5967
maxWidth: .infinity,
6068
minHeight: 100,
6169
maxHeight: .infinity)
70+
.overlay(
71+
HStack() {
72+
Text("ok")
73+
}
74+
.frame(minWidth: 100,
75+
maxWidth: .infinity,
76+
minHeight: 100,
77+
maxHeight: .infinity)
78+
.background(Color.YELLOW_500)
79+
.offset(x: self.shouldShowPreview ? 0 : 10000, y: 0)
80+
.transition(AnyTransition.move(edge: .trailing)), alignment: .topLeading)
81+
6282

6383
Divider()
6484

@@ -110,7 +130,7 @@ class CodeViewerViewModel: ObservableObject {
110130
struct CodeViewer_Previews: PreviewProvider {
111131
static var previews: some View {
112132
CodeViewer(viewModel: CodeViewerViewModel(onTrigger: { _ in
113-
print("action")
133+
print("action")
114134
},
115135
onDimiss: { print("onDismiss")}
116136
))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// MarkdownHTMLViewer.swift
3+
// Snip
4+
//
5+
// Created by Anthony Fernandez on 8/24/20.
6+
// Copyright © 2020 pictarine. All rights reserved.
7+
//
8+
9+
import Foundation

0 commit comments

Comments
 (0)