Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TNS 3.0] Android: Formatted string does not work if defined in XML #4109

Closed
PeterStaev opened this issue May 4, 2017 · 6 comments
Closed

Comments

@PeterStaev
Copy link
Contributor

PeterStaev commented May 4, 2017

I have the following defined in XML that was working with 2.5:

<Button class="btn">   
    <Button.formattedText>
        <FormattedString>
            <FormattedString.spans>
                <Span text=" Login"></Span>
            </FormattedString.spans>
        </FormattedString>
    </Button.formattedText>
</Button>  

This throws the following error:

An uncaught Exception occurred on "main" thread.
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Typeface.getStyle()' on a null object reference
at org.nativescript.widgets.CustomTypefaceSpan.applyCustomTypeFace(CustomTypefaceSpan.java:35)
at org.nativescript.widgets.CustomTypefaceSpan.updateDrawState(CustomTypefaceSpan.java:23)
at android.text.TextLine.handleRun(TextLine.java:932)
at android.text.TextLine.measureRun(TextLine.java:417)
at android.text.TextLine.measure(TextLine.java:296)
at android.text.TextLine.metrics(TextLine.java:270)
at android.text.BoringLayout.isBoring(BoringLayout.java:311)
at android.widget.TextView.makeSingleLayout(TextView.java:6715)
at android.widget.TextView.makeNewLayout(TextView.java:6610)
at android.widget.TextView.onMeasure(TextView.java:6961)
at android.view.View.measure(View.java:18788)
at org.nativescript.widgets.CommonLayoutParams.measureChild(CommonLayoutParams.java:262)
at org.nativescript.widgets.StackLayout.onMeasure(StackLayout.java:83)
at android.view.View.measure(View.java:18788)
at org.nativescript.widgets.CommonLayoutParams.measureChild(CommonLayoutParams.java:262)
at org.nativescript.widgets.StackLayout.onMeasure(StackLayout.java:83)
at android.view.View.measure(View.java:18788)
at org.nativescript.widgets.CommonLayoutParams.measureChild(CommonLayoutParams.java:262)
at org.nativescript.widgets.MeasureHelper.measureChildFixedColumnsAndRows(GridLayout.java:1059)
at org.nativescript.widgets.MeasureHelper.measure(GridLayout.java:869)
at org.nativescript.widgets.GridLayout.onMeasure(GridLayout.java:279)
at android.view.View.measure(View.java:18788)
at org.nativescript.widgets.CommonLayoutParams.measureChild(CommonLayoutParams.java:262)
at org.nativescript.widgets.ContentLayout.onMeasure(ContentLayout.java:32)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
at android.view.View.measure(View.java:18788)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Also tried the short format - directly having FormattedString inside the button and then directly Span inside it. Also the same problem happens with Label. Before testing I have uninstalled the app from device and nuked node_modules and platforms.

EDIT
Seems related to the btn class from the nativescript theme. If that is removed the exception does not happen.

@tsonevn
Copy link
Contributor

tsonevn commented May 4, 2017

Hi @PeterStaev,
Thank you for reporting this issue.
I tested the above-given code snippet in a newly created project, however, everything seems to work as expected, while setting FormattedString via XML.
For your convenience, I am attaching sample project, where you could make the needed changes, which will allow us to reproduce the problem.
Archive.zip

It would also help if you could provide some info, is this issue appears on a newly created project or on the old one.

@PeterStaev
Copy link
Contributor Author

@tsonevn , after further testing, seems related to the btn class. As soon as you add this to your sample you should receive the above error. I have adjusted the original post.

@vakrilov vakrilov added the bug label May 4, 2017
@vakrilov
Copy link
Contributor

vakrilov commented May 4, 2017

I managed to reproduce the exception once I've added class="btn".

@vakrilov vakrilov added this to the 3.1 TBD milestone May 4, 2017
@tsonevn tsonevn added backlog and removed question labels May 9, 2017
@vakrilov vakrilov self-assigned this May 9, 2017
@vakrilov vakrilov added ready for test TSC needs to test this and confirm against live production apps and automated test suites and removed in progress labels May 11, 2017
@vakrilov vakrilov assigned vakrilov and unassigned vakrilov May 11, 2017
@SvetoslavTsenov SvetoslavTsenov added done and removed ready for test TSC needs to test this and confirm against live production apps and automated test suites labels May 12, 2017
@SvetoslavTsenov
Copy link
Contributor

The fix is available in 'next' version of tns-core-modules.

@dtopuzov
Copy link
Contributor

Fix will be released in 3.0.1 later this week.

@dtopuzov dtopuzov modified the milestones: 3.0.1, 3.1 May 22, 2017
@lock
Copy link

lock bot commented Aug 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Aug 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants