ryanlintott / frameup Goto Github PK
View Code? Open in Web Editor NEWReframing SwiftUI Views. A collection of tools to help with layout.
License: MIT License
Reframing SwiftUI Views. A collection of tools to help with layout.
License: MIT License
Hi,
I have closed my other issue to do with performance and would like your assistance please to let me know if FrameUp is already supporting justifying blocks of text for languages that are right to left.
I usually place the following 2 lines and it works but it didn't with the HFlow Layout.
Text(languageText)
.multilineTextAlignment(.trailing)
.frame(maxWidth: .infinity, alignment: .trailing)
@ViewBuilder
func justifiedItem(_ item: TextItem) -> some View {
if let text = viewModel.getText(item) {
let words = Array(text.string.split(separator: " ").map(String.init).enumerated())
LazyVStack(spacing: 0) {
HFlowLayout(alignment: .justified) {
ForEach(words, id: \.offset) { word in
Text(word.element)
.multilineTextAlignment(.trailing)
.frame(maxWidth: .infinity, alignment: .trailing)
}
}
}
}
}
I am happy to modify FrameUp myself if you guide me as to what can be done. I am hoping its simple enough to do. Thank you.
Hi Ryan,
FrameUp is an amazing project. once again thank you for sharing.
I am wondering in additonal to my previous issue regarding right to left language support.
Is it also possible to implement an option for HFlow Layout so that when a word is too long for a row, it would break the word onto 2 lines with the extra characters of the word on the second line?
In my scenario I am displaying like 3 columns of justified text each column has one kind of a language, the frame width for each column is not that wide so sometimes the word is too long in its row and to display it correctly I would like to break it up on to 2 lines.
Hoping for a response whenever you are free on the 2 issues please. I pormise I won't have any more :].
Thank you.
Wael
Hi Ryan :),
A few days ago I was excited when I find out about FrameUp, its exactly what I was looking for, however because of a specific SwiftUI bug with LazyVStack and a ScrollView it has prevented me from properly using FrameUp because of performance issues (not directly related to FrameUp).
I am hoping you will have some time to take a look please at my question on stackoverflow and see if you can help me with the appropriate solution for implementing simple Text justification for 100's of text blocks that are loaded dynamically.
I think implementing the text justification manually as described in my question on stackoverflow is the best approach from a performance perspective espcially when I need to have 100's of small Text views to be loading text dynamically. You'll understand what I mean when you have read my question here as to why I came to that conclusion -
Thank you,
Wael
Hi Ryan :)
Thank you for all of your respones. This is my last challange that I am currently working on. I am a bit confused about how to solve.
The getText function returns an AttributedString. In the sentense I am passing it has some couple of words that are in a different language so its using its own font with a different color. In a normal SwiftUI Text view my AttributedString appears correctly.
I understand why the attributes get lost as I am converting the attributed string back to a string to extract the words but how can I maintain the attributes for every word? Thanks.
I think its probablly this line it needs to return an AttributedString !
let words = Array(text.string.split(separator: " ").map(String.init).enumerated())
extension AttributedString {
var string: String {
String(self.characters)
}
}
@ViewBuilder
func justifiedItem(_ item: TextItem, _ language: LanguageType) -> some View {
if let text = viewModel.getText(item, language) {
let words = Array(text.string.split(separator: " ").map(String.init).enumerated())
HFlowLayout(alignment: .justified) {
ForEach(words, id: \.offset) { word in
Text(word.element)
.foregroundColor(viewModel.color(item))
.font(Font(viewModel.font(item, language)))
}
}
}
}
Looks like some of this should work on max but readme says iOS only
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.