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

Commit

Permalink
Fix preview, add viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallino16 committed Dec 7, 2020
1 parent bfdff6c commit 3c69c06
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions Snip/Components/CodeViewer/CodeViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ struct CodeViewer: View {
@Environment(\.themeTextColor) var themeTextColor
@Environment(\.themePrimaryColor) var themePrimaryColor

@State private var shouldShowPreview = false

var body: some View {

VStack(alignment: .leading) {
Expand All @@ -44,7 +42,7 @@ struct CodeViewer: View {
},
onPreviewToggle: viewModel.snipItem.mode == CodeMode.html.mode() || viewModel.snipItem.mode == CodeMode.markdown.mode() ? {
withAnimation(Animation.easeOut(duration: 0.6)) { () -> () in
self.shouldShowPreview.toggle()
viewModel.shouldShowPreview.toggle()
}
} : nil
))
Expand Down Expand Up @@ -73,10 +71,10 @@ struct CodeViewer: View {
onContentChange: { newCode in
viewModel.saveNewCodeSnippet(newCode)
})
.frame(width: self.shouldShowPreview ? reader.size.width / 2 : reader.size.width, height: reader.size.height)
.frame(width: viewModel.shouldShowPreview ? reader.size.width / 2 : reader.size.width, height: reader.size.height)


if self.shouldShowPreview {
if viewModel.shouldShowPreview {
Divider()

MarkdownHTMLViewer(code: viewModel.snipItem.snippet, mode: viewModel.snipItem.mode)
Expand Down Expand Up @@ -105,6 +103,7 @@ struct CodeViewer: View {
final class CodeViewerViewModel: ObservableObject {

@Published var snipItem: SnipItem
@Published var shouldShowPreview = false
var onTrigger: (SnipItemsListAction) -> Void
var onDimiss: () -> Void

Expand Down
2 changes: 1 addition & 1 deletion Snip/Representables/MarkdownHTMLViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct MarkdownHTMLViewer: NSViewRepresentable {
let down = Down(markdownString: code)

if let html = try? down.toHTML() {
htmlSource = "<article class=\"markdown-body\">\(html)</article>"
htmlSource = "<head><meta name=\"viewport\" content=\"initial-scale=1.0\" /></head>" + "<article class=\"markdown-body\">\(html)</article>"
}
}

Expand Down

0 comments on commit 3c69c06

Please sign in to comment.