leandroBorgesFerreira / LoadingButtonAndroid

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

Crash - lateinit property initialState has not been initialized #176

Closed DPalagi closed 3 years ago

DPalagi commented 3 years ago

Hello,

Thank you again for this awesome library !

Since I have updated to 2.2.0, I am having some issues on lifecycle events : my app crash in the onDestroy event of ExampleActivity when rotated.

Manually calling dispose method in onDestroy, as in previous version, has no effect...

Logcat :

java.lang.RuntimeException: Unable to destroy activity {ExampleActivity}: java.lang.RuntimeException: Failed to call observer method
...
Caused by: java.lang.RuntimeException: Failed to call observer method
...
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property initialState has not been initialized
        at br.com.simplepass.loadingbutton.customViews.CircularProgressButton.access$getInitialState$p(CircularProgressButton.kt:21)
        at br.com.simplepass.loadingbutton.customViews.CircularProgressButton$morphAnimator$2.invoke(CircularProgressButton.kt:70)
        at br.com.simplepass.loadingbutton.customViews.CircularProgressButton$morphAnimator$2.invoke(CircularProgressButton.kt:21)
        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.dispose(CircularProgressButton.kt:171)

The view setup is the following :

ExampleActivity contains a LoadingScreenView which contains a CircularProgressButton

The button is instantiated through the following XML :

<br.com.simplepass.loadingbutton.customViews.CircularProgressButton
            android:id="@+id/loading_button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="@string/retry_label"
            android:paddingStart="16dp"
            android:paddingEnd="16dp"
            android:theme="@style/blackButton"
            android:minHeight="56dp"
            app:spinning_bar_width="4dp"
            app:spinning_bar_color="#FFF"
            app:spinning_bar_padding="6dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@id/loading_image"
    />

Any idea how I could fix this ?

Thank you 😊

leandroBorgesFerreira commented 3 years ago

Let me check it at the weekend. Thanks for posting it!

DPalagi commented 3 years ago

Hey !

I have found a way to fix this for the time being :

While initializing my custom view, LoadingScreenView, all I have to do is call loadingButton.saveInitialState() to get rid of the error.

Hope this will help people working around this !