๐ Hello! I am an iOS developer
๐ ๏ธ I use Swift (SwiftUI) to develop iOS apps
๐จ I also like to design
ChatGenie | PayMap | Trendy | Fonty | MusicSpace |
FontSnap | ChatMe | Real Probability | Salary | DropUI(Swift Student Challenge) |
Easily show RichText(html) in SwiftUI
License: MIT License
๐ Hello! I am an iOS developer
๐ ๏ธ I use Swift (SwiftUI) to develop iOS apps
๐จ I also like to design
ChatGenie | PayMap | Trendy | Fonty | MusicSpace |
FontSnap | ChatMe | Real Probability | Salary | DropUI(Swift Student Challenge) |
Hi, very helpful lib that you have made!
Is it possible to add custom CSS?
How do I add a customizable font size?
I'm trying to get a custom font rendering in my webview.
I feel like I'm doing all the right steps but I'm unable to see a font change.
I tried using the FontType.custom with a name and a UIFont. The UIFont was definitely not nil and was the correct font I wanted passed in. Should using this modifier be the only thing I need? I also tried using custom CSS to change the font. Nothing worked though.
Does someone have an example using a custom font just so I could compare.
For more project context I added this library as a local package because of needing a few small changes to styling. The custom fonts are added to the main target of the project. Do they need to be added as resources to local package?
Thanks for the library - it's very nice
When I try to set a custom font that I imported into my project it doesn't work
.fontType(.custom(UIFont(name: "NunitoSans-Regular", size: 14.0)))
Could be my inexperience, but I was hoping to use this new feature in the following way:
.linkOpenType(.custom({ url in
print(url)
}))
but I'm getting the following messages in the Output window after clinking the link:
0x16e1300c0 - [PID=77634] WebProcessProxy::checkURLReceivedFromWebProcess: Received an unexpected URL from the web process
0x1060a9018 - [pageProxyID=14, webPageID=15, PID=77634] WebPageProxy::Ignoring request to load this main resource because it is outside the sandbox
If I click a traditional-looking link like:
<a href="https://api.site.com/gary-busey/4005-15789/\" data-ref-id="4005-15789">Gary Busey
My code will print the URL as expected.
Am I totally off base, trying to use the new feature in this way? If so, what's the intended use of this feature?
Thanks
Maury
Frame is set to 48 tall.
Message body:
<p>This is a <strong>fancy</strong> <strong><span style=\"color: rgb(226, 80, 65);\">HTML</span></strong> <span style=\"background-color: rgb(97, 189, 109);\">message</span> with some styling.</p><p>And a <a href=\"http://www.google.com\" target=\"_blank\">link to google</a>.</p>
Right now I cannot add your package using SPM by specifying a version. The tagged versions should be something like 1.6.0
and not 1.6
.
Thanks!
While it renders
. it is offset from the rest of the text.Here is the example HTML text:
<figure data-align=\"center\" data-size=\"large\" data-img-src=\"https://www.gamespot.com/a/uploads/original/1596/15969599/4052233-steamskins2.png\" data-ref-id=\"1300-4052233\" data-ratio=\"0.33333333333333\" data-width=\"900\" data-embed-type=\"image\" style=\"width: 900px\"><a class=\"fluid-height\" style=\"padding-bottom:33.3%\" href=\"https://www.gamespot.com/a/uploads/original/1596/15969599/4052233-steamskins2.png\" data-ref-id=\"1300-4052233\"><img alt=\"The days of easily modding your Steam to look the way you want are, sadly, over.\" src=\"https://www.gamespot.com/a/uploads/original/1596/15969599/4052233-steamskins2.png\" srcset=\"https://www.gamespot.com/a/uploads/original/1596/15969599/4052233-steamskins2.png 900w, https://www.gamespot.com/a/uploads/scale_medium/1596/15969599/4052233-steamskins2.png 480w\" sizes=\"(max-width: 900px) 100vw, 900px\" data-width=\"900\"></a><figcaption>The days of easily modding your Steam to look the way you want are, sadly, over.</figcaption></figure>
Here is what is rendered in SwiftUI
Can you advise if there is anything I can do to resolve this or if it is a known bug?
that html sample will render white bg and no options to ignore it. doesn't look well on dark mode
<p style=\"text-align: justify;background: white;\"><strong><span style=\"font-size:17px;\"> </span></strong></p>
Hi, im using the pod, but i have problems when i want to use horizontal scroll and overflows not work when create the css style.
i already support this?
seems like a very capable library, but can unfortunately not be used for a macOS SwiftUI application due to the lack of UIKit availability.
RichText works fine in light mode - but I don't see anything in dark mode. Just a blank black screen.
RichText(html: myHtml)
.placeholder {
Text("Loading myHtml")
}
Hi, I have the following text:
USDC is a fully collateralized US dollar stablecoin. USDC is the bridge between dollars and trading on cryptocurrency exchanges. The technology behind CENTRE makes it possible to exchange value between people, businesses and financial institutions just like email between mail services and texts between SMS providers. We believe by removing artificial economic borders, we can create a more inclusive global economy.
and it's not showing up:
If I don't set the .linkColor
, the link color uses the RichText default light blue color. But when I try to set my custom color, it does not change to the desired color and fallbacks to the dark blue link color.
RichText(html: htmlString)
.linkColor(light: Color.white, dark: Color.white)
I am not sure if is related but I am testing this on the latest Xcode 14 beta 5.
You should rename the .transition
modifier to .animation
and introduce a new .transition
modifier that is responsible for transitioning from the placeholder to the WebView.
Hi does this support CSS click events? Like can I use a click event to reveal some text? Thanks!
I tried one but it didnt work when I tapped on it.
Considering this situation:
struct MyHtmlView: View {
let longHTML: String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est est, mattis vel ante sit amet, porttitor interdum dui. Nunc cursus lobortis ex, ut faucibus felis malesuada id. Vivamus in risus nec dolor ullamcorper tincidunt in at velit. Vestibulum nec mollis ipsum. Phasellus volutpat augue odio, ultricies accumsan magna eleifend tristique. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque efficitur sem non dui ultricies sollicitudin eu eu sapien."
let shortHTML: String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est est, mattis vel ante sit amet, porttitor interdum dui. Nunc cursus lobortis ex, ut faucibus felis malesuada id."
@State private var isExpanded: Bool = false
var body: some View {
VStack {
RichText(html: isExpanded ? longHTML : shortHTML)
.lineHeight(120)
.colorScheme(.auto)
.transition(.easeOut)
.background(Color.red)
Button {
isExpanded.toggle()
} label: {
Text("Show more/less")
}
}
}
}
When the HTML changes from a long description to a short one the RichText
frame's height remains equal to the bigger one calculated from the long description's height leaving a blank space underneath the RichText
view
Need:
Possible Solution:
I really like this package but I've run into an issue. I've got this code:
import SwiftUI
import RichText
struct MainView : View {
var body: some View { ScrollView { RichText(html: Documents.Welcome) }
}
and when it runs I get a bunch of warnings: [ViewportSizing] maximumViewportInset cannot be larger than frame (similarly for minimumViewportInset). Documents.Welcome is quite large but the warnings didn't seem to be a problem.
But today I added a "details" section:
There's a lot of text here.
Hello and thank you for sharing this! It appears to be working really well for the initial render, but from your example in the readme, changes to the @State var html won't be reflected by the webview. It seems like this function updateUIView would need to get implemented yea? I took a quick pass at this, so lmk if this seems reasonable and ill make a PR:
public func updateUIView(_ uiView: WKWebView, context: Context) {
let htmlStart = """
<HTML>
<head>
<meta name='viewport' content='width=device-width, shrink-to-fit=YES, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'>
</head>
"""
let htmlEnd = "</BODY></HTML>"
let htmlString = "\(htmlStart)\(css(colorScheme: self.colorScheme))\(html)\(htmlEnd)"
uiView.loadHTMLString(htmlString, baseURL: nil)
}
I guess we might want to factor that bit out of makeUIView and updateUIView
Hi, when I add new font using fontType modifier nothing changes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.