LoadingButtonAndroid icon indicating copy to clipboard operation
LoadingButtonAndroid copied to clipboard

Issue when calling setProgress

Open jdejesus11 opened this issue 6 years ago • 9 comments

btn = (CircularProgressButton) findViewById(R.id.btn_id);

    btn.setProgress(5);

    btn.startAnimation();

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.juandejesus.favoritetoys, PID: 494 kotlin.UninitializedPropertyAccessException: lateinit property initialState has not been initialized at br.com.simplepass.loadingbutton.customViews.CircularProgressButton.access$getInitialState$p(CircularProgressButton.kt:19) at br.com.simplepass.loadingbutton.customViews.CircularProgressButton$morphAnimator$2.invoke(CircularProgressButton.kt:64) at br.com.simplepass.loadingbutton.customViews.CircularProgressButton$morphAnimator$2.invoke(CircularProgressButton.kt:19) at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) at br.com.simplepass.loadingbutton.customViews.CircularProgressButton.getMorphAnimator(Unknown Source:7) at br.com.simplepass.loadingbutton.customViews.CircularProgressButton.startMorphAnimation(CircularProgressButton.kt:125) at br.com.simplepass.loadingbutton.presentation.ProgressButtonPresenter.onDraw(ProgressButtonPresenter.kt:63) at br.com.simplepass.loadingbutton.customViews.CircularProgressButton.onDraw(CircularProgressButton.kt:166) at android.view.View.draw(View.java:19123) at android.view.View.updateDisplayListIfDirty(View.java:18073) at android.view.View.draw(View.java:18851) at android.view.ViewGroup.drawChild(ViewGroup.java:4214) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000) at android.support.constraint.ConstraintLayout.dispatchDraw(ConstraintLayout.java:2023) at android.view.View.draw(View.java:19126) at android.view.View.updateDisplayListIfDirty(View.java:18073) at android.view.View.draw(View.java:18851) at android.view.ViewGroup.drawChild(ViewGroup.java:4214) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000) at android.view.View.updateDisplayListIfDirty(View.java:18064) at android.view.View.draw(View.java:18851) at android.view.ViewGroup.drawChild(ViewGroup.java:4214) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000) at android.view.View.updateDisplayListIfDirty(View.java:18064) at android.view.View.draw(View.java:18851) at android.view.ViewGroup.drawChild(ViewGroup.java:4214) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000) at android.view.View.draw(View.java:19126) at com.android.internal.policy.DecorView.draw(DecorView.java:785) at android.view.View.updateDisplayListIfDirty(View.java:18073) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:643) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:649) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:757) at android.view.ViewRootImpl.draw(ViewRootImpl.java:2980) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2794) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2347) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911) at android.view.Choreographer.doCallbacks(Choreographer.java:723) at android.view.Choreographer.doFrame(Choreographer.java:658) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Application terminated.

jdejesus11 avatar Jan 23 '19 14:01 jdejesus11

btn.setProgress(5); is not supposed to be called before startAnimation. Call it after. Like this:

btn.startAnimation();
btn.setProgress(5);

leandroBorgesFerreira avatar Jan 23 '19 17:01 leandroBorgesFerreira

Anyway, I will improve the error message

leandroBorgesFerreira avatar Jan 23 '19 17:01 leandroBorgesFerreira

Just as an FYI, we see this crash in Fabric coming in from TrendMicro (https://mars.trendmicro.com/). Nothing that affects real users atm, but it could be worth looking into.

Qw4z1 avatar Jan 29 '19 07:01 Qw4z1

I can now reproduce this crash consistently in our app. Still not sure what is going on, but my gut tells me that it has something to do with how we use it in a fragment. Clicking on it opens the BankID app (Swedish authentication app) with a startActivityForResult and when backing out of the BankID app (i.e. returning) to our app the crash happens. I'll try to see if I can put together a sample demonstrating this issue by the end of the week.

Qw4z1 avatar Jan 30 '19 10:01 Qw4z1

@Qw4z1, if you reproduce the error, we can work on the solution. I'll try to see if it breaks with a startActivityForResult interaction

leandroBorgesFerreira avatar Feb 01 '19 01:02 leandroBorgesFerreira

@leandroBorgesFerreira I've managed to track down the crash now. It happens when we set the button to animate too early in the lifecycle. What we really want to do is to set it to it's loading state directly.

It's easy enough to reproduce if you add this to MainActivity in the sample app included in this repo.

override fun onResume() { super.onResume() buttonTest1.startAnimation() }

Simple workaround seems to be to call saveInitialState() before starting the animation, but this seems a bit unintuitive.

Qw4z1 avatar Feb 01 '19 15:02 Qw4z1

@Qw4z1 This is not supposed to happen as the button handles this use case. Anyway, I will test and fix it. Right now I am in the middle of a travel and I don't have a computer with me... So it may take a few days.

leandroBorgesFerreira avatar Feb 05 '19 14:02 leandroBorgesFerreira

@leandroBorgesFerreira Appreciate it. =) Thanks for getting back to be even though you're traveling =)

Qw4z1 avatar Feb 07 '19 08:02 Qw4z1

Also seeing this -- would love to see if a fix can be applied, thanks!

tomafc330 avatar Feb 16 '19 08:02 tomafc330