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

v6.1 no longer works with CoordinatorLayout, must be a FrameLayout now #23

Closed
bwalsh0 opened this issue May 11, 2019 · 8 comments
Closed

Comments

@bwalsh0
Copy link

bwalsh0 commented May 11, 2019

Prior to v6.x, I was using a CoordinatorLayout as the view for the snackbar since I have a FAB that I would like to respond to a snackbar being shown. Upon updating, I've had to use FrameLayout to avoid a crash.

I've also tried to access snackProgressBarLayout.setViewsToMove$lib_release(View[]);, but it has no effect when getting the FAB view.

This is my error:
ClassCastException: androidx.coordinatorlayout.widget.CoordinatorLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams

Occurs here:

snackProgressBarManager = new SnackProgressBarManager(coordinatorLayout, this)

The error is fixed when I change the coordinatorLayout to a FrameLayout, but the FAB no longer moves along with it. I've tried making a CoordinatorLayout the parent of the FrameLayout, but the same error results. I've tried android:animateLayoutChanges="true", but I don't think that has any effect on a FrameLayout.

You've done a tremendous job with 6.0+, loving the new behavior to .updateTo and the public SnackProgressBarLayout, as well as Lifecycle management.

@bwalsh0
Copy link
Author

bwalsh0 commented May 11, 2019

I guess I overthought it, and I fixed it simply by using .setViewToMove(fab) while keeping the layout as a FrameLayout.

@bwalsh0 bwalsh0 closed this as completed May 11, 2019
@tingyik90
Copy link
Owner

tingyik90 commented May 11, 2019

Thanks for the feedback @bwalsh0. Using a coordinator layout should be the default choice and should move the fab by default. Can you tell me the exact line number of code that caused the crash in stack trace (or just post the stack trace here)? I'd keep this issue open until I test and confirm it works with coordinator layout.

@tingyik90 tingyik90 reopened this May 11, 2019
@bwalsh0
Copy link
Author

bwalsh0 commented May 11, 2019

Sure, it only happens right before the snackbar is about to be shown, but it gets past instantiating SnackBarProgressManager just fine. Stack seems to suggest it has to do with animations

So it must be something below:

SnackProgressBar progSnack = new SnackProgressBar(
      SnackProgressBar.TYPE_HORIZONTAL, progMsg)
      .setAllowUserInput(true)
      .setIsIndeterminate(false)
      .setProgressMax(100);

snackProgressBarManager.setProgress(10).show(progSnack, SnackProgressBarManager.LENGTH_INDEFINITE);

My layout.xml hierarchy is as follows:

- Parent/Root (LinearLayoutCompat)
----> Child 1 (Other CoordinatorLayout)
----> Child 2 (CoordinatorLayout for snackbar)

Here's the full trace, it's pretty long:

2019-05-10 20:33:53.937 29043-29043 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.bryanwalsh.appname, PID: 29043
    java.lang.ClassCastException: androidx.coordinatorlayout.widget.CoordinatorLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
        at com.tingyik90.snackprogressbar.SnackProgressBarLayout.animateContentIn(SnackProgressBarLayout.kt:280)
        at com.google.android.material.snackbar.BaseTransientBottomBar$12.onAnimationStart(BaseTransientBottomBar.java:779)
        at android.animation.Animator$AnimatorListener.onAnimationStart(Animator.java:536)
        at android.animation.ValueAnimator.notifyStartListeners(ValueAnimator.java:1013)
        at android.animation.ValueAnimator.startAnimation(ValueAnimator.java:1262)
        at android.animation.ValueAnimator.start(ValueAnimator.java:1064)
        at android.animation.ValueAnimator.start(ValueAnimator.java:1088)
        at com.google.android.material.snackbar.BaseTransientBottomBar.startSlideInAnimation(BaseTransientBottomBar.java:806)
        at com.google.android.material.snackbar.BaseTransientBottomBar.animateViewIn(BaseTransientBottomBar.java:693)
        at com.google.android.material.snackbar.BaseTransientBottomBar$7.onLayoutChange(BaseTransientBottomBar.java:663)
        at com.google.android.material.snackbar.BaseTransientBottomBar$SnackbarBaseLayout.onLayout(BaseTransientBottomBar.java:958)
        at android.view.View.layout(View.java:20696)
        at android.view.ViewGroup.layout(ViewGroup.java:6193)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1193)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:880)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:899)
        at android.view.View.layout(View.java:20696)
        at android.view.ViewGroup.layout(ViewGroup.java:6193)
        at androidx.appcompat.widget.LinearLayoutCompat.setChildFrame(LinearLayoutCompat.java:1649)
        at androidx.appcompat.widget.LinearLayoutCompat.layoutVertical(LinearLayoutCompat.java:1503)
        at androidx.appcompat.widget.LinearLayoutCompat.onLayout(LinearLayoutCompat.java:1411)
        at android.view.View.layout(View.java:20696)
        at android.view.ViewGroup.layout(ViewGroup.java:6193)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:20696)
        at android.view.ViewGroup.layout(ViewGroup.java:6193)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
        at android.view.View.layout(View.java:20696)
        at android.view.ViewGroup.layout(ViewGroup.java:6193)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:20696)
        at android.view.ViewGroup.layout(ViewGroup.java:6193)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
        at android.view.View.layout(View.java:20696)
        at android.view.ViewGroup.layout(ViewGroup.java:6193)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at com.android.internal.policy.DecorView.onLayout(DecorView.java:766)
        at android.view.View.layout(View.java:20696)
        at android.view.ViewGroup.layout(ViewGroup.java:6193)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2832)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2359)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1500)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7418)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1019)
        at android.view.Choreographer.doCallbacks(Choreographer.java:830)
2019-05-10 20:33:53.937 29043-29043 E/AndroidRuntime:     at android.view.Choreographer.doFrame(Choreographer.java:765)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1005)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6740)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:495)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:859)

@tingyik90
Copy link
Owner

@bwalsh0, thanks for the details. I've narrowed it down to the wrong casting of parent view in animateContentIn.

A new code was added since I'm now exposing SnackProgressBarLayout and user can actually add margin to the parent view to make the SnackProgressBar to appear above the bottom navigation bar etc. With that consideration, I need to include the bottom margin of the parent view for extra translation of other views set to animate together.

The casting is now corrected. Please give implementation 'com.github.tingyik90:snackprogressbar:c4a1fb7467' a try and let me know if you can use CoordinatorLayout now.

@bwalsh0
Copy link
Author

bwalsh0 commented May 11, 2019

Works perfectly with CoordinatorLayout on that build now, thanks! Glad to hear the layout can use a margin now, I've held off from migrating to bottom navigation due to conflicts with fabs/snackbars in the past.

@tingyik90
Copy link
Owner

Great! Might be a good time to test now. I'll publish this as new release soon. Pending another issue to be closed. I'll let you know when a new version is available.

@starsep
Copy link

starsep commented Jul 30, 2019

Hi, any chance for release with the fix?
I confirm that implementation 'com.github.tingyik90:snackprogressbar:c4a1fb7467' fixes the issue for me.

@tingyik90
Copy link
Owner

Hi @starsep, thanks for the reminder. I've released this as v6.1.1. I was originally pending issue #22 to be closed together, so if anyone encounter that issue, please do share more information with me as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants