-
-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various fixes to share as image + copy text
- Loading branch information
Showing
7 changed files
with
156 additions
and
91 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
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
56 changes: 56 additions & 0 deletions
56
Packages/StatusKit/Sources/StatusKit/Share/StatusRowSelectableTextView.swift
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,56 @@ | ||
import SwiftUI | ||
import DesignSystem | ||
|
||
struct StatusRowSelectableTextView: View { | ||
@Environment(\.dismiss) private var dismiss | ||
@Environment(Theme.self) private var theme | ||
|
||
let content: AttributedString | ||
|
||
var body: some View { | ||
NavigationStack { | ||
SelectableText(content: content) | ||
.padding() | ||
.toolbar { | ||
ToolbarItem(placement: .navigationBarTrailing) { | ||
Button { | ||
dismiss() | ||
} label: { | ||
Text("action.done").bold() | ||
} | ||
} | ||
} | ||
.navigationTitle("status.action.select-text") | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
.presentationBackground(.ultraThinMaterial) | ||
.presentationCornerRadius(16) | ||
} | ||
} | ||
|
||
fileprivate struct SelectableText: UIViewRepresentable { | ||
let content: AttributedString | ||
|
||
func makeUIView(context _: Context) -> UITextView { | ||
let attributedText = NSMutableAttributedString(content) | ||
attributedText.addAttribute( | ||
.font, | ||
value: Font.scaledBodyFont, | ||
range: NSRange(location: 0, length: content.characters.count) | ||
) | ||
|
||
let textView = UITextView() | ||
textView.translatesAutoresizingMaskIntoConstraints = false | ||
textView.isEditable = false | ||
textView.isScrollEnabled = true | ||
textView.attributedText = attributedText | ||
textView.textColor = UIColor(Color.label) | ||
textView.select(textView) | ||
textView.selectedRange = .init(location: 0, length: attributedText.string.utf8.count) | ||
textView.backgroundColor = .clear | ||
return textView | ||
} | ||
|
||
func updateUIView(_: UITextView, context _: Context) {} | ||
func makeCoordinator() {} | ||
} |
56 changes: 56 additions & 0 deletions
56
Packages/StatusKit/Sources/StatusKit/Share/StatusRowShareAsImageView.swift
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,56 @@ | ||
import SwiftUI | ||
import Env | ||
import Network | ||
import DesignSystem | ||
|
||
struct StatusRowShareAsImageView: View { | ||
@Environment(\.dismiss) private var dismiss | ||
@Environment(Theme.self) private var theme | ||
|
||
let viewModel: StatusRowViewModel | ||
@StateObject var renderer: ImageRenderer<AnyView> | ||
|
||
var rendererImage: Image { | ||
Image(uiImage: renderer.uiImage ?? UIImage()) | ||
} | ||
|
||
var body: some View { | ||
NavigationStack { | ||
Form { | ||
Section { | ||
Button { | ||
viewModel.routerPath.presentedSheet = .shareImage(image: renderer.uiImage ?? UIImage(), | ||
status: viewModel.status) | ||
} label: { | ||
Label("status.action.share-image", systemImage: "square.and.arrow.up") | ||
} | ||
} | ||
#if !os(visionOS) | ||
.listRowBackground(theme.primaryBackgroundColor.opacity(0.4)) | ||
#endif | ||
|
||
Section { | ||
rendererImage | ||
.resizable() | ||
.scaledToFit() | ||
} | ||
.listRowBackground(theme.primaryBackgroundColor) | ||
} | ||
.scrollContentBackground(.hidden) | ||
.toolbar { | ||
ToolbarItem(placement: .navigationBarTrailing) { | ||
Button { | ||
dismiss() | ||
} label: { | ||
Text("action.done") | ||
.bold() | ||
} | ||
} | ||
} | ||
.navigationTitle("Share post as image") | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
.presentationBackground(.ultraThinMaterial) | ||
.presentationCornerRadius(16) | ||
} | ||
} |