-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a85558e
commit 05f84eb
Showing
3 changed files
with
106 additions
and
26 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
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,57 @@ | ||
// | ||
// SelectTextSheet.swift | ||
// Enchanted | ||
// | ||
// Created by Augustinas Malinauskas on 01/05/2024. | ||
// | ||
|
||
#if os(iOS) | ||
import SwiftUI | ||
import UIKit | ||
|
||
struct SelectTextSheet: View { | ||
@Environment(\.presentationMode) var presentationMode | ||
@FocusState private var isTextEditorFocused: Bool | ||
|
||
var message: MessageSD | ||
var body: some View { | ||
VStack { | ||
ZStack { | ||
Text("Select Text") | ||
.font(.system(size: 16)) | ||
.fontWeight(.bold) | ||
|
||
HStack { | ||
Spacer() | ||
Button(action: {}) { | ||
Image(systemName: "x.circle.fill") | ||
.padding(7) | ||
} | ||
.buttonStyle(.plain) | ||
} | ||
.padding() | ||
} | ||
|
||
TextEditor(text: .constant(message.content)) | ||
.focusable() | ||
.focused($isTextEditorFocused) | ||
.onReceive(NotificationCenter.default.publisher(for: UITextField.textDidBeginEditingNotification)) { obj in | ||
if let textField = obj.object as? UITextView { | ||
textField.selectedTextRange = textField.textRange(from: textField.beginningOfDocument, to: textField.endOfDocument) | ||
} | ||
} | ||
|
||
} | ||
.textSelection(.enabled) | ||
.onAppear { | ||
isTextEditorFocused = true | ||
} | ||
|
||
} | ||
} | ||
|
||
#Preview { | ||
SelectTextSheet(message: MessageSD.sample[0]) | ||
} | ||
|
||
#endif |