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

Commit c57c7f9

Browse files
committed
Add welcome modal
1 parent 3c6eaeb commit c57c7f9

File tree

6 files changed

+93
-21
lines changed

6 files changed

+93
-21
lines changed

Snip.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
791B8D7824E2C6C200851E2A /* SharePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791B8D7724E2C6C200851E2A /* SharePicker.swift */; };
1919
79284D6B2507CCDC00210E61 /* WelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79284D6A2507CCDC00210E61 /* WelcomeView.swift */; };
2020
79284D6D2507DE7F00210E61 /* PagerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79284D6C2507DE7F00210E61 /* PagerView.swift */; };
21+
79284D6F250A23E900210E61 /* Bundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79284D6E250A23E900210E61 /* Bundle.swift */; };
2122
7936F88F24D450B900F09AE7 /* SnipItemsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7936F88E24D450B900F09AE7 /* SnipItemsList.swift */; };
2223
7936F89324D6377D00F09AE7 /* List.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7936F89224D6377D00F09AE7 /* List.swift */; };
2324
7936F89624D637D800F09AE7 /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = 7936F89524D637D800F09AE7 /* Introspect */; };
@@ -90,6 +91,7 @@
9091
791B8D7724E2C6C200851E2A /* SharePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharePicker.swift; sourceTree = "<group>"; };
9192
79284D6A2507CCDC00210E61 /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = "<group>"; };
9293
79284D6C2507DE7F00210E61 /* PagerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagerView.swift; sourceTree = "<group>"; };
94+
79284D6E250A23E900210E61 /* Bundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bundle.swift; sourceTree = "<group>"; };
9395
7936F88E24D450B900F09AE7 /* SnipItemsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnipItemsList.swift; sourceTree = "<group>"; };
9496
7936F89224D6377D00F09AE7 /* List.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = List.swift; sourceTree = "<group>"; };
9597
7936F89924D845B600F09AE7 /* SnipItemsListAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnipItemsListAction.swift; sourceTree = "<group>"; };
@@ -344,6 +346,7 @@
344346
79956A4824E57AD900B823E1 /* CharacterSet.swift */,
345347
79956A4F24E5BC2300B823E1 /* URL.swift */,
346348
794D27DA24F6A19C006E3B3D /* Data.swift */,
349+
79284D6E250A23E900210E61 /* Bundle.swift */,
347350
);
348351
path = Extensions;
349352
sourceTree = "<group>";
@@ -536,6 +539,7 @@
536539
791B8D7624E28EF800851E2A /* AppState.swift in Sources */,
537540
79F07A2924D3050500469324 /* ImageButton.swift in Sources */,
538541
791AC9BE24DAA4FD00CAB87C /* TagView.swift in Sources */,
542+
79284D6F250A23E900210E61 /* Bundle.swift in Sources */,
539543
796B092924D1B563006904C4 /* Settings.swift in Sources */,
540544
79956A4924E57AD900B823E1 /* CharacterSet.swift in Sources */,
541545
79956A4E24E5A4A200B823E1 /* OAuth.swift in Sources */,

Snip/Components/Welcome/WelcomeView.swift

+54-20
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,69 @@ struct WelcomeView: View {
1717
ZStack {
1818

1919
backgroundView
20-
.frame(width: viewModel.size.width, height: viewModel.size.height)
21-
.transition(AnyTransition.opacity)
20+
.frame(width: viewModel.size.width, height: viewModel.size.height)
21+
.transition(AnyTransition.opacity)
2222

2323
VStack(alignment: .leading) {
2424
PagerView(pageCount: 3, currentIndex: $currentPage) {
25-
firstView
26-
secondView
25+
firstView
26+
secondView
2727
}
2828
}
2929
.frame(width: viewModel.size.width / 2.5,
3030
height: viewModel.size.height / 1.5,
3131
alignment: .center)
32-
.background(Color.secondary)
33-
.cornerRadius(4.0)
34-
.offset(x: 0,
35-
y: viewModel.isVisible ? ((viewModel.size.height / 2) - ((viewModel.size.height / 1.5) / 1.5)) : 10000)
36-
.transition(AnyTransition.move(edge: .bottom))
32+
.background(Color.BLACK_500)
33+
.cornerRadius(4.0)
34+
.offset(x: 0,
35+
y: viewModel.isVisible ? ((viewModel.size.height / 2) - ((viewModel.size.height / 1.5) / 1.5)) : 10000)
36+
.transition(AnyTransition.move(edge: .bottom))
3737
}
3838
}
3939

