SwiftUI - text gets truncated after embedded on a ScrollView - swiftui

When added a long text inside a text view, it works as expected (not truncated).
Xcode 11.0 beta 6 (11M392q)
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
.lineLimit(nil)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
But when embedded inside a ScrollView, it gets truncated (not expected):
import SwiftUI
struct ContentView: View {
var body: some View {
ScrollView {
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
.lineLimit(nil)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
I tried setting a .lineLimit(nil) modifier, but also didn't avoid truncating the text.
Is this the expected behaviour for SwiftUI text? Or is it a bug?
Appreciate if someone can help! : )
Cheers

Text("Your long text goes here")
.fixedSize(horizontal: false, vertical: true)
should solve the problem.
This is default in iOS 13.1 beta 1 and above.

A solution for this problem (seems to be a bug with SwiftUI Xcode Beta 6), is to use the modifier bellow:
.frame(idealHeight: .greatestFiniteMagnitude)

Related

2 regex work correctly independently but they don't when combined

I would like to split up a string based on punctuation, while keeping the punctuation, and also if a string is wrapped in curly braces delete the curly braces but not the word.
My current regex works ALMOST perfectly. It does not capture a punctuation if it is the last character in a string. Thank you for your help
// const re = /([.!\"'/$:\d]+)/g;
// const re = /{(.*?)}/g
const re = /([.!\"'/$:\d]+)| {(.*?)}/g
const delimiter= new RegExp(re);
const sentences = sentence.split(delimiter);
sentences = sentences.filter(Boolean);
console.log(sentences)
Input:
const sentence = `Lorem ipsum {dolor sit} amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et {dolore magna aliqua}. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat! Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum?`
Actual Output:
[
'Lorem ipsum',
'dolor sit',
' amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et',
'dolore magna aliqua',
'.',
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat',
'!',
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
'.',
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum?'
]
Desired Output:
[
'Lorem ipsum',
'dolor sit',
' amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et',
'dolore magna aliqua',
'.',
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat',
'!',
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
'.',
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum',
'?'
]
You may use
/\s*{([^{}]*)}|([`!##$%^&*()_+=[\]{};':"\\|.<>\/?~-])/
Or - a bit more compact:
/\s*{([^{}]*)}|(?!,)([!-\/:-#[-`{-~])/
Both [`!##$%^&*()_+=[\]{};':"\\|.<>\/?~-] and (?!,)([!-\/:-#[-`{-~]) patterns match all ASCII punctuations and symbols other than ,. The main difference is the \s* part: your space before {{ was an obligatory pattern, with *, \s* matches zero or more occurrences of whitespace chars.
JS demo:
var sentence = "Lorem ipsum {dolor sit} amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et {dolore magna aliqua}. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat! Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum?";
var delimiter = /\s*{([^{}]*)}|([`!##$%^&*()_+=[\]{};':"\\|.<>\/?~-])/;
var sentences = sentence.split(delimiter).filter(Boolean);
console.log(sentences);

RegEx to extract text and number in outlook vba

I Have outgoing emails which go like:
Dear XYZ,
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
CASE ID: 123654
Best Regards,
XYZ
The text could be one or two paragraphs. I want to make two regex. One should give me the text in paragraphs and the other should give me the number that is the CASE ID. The result should look like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
123654
I have managed to create a RegEx to get the case using (CASE ID\s*[:]+\s*(\w*)\s*)but I haven't been able to extract the paragraph. Any help will be much appreciated.
Basically you can or should do one regex instead, that will deliver matchgroups.
In almost any other language it would look like this (using "gs" flag to ignore newline):
(.+?)CASE ID: (\d+)
But for vbscript it we have something like this:
(.*?[^\$]*)CASE ID: (\d+)
Also you need to deal with matchgroups like this:
Dim RegEx : Set RegEx = New RegExp
RegEx.Pattern = "(.*?[^\$]*)CASE ID: (\d+)"
RegEx.Global = True
RegEx.MultiLine = True
Dim strTemp : strTemp = "Lorem ipsum " & VbCrLf & "Cannot be translated to english " & VbCrLf & "CASE ID: 153"
WScript.Echo RegEx.Execute(strTemp)(0).SubMatches(0)
WScript.Echo RegEx.Execute(strTemp)(0).SubMatches(1)
The thing is that this will only work if the constant string "CASE ID: " is contained in the message. In case the string is missing e.g. the newline after the ":" it would not work

Sending an action to containing component

If I have two components:
nav-menu
nav-button
and nav-menu is a block component that would contain nav-button like so:
{{#nav-menu}}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
{{nav-button}}
{{/nav-menu}}
I'd like the button to be able to directly send an action to the menu to tell it to toggle it's visibility state. I guess if I hook into a mutux point in Controller then I could do something like:
{{#nav-menu toggleNavigation=mutex}}
{{nav-button action=mutex}}
{{/nav-menu}}
Is this the only way? Just looking for the most graceful, ember-centric way of doing this.
I've run into this issue before and unfortunately, there's no way in the public API to do this. When creating a block component, anything rendered inside of it has the context of the outer scope, not the component. It's unfortunate that there's no way to change this behavior, but it really does make sense.
I would say that the way you've proposed is the best way to handle this situation: have a variable on the controller that's passed to the outer component. It's inline with Ember's "data down, actions up" philosophy.

Regular expression to find R code in Sweave expression

I have some sweave expressions contained among text in some .Rnw files. The paragraph below contains two sweave expressions. What regular expression can I use to find the R code in each expression. So the regular expression should be able to find mean(mtcars$mpg) and/or summary(lm(mpg ~ hp + drat, mtcars))
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \Sexpr{mean(mtcars$mpg)}. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat \Sexpr{summary(lm(mpg ~ hp + drat, mtcars))} non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
The regex would be (?<=\\Sexpr{).+?(?=})
(?<=\\Sexpr{) part is positive lookbehind
(?=}) is positive lookahead
.+? will match everything between above two lookarounds lazily.
Readup more here. http://www.regular-expressions.info/lookaround.html
E.g. in R (since you tagged R)
txt <- 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \\Sexpr{mean(mtcars$mpg)}. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat \\Sexpr{summary(lm(mpg ~ hp + drat, mtcars))} non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
regmatches(txt, gregexpr('(?<=\\Sexpr{).+?(?=})', txt, perl=T))
## [[1]]
## [1] "mean(mtcars$mpg)" "summary(lm(mpg ~ hp + drat, mtcars))"

LWUIT textarea scroll issue

I have problem with LWUIT scroll.
I have a form contain textarea and 20 labels. When it scroll to the bottom, it jump to the top (like cycle). Sorry for my bad english :(
This is my code
public class ScrollMidlet extends MIDlet {
public void startApp() {
Display.init(this);
Form mainForm = new Form("Scroll issue");
mainForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
TextArea textArea = new TextArea("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum");
mainForm.addComponent(textArea);
for (int i = 0; i < 20; i++) {
mainForm.addComponent(new Label("This is label " + (i + 1)));
}
mainForm.setScrollable(true);
mainForm.show();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
You need to disable cyclic focus using the setCyclicFocus method.
mainForm.setCyclicFocus(false);
EDIT: LWUIT scrolling works based on the focus of the current component. So when you press the down arrow, the focus changes to the element below and, if necessary, the Form scrolls. Labels are not focusable by default, so they won't receive focus and the scrolling will not work correctly. To correct this you should modify the label creation.
Label l = new Label("This is label " + (i + 1));
l.setFocusable(true);
mainForm.addComponent(l);
Also, it is really bad user experience to scroll horizontally to read content, so you should forbid horizontal scrolling.
mainForm.setScrollableX(false);
mainForm.setScrollableY(true);
Now setCyclicFocus should work without problems.