Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/ Edit 화면 추가 #1

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions BlurMaskView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// BlurMaskView.swift
// moody
//
// Created by bart Shin on 25/06/2021.
//

import SwiftUI
import PencilKit

struct BlurMaskView: UIViewRepresentable {

@Binding var canvas: PKCanvasView
@Binding var markerWidth: CGFloat

private var tool: PKInkingTool {
PKInkingTool(
.marker, color: .white, width: markerWidth)
}

func makeUIView(context: Context) -> PKCanvasView {
canvas.drawingPolicy = .anyInput
canvas.tool = tool
canvas.backgroundColor = .clear
return canvas
}

func updateUIView(_ uiView: PKCanvasView, context: Context) {
canvas.tool = tool
}

init(canvas: Binding<PKCanvasView>, markerWidth: Binding<CGFloat>) {
_canvas = canvas
_markerWidth = markerWidth
}
}
70 changes: 66 additions & 4 deletions moody.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
objects = {

/* Begin PBXBuildFile section */
89110C812680AB50002779AA /* FilterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89110C802680AB50002779AA /* FilterView.swift */; };
89110C832680AD0E002779AA /* ImageEditFactor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89110C822680AD0E002779AA /* ImageEditFactor.swift */; };
89110C862680BCA0002779AA /* EditView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89110C852680BCA0002779AA /* EditView.swift */; };
89110C882680BCEB002779AA /* BottomNavigationButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89110C872680BCEB002779AA /* BottomNavigationButton.swift */; };
89110C8B2680BD57002779AA /* BottomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89110C8A2680BD57002779AA /* BottomNavigationBar.swift */; };
89110C8D2680C729002779AA /* ImageEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89110C8C2680C729002779AA /* ImageEditor.swift */; };
891DF6912684277A00A314B8 /* EditingImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891DF6902684277A00A314B8 /* EditingImage.swift */; };
891DF6932684283400A314B8 /* FeedBackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891DF6922684283400A314B8 /* FeedBackView.swift */; };
894A3B1E2686BE020091D5FE /* Publish.swift in Sources */ = {isa = PBXBuildFile; fileRef = 894A3B1D2686BE020091D5FE /* Publish.swift */; };
895BFC3A2680829000EB783E /* TuningPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 895BFC392680829000EB783E /* TuningPanel.swift */; };
898C02CC2685BA78008A2B2C /* BlurMaskView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898C02CB2685BA78008A2B2C /* BlurMaskView.swift */; };
C19759F8267CCE0B006003CA /* moodyApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C19759F7267CCE0B006003CA /* moodyApp.swift */; };
C19759FA267CCE0B006003CA /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C19759F9267CCE0B006003CA /* ContentView.swift */; };
C19759FC267CCE0D006003CA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C19759FB267CCE0D006003CA /* Assets.xcassets */; };
Expand All @@ -15,7 +26,7 @@
C1975A04267CCE0D006003CA /* moody.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = C1975A02267CCE0D006003CA /* moody.xcdatamodeld */; };
C1975A0F267CCE0D006003CA /* moodyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1975A0E267CCE0D006003CA /* moodyTests.swift */; };
C1975A1A267CCE0D006003CA /* moodyUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1975A19267CCE0D006003CA /* moodyUITests.swift */; };
C1975A2B267CCE8E006003CA /* Home.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1975A2A267CCE8E006003CA /* Home.swift */; };
C1975A2B267CCE8E006003CA /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1975A2A267CCE8E006003CA /* HomeView.swift */; };
C1975A2D267CCEAF006003CA /* ImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1975A2C267CCEAF006003CA /* ImagePicker.swift */; };
C1975A2F267CCEC8006003CA /* HomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1975A2E267CCEC8006003CA /* HomeViewModel.swift */; };
C1975A31267CCEE2006003CA /* FilteredImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1975A30267CCEE2006003CA /* FilteredImage.swift */; };
Expand All @@ -39,6 +50,17 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
89110C802680AB50002779AA /* FilterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterView.swift; sourceTree = "<group>"; };
89110C822680AD0E002779AA /* ImageEditFactor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageEditFactor.swift; sourceTree = "<group>"; };
89110C852680BCA0002779AA /* EditView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditView.swift; sourceTree = "<group>"; };
89110C872680BCEB002779AA /* BottomNavigationButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomNavigationButton.swift; sourceTree = "<group>"; };
89110C8A2680BD57002779AA /* BottomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomNavigationBar.swift; sourceTree = "<group>"; };
89110C8C2680C729002779AA /* ImageEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageEditor.swift; sourceTree = "<group>"; };
891DF6902684277A00A314B8 /* EditingImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditingImage.swift; sourceTree = "<group>"; };
891DF6922684283400A314B8 /* FeedBackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedBackView.swift; sourceTree = "<group>"; };
894A3B1D2686BE020091D5FE /* Publish.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Publish.swift; sourceTree = "<group>"; };
895BFC392680829000EB783E /* TuningPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TuningPanel.swift; sourceTree = "<group>"; };
898C02CB2685BA78008A2B2C /* BlurMaskView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurMaskView.swift; sourceTree = "<group>"; };
C19759F4267CCE0A006003CA /* moody.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = moody.app; sourceTree = BUILT_PRODUCTS_DIR; };
C19759F7267CCE0B006003CA /* moodyApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = moodyApp.swift; sourceTree = "<group>"; };
C19759F9267CCE0B006003CA /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand All @@ -53,7 +75,7 @@
C1975A15267CCE0D006003CA /* moodyUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = moodyUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C1975A19267CCE0D006003CA /* moodyUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = moodyUITests.swift; sourceTree = "<group>"; };
C1975A1B267CCE0D006003CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C1975A2A267CCE8E006003CA /* Home.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Home.swift; sourceTree = "<group>"; };
C1975A2A267CCE8E006003CA /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
C1975A2C267CCEAF006003CA /* ImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePicker.swift; sourceTree = "<group>"; };
C1975A2E267CCEC8006003CA /* HomeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewModel.swift; sourceTree = "<group>"; };
C1975A30267CCEE2006003CA /* FilteredImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilteredImage.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -84,9 +106,30 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
89110C842680AD30002779AA /* Helper */ = {
isa = PBXGroup;
children = (
89110C872680BCEB002779AA /* BottomNavigationButton.swift */,
89110C822680AD0E002779AA /* ImageEditFactor.swift */,
894A3B1D2686BE020091D5FE /* Publish.swift */,
);
path = Helper;
sourceTree = "<group>";
};
89110C892680BD18002779AA /* Edit */ = {
isa = PBXGroup;
children = (
89110C852680BCA0002779AA /* EditView.swift */,
891DF6902684277A00A314B8 /* EditingImage.swift */,
895BFC392680829000EB783E /* TuningPanel.swift */,
);
name = Edit;
sourceTree = "<group>";
};
C19759EB267CCE0A006003CA = {
isa = PBXGroup;
children = (
898C02CB2685BA78008A2B2C /* BlurMaskView.swift */,
C19759F6267CCE0A006003CA /* moody */,
C1975A0D267CCE0D006003CA /* moodyTests */,
C1975A18267CCE0D006003CA /* moodyUITests */,
Expand All @@ -111,6 +154,7 @@
C1975A28267CCE32006003CA /* ViewModel */,
C1975A27267CCE2B006003CA /* Model */,
C19759F7267CCE0B006003CA /* moodyApp.swift */,
89110C842680AD30002779AA /* Helper */,
C19759F9267CCE0B006003CA /* ContentView.swift */,
C19759FB267CCE0D006003CA /* Assets.xcassets */,
C1975A00267CCE0D006003CA /* Persistence.swift */,
Expand Down Expand Up @@ -159,14 +203,19 @@
isa = PBXGroup;
children = (
C1975A2E267CCEC8006003CA /* HomeViewModel.swift */,
89110C8C2680C729002779AA /* ImageEditor.swift */,
);
path = ViewModel;
sourceTree = "<group>";
};
C1975A29267CCE38006003CA /* View */ = {
isa = PBXGroup;
children = (
C1975A2A267CCE8E006003CA /* Home.swift */,
89110C892680BD18002779AA /* Edit */,
C1975A2A267CCE8E006003CA /* HomeView.swift */,
891DF6922684283400A314B8 /* FeedBackView.swift */,
89110C8A2680BD57002779AA /* BottomNavigationBar.swift */,
89110C802680AB50002779AA /* FilterView.swift */,
C1975A2C267CCEAF006003CA /* ImagePicker.swift */,
);
name = View;
Expand Down Expand Up @@ -302,12 +351,23 @@
buildActionMask = 2147483647;
files = (
C1975A31267CCEE2006003CA /* FilteredImage.swift in Sources */,
894A3B1E2686BE020091D5FE /* Publish.swift in Sources */,
C1975A01267CCE0D006003CA /* Persistence.swift in Sources */,
89110C882680BCEB002779AA /* BottomNavigationButton.swift in Sources */,
898C02CC2685BA78008A2B2C /* BlurMaskView.swift in Sources */,
89110C862680BCA0002779AA /* EditView.swift in Sources */,
891DF6912684277A00A314B8 /* EditingImage.swift in Sources */,
C19759FA267CCE0B006003CA /* ContentView.swift in Sources */,
C1975A2F267CCEC8006003CA /* HomeViewModel.swift in Sources */,
C1975A2B267CCE8E006003CA /* Home.swift in Sources */,
89110C832680AD0E002779AA /* ImageEditFactor.swift in Sources */,
C1975A2B267CCE8E006003CA /* HomeView.swift in Sources */,
891DF6932684283400A314B8 /* FeedBackView.swift in Sources */,
89110C8D2680C729002779AA /* ImageEditor.swift in Sources */,
C1975A2D267CCEAF006003CA /* ImagePicker.swift in Sources */,
C1975A04267CCE0D006003CA /* moody.xcdatamodeld in Sources */,
895BFC3A2680829000EB783E /* TuningPanel.swift in Sources */,
89110C812680AB50002779AA /* FilterView.swift in Sources */,
89110C8B2680BD57002779AA /* BottomNavigationBar.swift in Sources */,
C19759F8267CCE0B006003CA /* moodyApp.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -467,6 +527,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"moody/Preview Content\"";
DEVELOPMENT_TEAM = 96XCF965VW;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = moody/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
Expand All @@ -488,6 +549,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"moody/Preview Content\"";
DEVELOPMENT_TEAM = 96XCF965VW;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = moody/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
Expand Down
21 changes: 21 additions & 0 deletions moody/Assets.xcassets/selfie_dummy.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "selfie_dummy.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"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.
49 changes: 49 additions & 0 deletions moody/BottomNavigationBar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// BottomNavigationBar.swift
// moody
//
// Created by bart Shin on 21/06/2021.
//

import SwiftUI

struct BottomNavigationBar: View {

@Binding var navigationTag: String?

var body: some View {
HStack {
createNavigationLink(for: EditView(), image: Image(systemName: "slider.horizontal.below.rectangle"))
createNavigationLink(for: FilterView(), image: Image(systemName: "camera.filters"))
}
}

private func createNavigationLink<D>(for destination: D, image: Image) -> some View where D: View {
NavigationLink(
destination: destination,
tag: String(describing: D.self),
selection: $navigationTag)
{
drawButton(for: D.self, image: image)
.padding(.horizontal)
}
}

private func drawButton<D>(for destination: D.Type, image: Image) -> some View where D: View{
Button(action: {
navigationTag = String(describing: D.self)
} ) {
image
.resizable()
.frame(width: Constant.bottomButtonSize.width,
height: Constant.bottomButtonSize.height)
.padding()
}
.buttonStyle(BottomNavigation())
}

struct Constant {
static let bottomButtonSize = CGSize(width: 50, height: 50)
}
}

7 changes: 5 additions & 2 deletions moody/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ import CoreData
import SwiftUI

struct ContentView: View {
let editor = ImageEditor()

var body: some View {
NavigationView{
Home()
.navigationBarTitle("Filter")
HomeView()
.preferredColorScheme(.dark)
}
.environmentObject(editor)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.environmentObject(ImageEditor.forPreview)
}
}
99 changes: 99 additions & 0 deletions moody/EditView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//
// EditView.swift
// moody
//
// Created by bart Shin on 21/06/2021.
//

import SwiftUI

struct EditView: View, EditorDelegation {

@EnvironmentObject var editor: ImageEditor
@State private var isShowingPicker = false
@State private var feedBackImage: Image?
@State private var currentControl: String = ImageColorControl.brightness.rawValue

var body: some View {
ZStack {
VStack(spacing: 0) {
EditingImage(currentControl: $currentControl)
.contentShape(Rectangle())
TuningPanel(currentControl: $currentControl)
.onChange(of: isShowingPicker, perform: resetTunner(_:))
.disabled(editor.imageForDisplay == nil)
}
FeedBackView(feedBackImage: $feedBackImage)
}
.toolbar{
ToolbarItem(placement: .navigationBarLeading, content: drawSaveButton)
ToolbarItem(placement: .navigationBarTrailing,
content: drawPickerButton)
}
.sheet(isPresented: $isShowingPicker, content: createImagePicker)
.onAppear (perform: showPickerIfNeeded)
.navigationTitle("Edit")
}

private func drawSaveButton() -> some View {
Button(action: {
editor.saveImage()
}) {
Text("SAVE")
.font(.title)
}
}

private func drawPickerButton() -> some View {
Button(action: {
isShowingPicker = true
}) {
Image(systemName: "photo")
.font(.title2)
}
}

private func createImagePicker () -> ImagePicker {
ImagePicker(
picker: $isShowingPicker,
imageData: Binding<Data>.constant(Data()),
passImage: editor.setNewImage)
}

private func resetTunner(_ pickerPresenting: Bool) {
guard !isShowingPicker else { return }
withAnimation {
editor.colorControl = ImageColorControl.defaults
}
}

private func showPickerIfNeeded() {
guard editor.delegate == nil else {
return
}
editor.delegate = self
if editor.imageForDisplay == nil {
DispatchQueue.main.async {
isShowingPicker = true
}
}
}

// Editor delegation
func savingCompletion(error: Error?) {
if error == nil {
withAnimation{
feedBackImage = Image(systemName: "checkmark")
}
}else {
print("Fail to save image: \(error!.localizedDescription)")
}
}
}

struct EditView_Previews: PreviewProvider {
static var previews: some View {
EditView()
.environmentObject(ImageEditor.forPreview)
}
}
Loading