4040
var firstView: some View {
4141
VStack {
42-
Spacer()
43-
Text("Test 1")
42+
HStack {
43+
Spacer()
44+
Text("Welcome!")
45+
.foregroundColor(.text)
46+
.font(.title)
47+
Spacer()
48+
}
49+
Text("Changelog Ver. 1.2")
50+
.font(.subheadline)
51+
.foregroundColor(.text)
52+
.padding(EdgeInsets(top: 16, leading: 0, bottom: 16, trailing: 0))
53+
HStack {
54+
Text("- Fix 'non clickable' area\n- Add snippet from StackOverflow via a Chrome Ext.\n- A StackOverflow snippet has a special top bar button to open the dedicated StackOverflow Post")
55+
.font(Font.custom("CourierNewPSMT", size: 12))
56+
.foregroundColor(.text)
57+
Spacer()
58+
}
59+
.padding(EdgeInsets(top: 16, leading: 8, bottom: 16, trailing: 8))
60+
.background(Color.BLACK_200)
61+
Text("We Need Your Help!")
62+
.font(.subheadline)
63+
.foregroundColor(.text)
64+
.padding(EdgeInsets(top: 16, leading: 0, bottom: 16, trailing: 0))
65+
CodeView(code: .constant("Snip needs your help to grow!\n\nWant to translate snip into your native language?\nWant to have first-day in our next features?\n\nJOIN US now!"), mode: .constant(CodeMode.text.mode()))
66+
.frame(maxWidth: .infinity)
4467
Spacer()
4568
HStack {
4669
Spacer()
4770
Button(action: {
48-
self.currentPage += 1
71+
self.viewModel.isVisible = false
4972
}) {
50-
Text("Next")
51-
.padding(EdgeInsets(top: 8, leading: 20, bottom: 8, trailing: 20))
52-
.background(Color.accent)
53-
.cornerRadius(4)
73+
Text("Close")
74+
.padding(EdgeInsets(top: 8, leading: 20, bottom: 8, trailing: 20))
75+
.background(Color.transparent)
76+
}
77+
.buttonStyle(PlainButtonStyle())
78+
Button(action: self.viewModel.openSnipWebsite) {
79+
Text("JOIN US")
80+
.padding(EdgeInsets(top: 8, leading: 20, bottom: 8, trailing: 20))
81+
.background(Color.accentDark)
82+
.cornerRadius(4)
5483
}
5584
.buttonStyle(PlainButtonStyle())
5685
}
@@ -74,18 +103,23 @@ struct WelcomeView: View {
74103

75104
final class WelcomeViewModel: ObservableObject {
76105

77-
var isVisible: Bool
106+
@Binding var isVisible: Bool
78107
var size: CGSize
79108

80-
init(isVisible: Bool, readerSize: CGSize) {
81-
self.isVisible = isVisible
109+
init(isVisible: Binding<Bool>, readerSize: CGSize) {
110+
self._isVisible = isVisible
82111
self.size = readerSize
83112
}
113+
114+
func openSnipWebsite() {
115+
guard let url = URL(string: "https://snip.picta-hub.io") else { return }
116+
NSWorkspace.shared.open(url)
117+
}
84118
}
85119

86120
struct WelcomeView_Previews: PreviewProvider {
87121
static var previews: some View {
88-
WelcomeView(viewModel: WelcomeViewModel(isVisible: true,
122+
WelcomeView(viewModel: WelcomeViewModel(isVisible: .constant(true),
89123
readerSize: CGSize(width: 300, height: 400)))
90124
}
91125
}

Snip/Extensions/Bundle.swift

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Bundle.swift
3+
// Snip
4+
//
5+
// Created by Anthony Fernandez on 9/10/20.
6+
// Copyright © 2020 pictarine. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
12+
extension Bundle {
13+
14+
var releaseVersionNumber: String {
15+
return (infoDictionary!["CFBundleShortVersionString"] as! String)
16+
}
17+
var buildVersionNumber: String {
18+
return (infoDictionary!["CFBundleVersion"] as! String)
19+
}
20+
21+
}

Snip/Extensions/Color.swift

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ extension Color {
3939

4040
static let GREY_200 = Color.init(hex: "F6F8FA")
4141

42+
static let BLUE_700 = Color.init(hex: "0C1021")
43+
4244
init(hex: String) {
4345
let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
4446
var int: UInt64 = 0

Snip/Model/AppState.swift

+10
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,14 @@ class AppState: ObservableObject {
1313

1414
@Published var selectedSnippetId: String? = ""
1515
@Published var selectedSnippetFilter: ModelFilter = .all
16+
17+
@Published var shouldShowChangelogModel: Bool {
18+
didSet {
19+
UserDefaults.standard.set(Bundle.main.buildVersionNumber, forKey: "previous_launched_version")
20+
}
21+
}
22+
23+
init() {
24+
self.shouldShowChangelogModel = (UserDefaults.standard.object(forKey: "previous_launched_version") as? String ?? "") != Bundle.main.buildVersionNumber
25+
}
1626
}

Snip/SnipViewApp.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct SnipViewApp: View {
1414
@ObservedObject var snippetManager = SnippetManager.shared
1515
@ObservedObject var viewModel : SnipViewAppViewModel
1616
@EnvironmentObject var settings: Settings
17+
@EnvironmentObject var appState: AppState
1718

1819
var body: some View {
1920
appNavigation
@@ -78,7 +79,7 @@ struct SnipViewApp: View {
7879

7980
var welcomePanel: some View {
8081
GeometryReader { reader in
81-
WelcomeView(viewModel: WelcomeViewModel(isVisible: true, readerSize: reader.size))
82+
WelcomeView(viewModel: WelcomeViewModel(isVisible: self.$appState.shouldShowChangelogModel, readerSize: reader.size))
8283
}
8384
}
8485

0 commit comments

Comments
 (0)