-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from juandahurt/modal
feat: add basic modal ui
- Loading branch information
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// ModalExample.swift | ||
// PuraceDemo | ||
// | ||
// Created by Juan Hurtado on 19/06/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import Purace | ||
|
||
struct ModalExample: View { | ||
@State var isVisible = false | ||
|
||
var body: some View { | ||
ZStack { | ||
VStack { | ||
PuraceButtonView("Mostrar") { | ||
isVisible.toggle() | ||
} | ||
Spacer() | ||
} | ||
PuraceModalView( | ||
title: "Lorem ipsum", | ||
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", | ||
isVisible: $isVisible | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// PuraceModalView.swift | ||
// | ||
// | ||
// Created by Juan Hurtado on 19/06/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
public struct PuraceModalView: View { | ||
let titleText: String | ||
let contentText: String | ||
var isVisible: Binding<Bool> | ||
|
||
@State var opacity: Double = 0 | ||
|
||
public init(title: String, content: String, isVisible: Binding<Bool>) { | ||
self.titleText = title | ||
self.contentText = content | ||
self.isVisible = isVisible | ||
} | ||
|
||
var title: some View { | ||
HStack { | ||
PuraceTextView(titleText, fontSize: 14, weight: .medium) | ||
.multilineTextAlignment(.leading) | ||
Spacer(minLength: 0) | ||
} | ||
} | ||
|
||
var content: some View { | ||
HStack { | ||
PuraceTextView(contentText) | ||
.multilineTextAlignment(.leading) | ||
Spacer(minLength: 0) | ||
} | ||
} | ||
|
||
var card: some View { | ||
VStack(spacing: 5) { | ||
title | ||
content | ||
} | ||
.padding() | ||
.background(Color.white) | ||
.opacity(opacity) | ||
.cornerRadius(5) | ||
} | ||
|
||
public var body: some View { | ||
ZStack { | ||
Color.black | ||
.opacity(0.7) | ||
VStack(spacing: 15) { | ||
HStack { | ||
Spacer() | ||
Image(systemName: "xmark") | ||
.foregroundColor(.white) | ||
.onTapGesture { | ||
isVisible.wrappedValue = false | ||
} | ||
} | ||
card | ||
}.padding(.horizontal) | ||
} | ||
.onChange(of: isVisible.wrappedValue) { visible in | ||
withAnimation { | ||
opacity = visible ? 1 : 0 | ||
} | ||
} | ||
.opacity(opacity) | ||
} | ||
} |