-
Notifications
You must be signed in to change notification settings - Fork 456
Implemented Simple and Detailed Contact Views in SwiftUI #477
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
Open
kutakmir
wants to merge
14
commits into
carekit-apple:master
Choose a base branch
from
TheraForge:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
aa01805
Implemented Simple and Detailed Contact Views in SwiftUI
kutakmir ea6ca20
Merge pull request #2 from carekit-apple/master
kutakmir a512f3f
Merge branch 'master' into feature/swiftUIcontact
kutakmir 35e6e5a
Merge pull request #1 from HippocratesTech/feature/swiftUIcontact
kutakmir 4242136
Added actions to the DetailedContactView.
kutakmir 73464d0
Merge branch 'feature/swiftUIcontact' of https://github.com/Hippocrat…
kutakmir 0eb6037
Merge pull request #3 from HippocratesTech/feature/swiftUIcontact
kutakmir b9fc42b
Merged with latest cbaker fork
kutakmir c8634eb
Added missing files
kutakmir 5c3b281
Create README.md
marco-theraforge 09423e0
Update README.md
marco-theraforge 00320b6
Update README.md
marco-theraforge 6853749
Update README.md
marco-theraforge 245471c
Update README.md
marco-theraforge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
138 changes: 138 additions & 0 deletions
138
CareKit/CareKit/Shared/Contact/DetailedContactView.swift
This file contains hidden or 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,138 @@ | ||
// | ||
/* | ||
Copyright (c) 2020, Apple Inc. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation and/or | ||
other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder(s) nor the names of any contributors | ||
may be used to endorse or promote products derived from this software without | ||
specific prior written permission. No license is granted to the trademarks of | ||
the copyright holders even if such marks are included in this software. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
import CareKitStore | ||
import CareKitUI | ||
import Foundation | ||
import SwiftUI | ||
|
||
/// A card that displays information for a contact. The header is an `OCKHeaderView` | ||
/// The body contains a multi-line istructions label, and four buttons; call, message, | ||
/// email, and address. The first three buttons have title labels and image views that can | ||
/// be modified, while the last has a title label, body label, and image view. | ||
/// | ||
/// +-------------------------------------------------------+ | ||
/// | +------+ | | ||
/// | | icon | [title] | | ||
/// | | img | [detail] | | ||
/// | +------+ | | ||
/// | | | ||
/// | -------------------------------------------------- | | ||
/// | | | ||
/// | [Instructions] | | ||
/// | | | ||
/// | +------------+ +------------+ +------------+ | | ||
/// | | [title] | | [title] | | [title] | | | ||
/// | | | | | | | | | ||
/// | +------------+ +------------+ +------------+ | | ||
/// | | | ||
/// | +---------------------------------------------------+ | | ||
/// | | [title] | | | ||
/// | | [detail] | | | ||
/// | | | | | ||
/// | +---------------------------------------------------+ | | ||
/// +-------------------------------------------------------+ | ||
/// | ||
@available(iOS 14.0, watchOS 7.0, *) | ||
public struct DetailedContactView<Header: View, Footer: View>: View { | ||
private typealias ContactView = SynchronizedContactView<OCKDetailedContactController, CareKitUI.DetailedContactView<Header, Footer>> | ||
|
||
private let contactView: ContactView | ||
|
||
public var body: some View { | ||
contactView | ||
} | ||
|
||
private init(contactView: ContactView) { | ||
self.contactView = contactView | ||
} | ||
|
||
public init(contactID: String, storeManager: OCKSynchronizedStoreManager, content: @escaping (_ controller: OCKDetailedContactController) -> CareKitUI.DetailedContactView<Header, Footer>) { | ||
contactView = .init(controller: .init(storeManager: storeManager), query: .contactID(contactID), content: content) | ||
} | ||
|
||
public init(contact: OCKAnyContact, contactQuery: OCKContactQuery, storeManager: OCKSynchronizedStoreManager, | ||
content: @escaping (_ controller: OCKDetailedContactController) -> CareKitUI.DetailedContactView<Header, Footer>) { | ||
contactView = .init(controller: .init(storeManager: storeManager), query: .init(.contact(contact)), content: content) | ||
} | ||
|
||
public init(controller: OCKDetailedContactController, content: @escaping (_ controller: OCKDetailedContactController) -> CareKitUI.DetailedContactView<Header, Footer>) { | ||
contactView = .init(controller: controller, content: content) | ||
} | ||
|
||
public func onError(_ perform: @escaping (Error) -> Void) -> DetailedContactView<Header, Footer> { | ||
.init(contactView: .init(copying: contactView, settingErrorHandler: perform)) | ||
} | ||
} | ||
|
||
@available(iOS 14.0, watchOS 7.0, *) | ||
public extension DetailedContactView where Header == _DetailedContactViewHeader, Footer == _DetailedContactViewFooter { | ||
init(contactID: String, storeManager: OCKSynchronizedStoreManager) { | ||
self.init(contactID: contactID, storeManager: storeManager) { | ||
.init(viewModel: $0.viewModel) | ||
} | ||
} | ||
|
||
init(contact: OCKAnyContact,contactQuery: OCKContactQuery, storeManager: OCKSynchronizedStoreManager) { | ||
self.init(contact: contact, contactQuery: contactQuery, storeManager: storeManager) { | ||
.init(viewModel: $0.viewModel) | ||
} | ||
} | ||
|
||
init(controller: OCKDetailedContactController) { | ||
contactView = .init(controller: controller) { | ||
.init(viewModel: $0.viewModel) | ||
} | ||
} | ||
} | ||
|
||
// CODE REVIEW: Let's add actions - they are nil right now, see UIKit version | ||
kutakmir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
private extension CareKitUI.DetailedContactView where Header == _DetailedContactViewHeader, Footer == _DetailedContactViewFooter { | ||
init(viewModel: ContactViewModel?) { | ||
self.init(title: Text(viewModel?.title ?? ""), detail: Text(viewModel?.detail ?? ""), instructions: Text(viewModel?.instructions ?? ""), image: Image(systemName: "person.crop.circle"), disclosureImage: nil, callButton: ContactButton(title: Text("Call"), image: Image(systemName: "phone"), action: nil), messageButton: ContactButton(title: Text("Message"), image: Image(systemName: "text.bubble"), action: nil), emailButton: ContactButton(title: Text("E-mail"), image: Image(systemName: "envelope"), action: nil), addressButton: AddressButton(title: Text("Address"), detail: Text(viewModel?.address ?? ""), image: Image(systemName: "location"), action: nil)) | ||
kutakmir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
/// Data used to create a `CareKitUI.DetailedContactView`. | ||
public struct ContactViewModel { | ||
|
||
/// The title text to display in the header. | ||
public let title: String | ||
|
||
/// The detail text to display in the header. | ||
public let detail: String? | ||
|
||
/// The instructions text to display under the header. | ||
public let instructions: String? | ||
|
||
/// The address text to display under the address button. | ||
public let address: String? | ||
} | ||
kutakmir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.