leandroBorgesFerreira / LoadingButtonAndroid

A button to substitute the ProgressDialog
MIT License
1.94k stars 214 forks source link

Issue when calling setProgress #111

Open jdejesus11 opened 5 years ago

jdejesus11 commented 5 years ago

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.

leandroBorgesFerreira commented 5 years ago

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

btn.startAnimation();
btn.setProgress(5);
leandroBorgesFerreira commented 5 years ago

Anyway, I will improve the error message

Qw4z1 commented 5 years ago

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 commented 5 years ago

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.

leandroBorgesFerreira commented 5 years ago

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

Qw4z1 commented 5 years ago

@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.

leandroBorgesFerreira commented 5 years ago

@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.

Qw4z1 commented 5 years ago

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

tomafc330 commented 5 years ago

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