generated from StanfordBDHG/SwiftPackageTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Initial setup of repository ## ♻️ Current situation & Problem Currently, the repo is mostly empty except for a template package. ## ⚙️ Release Notes - Initial setup of the `SpeziChat` repo which previously was a target in the [SpeziML](https://github.com/StanfordSpezi/SpeziML) repo - Improved README and documentation via DocC ## 📚 Documentation -- ## ✅ Testing UI Tests are included ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [X] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
- Loading branch information
1 parent
0e0ff11
commit b8f84de
Showing
38 changed files
with
1,041 additions
and
213 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 |
---|---|---|
|
@@ -11,4 +11,4 @@ builder: | |
configs: | ||
- platform: ios | ||
documentation_targets: | ||
- SpeziChat | ||
- SpeziChat |
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
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
This file was deleted.
Oops, something went wrong.
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,91 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open source project | ||
// | ||
// SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import SwiftUI | ||
|
||
|
||
/// Provides a basic reusable chat view which includes a message input field. The input can be either typed out via the iOS keyboard or provided as voice input and transcribed into written text. | ||
/// | ||
/// The actual content of the ``ChatView`` is defined by a ``Chat``, which contains an ordered array of ``ChatEntity``s representing the individual messages within the ``ChatView``. | ||
/// The ``Chat`` is passed to the ``ChatView`` as a SwiftUI `Binding`, which enables modification of the ``Chat`` from outside of the view, for example via a SwiftUI `.onChange()` `View` modifier. | ||
/// | ||
/// | ||
/// ```swift | ||
/// struct ChatTestView: View { | ||
/// @State private var chat: Chat = [ | ||
/// ChatEntity(role: .assistant, content: "Assistant Message!") | ||
/// ] | ||
/// | ||
/// var body: some View { | ||
/// ChatView($chat) | ||
/// .navigationTitle("SpeziChat") | ||
/// } | ||
/// } | ||
/// ``` | ||
public struct ChatView: View { | ||
@Binding var chat: Chat | ||
@Binding var disableInput: Bool | ||
let messagePlaceholder: String? | ||
|
||
@State var messageInputHeight: CGFloat = 0 | ||
|
||
|
||
public var body: some View { | ||
ZStack { | ||
VStack { | ||
MessagesView($chat, bottomPadding: $messageInputHeight) | ||
.gesture( | ||
TapGesture().onEnded { | ||
UIApplication.shared.sendAction( | ||
#selector(UIResponder.resignFirstResponder), | ||
to: nil, | ||
from: nil, | ||
for: nil | ||
) | ||
} | ||
) | ||
} | ||
VStack { | ||
Spacer() | ||
MessageInputView($chat, messagePlaceholder: messagePlaceholder) | ||
.disabled(disableInput) | ||
.onPreferenceChange(MessageInputViewHeightKey.self) { newValue in | ||
messageInputHeight = newValue | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
/// - Parameters: | ||
/// - chat: The chat that should be displayed. | ||
/// - disableInput: Flag if the input view should be disabled. | ||
/// - messagePlaceholder: Placeholder text that should be added in the input field. | ||
public init( | ||
_ chat: Binding<Chat>, | ||
disableInput: Binding<Bool> = .constant(false), | ||
messagePlaceholder: String? = nil | ||
) { | ||
self._chat = chat | ||
self._disableInput = disableInput | ||
self.messagePlaceholder = messagePlaceholder | ||
} | ||
} | ||
|
||
|
||
#Preview { | ||
ChatView(.constant( | ||
[ | ||
ChatEntity(role: .system, content: "System Message!"), | ||
ChatEntity(role: .system, content: "System Message (hidden)!"), | ||
ChatEntity(role: .user, content: "User Message!"), | ||
ChatEntity(role: .assistant, content: "Assistant Message!"), | ||
ChatEntity(role: .function, content: "Function Message!") | ||
] | ||
)) | ||
} |
Oops, something went wrong.