Repository navigation
Format expression Android bindings - #12985
Conversation
|
Solution to above issues will require introducing a |
5712099 to
80014cb
Compare
928056e to
3d9515b
Compare
0fc0825 to
0b1466e
Compare
a267ad1 to
56e58b9
Compare
|
This PR introduces Expression fields returned by Follow up work needed after this PR lands is exposing |
| * Text is required to be a string literal, font-scale a number literal and text-font an array literal that holds | ||
| * names of main and backup fonts. | ||
| * All of them are required to be passed, but font-scale and text-font can be nullified | ||
| * and will default to 1.0 and an empty array respectively. |
There was a problem hiding this comment.
"default to 1.0 and an empty array respectively."
Instead of describing the defaults in implementation terms here, I think it would be better to describe the conceptual effect, which is that if "font-scale" or "text-font" are not set, the section will use the base "text-size" or "text-font (respectively) defined for the symbol.
| * and accepts unlimited numbers of formatted sections. | ||
| * <p> | ||
| * Each sections consist of 3 elements, in this order: text, font-scale and text-font. | ||
| * Text is required to be a string literal, font-scale a number literal and text-font an array literal that holds |
There was a problem hiding this comment.
"text-font" is required to be an array literal. "text" only requires an expression that returns a string and "font-scale" requires an expression that returns a number.
| * "format" expressions can be used, for example, with the {@link PropertyFactory#textField(Expression)} | ||
| * and accepts unlimited numbers of formatted sections. | ||
| * <p> | ||
| * Each sections consist of 3 elements, in this order: text, font-scale and text-font. |
There was a problem hiding this comment.
How hard would it be to make the Java interface conform to the underlying expression format of using an array of text/option pairs? The problem with expanding the current "options" argument into two separate arguments here is that it will break backwards compatibility when/if we add support for further options (there are several that could conceivably be added, the immediate one we have a request for is to add "text-color" as a format option).
There was a problem hiding this comment.
Thanks for the heads up! I'll try to future-proof the builder.
| : (Expression) value; | ||
| } else { | ||
| Logger.w(TAG, "not a expression, try value"); | ||
| Logger.w(TAG, "not an expression, try value"); |
There was a problem hiding this comment.
Took me a moment to understand "try value"/"try expression" -- would it read easier to say "try getValue()"/"getExpression()"?
| }); | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
nit: This makes the diff bigger than it needs to be.
| auto section = value.sections.at(i); | ||
| auto text = jni::Make<jni::String>(env, section.text); | ||
|
|
||
| auto fontScale = 1.0; |
There was a problem hiding this comment.
nit: auto here is hard to read (although not technically ambiguous obviously since the compiler can figure it out). I would prefer explicitly declaring the type as double. There's a rule of thumb that you should restrict using auto to cases where the type is visible on the same line -- we definitely don't live up to that rule, but it's good to keep in the back of your mind! Basically, auto is good when it saves lots of repetitive typing, but it's bad when it prevents you from having to think about what type you're working with.
| fontScale = section.fontScale.value(); | ||
| } | ||
|
|
||
| auto fontStack = jni::Array<jni::String>::New(env, 0); |
There was a problem hiding this comment.
When I saw FormattedSection::getFontStack() above and saw that it was nullable, I assumed that "null" was being used to represent "not set". But it looks here (and now I notice in the tests) that text-font: null will cause getFontStack() to return new String[] {}. That doesn't seem right -- an empty array would signify "use this FontStack that doesn't have any fonts in it" instead of "use the default font stack".
There was a problem hiding this comment.
Good point, I'm going to return null instead of an empty array for un-set stack.
| } | ||
| }; | ||
| Object[] actual = format( | ||
| literal("test"), null, literal("awesome"), |
There was a problem hiding this comment.
"awesome" should be new String[]{"awesome"}
same applies for other occurrences of font-stack in the unit tests
|
Thanks for running with this @LukasPaczos and @ChrisLoer for the thorough review and great insights! Took the code for a spin and seems to be working well: Above is the a the expression copied from the unit test with some valid fonts (+ putting them in an array) An idea to improve the ease of use of this API we could expose format specific expression: This makes it slightly easier to integrate and would remove the necessity of adding null values such an improvement can be done as tail work. I'm 👍 on this PR, will leave it to @ChrisLoer for the actual 👍. |
b032b38 to
fc71883
Compare
a4ac85b to
5ed3c05
Compare
For converting to Java types, flatten 'text-field' back to a string.
659afbb to
923dfa7
Compare
|
This one is ready for another round @tobrun @ChrisLoer. I addressed the comments and opted for a more typed builder with |
|
923dfa7 also updates the local style that we are using for testing which was causing issues when setting a |
923dfa7 to
edcca60
Compare
|
8395a5c renames format options to avoid a clash with |
| * formatFontScale(2.0), | ||
| * formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"}) | ||
| * ), | ||
| * formatEntry(concat(literal("\n"), get("description_property")), formatFontScale(1.5)), |
There was a problem hiding this comment.
This code example looks like it abruptly ends after formatFontScale(1.5)),, is that intentional?
| return position.Get(env, field); | ||
| } | ||
|
|
||
| } // namespace andr[oid |
6607d5b to
219c370
Compare
219c370 to
4b0d51e
Compare


Refs #12624, exposes
formatexpression on Android.Setting the
text-fieldusing the expression, or plain text, works as expected, however, getting thetext-fieldproperty back from core reveals a couple of issues:format, is returned wrapped byformatexpression. This includes tokens (which are beforehand converted from plain text to expressions and this is expected).formatexpression, it's being returned asString, which is expected because of this implementation.Currently, above issues cause a bunch of tests to fail.
/cc @ChrisLoer