massivemadness / Fragula

🧛 Fragula is a swipe-to-dismiss extension for navigation component library for Android
Apache License 2.0
331 stars 18 forks source link

Exception when clicking on the back arrow button while swiping a swipeable fragment #13

Closed KitsuneFolk closed 1 year ago

KitsuneFolk commented 1 year ago

Library Version: 2.7

Affected Device(s): Redmi 9C with Android 10, API 29 Describe the bug If we open a swipeable fragment and then try to unswipe on 5dp or something, then slowly swipe back and press the back arrow button in the toolbar, the fragment becomes black. If we swipe from right to left, then it back to normal, but swipeable fragments in the recyclerview are not opening and if we try to open a swipeable fragment from the navigation view again, it throws the exception below:

java.lang.IllegalStateException: Fragment SwipeBackFragment{21e6e36} (56b51e72-7a1b-490c-82f0-2ad41f0a08f2) not attached to a context.
                                                                                                        at androidx.fragment.app.Fragment.requireContext(Fragment.java:967)
                                                                                                        at com.fragula2.adapter.NavBackStackAdapter.createFragment(NavBackStackAdapter.kt:14)
                                                                                                        at androidx.viewpager2.adapter.FragmentStateAdapter.ensureFragment(FragmentStateAdapter.java:268)
                                                                                                        at androidx.viewpager2.adapter.FragmentStateAdapter.onBindViewHolder(FragmentStateAdapter.java:175)
                                                                                                        at androidx.viewpager2.adapter.FragmentStateAdapter.onBindViewHolder(FragmentStateAdapter.java:67)
                                                                                                        at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7065)
                                                                                                        at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7107)
                                                                                                        at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6012)
                                                                                                        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6279)
                                                                                                        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
                                                                                                        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
                                                                                                        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
                                                                                                        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
                                                                                                        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
                                                                                                        at androidx.recyclerview.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1391)
                                                                                                        at androidx.recyclerview.widget.LinearLayoutManager.scrollHorizontallyBy(LinearLayoutManager.java:1116)
                                                                                                        at androidx.recyclerview.widget.RecyclerView.scrollStep(RecyclerView.java:1838)
                                                                                                        at androidx.recyclerview.widget.RecyclerView.scrollByInternal(RecyclerView.java:1940)
                                                                                                        at androidx.recyclerview.widget.RecyclerView.scrollBy(RecyclerView.java:1812)
                                                                                                        at androidx.viewpager2.widget.FakeDrag.fakeDragBy(FakeDrag.java:95)
                                                                                                        at androidx.viewpager2.widget.ViewPager2.fakeDragBy(ViewPager2.java:735)
                                                                                                        at com.fragula2.utils.ExtensionsKt.fakeDragTo$lambda$1$lambda$0(Extensions.kt:88)
                                                                                                        at com.fragula2.utils.ExtensionsKt.$r8$lambda$C6bpgJwUl--4hf-kWEmxak-d7uU(Unknown Source:0)
                                                                                                        at com.fragula2.utils.ExtensionsKt$$ExternalSyntheticLambda0.onAnimationUpdate(Unknown Source:8)
                                                                                                        at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1558)
                                                                                                        at android.animation.ValueAnimator.animateBasedOnTime(ValueAnimator.java:1349)
                                                                                                        at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1481)
                                                                                                        at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)
                                                                                                        at android.animation.AnimationHandler.access$100(AnimationHandler.java:37)
                                                                                                        at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
                                                                                                        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1039)
                                                                                                        at android.view.Choreographer.doCallbacks(Choreographer.java:860)
                                                                                                        at android.view.Choreographer.doFrame(Choreographer.java:781)
                                                                                                        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1026)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:914)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:100)
                                                                                                        at android.os.Looper.loop(Looper.java:225)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:7563)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)

To Reproduce Steps to reproduce the behavior:

  1. Open the native kotlin fragula app
  2. Open the Settings fragment in the navigation view
  3. Swipe from left to right a few millimeters, swipe back from right to left while pressing the toolbar's back button
  4. See the black screen, then swipe from right to left to get the fragment to normal
  5. Open the Settings fragment again and see the exception

I attached a video file, so you can see how exactly to reproduce the bug: https://github.com/massivemadness/Fragula/assets/104719315/cb79f3b7-0c0c-4fbf-b8ae-0f47145c91d9

massivemadness commented 1 year ago

@MrRuslanYT привет, спасибо видео, постараюсь воспроизвести

massivemadness commented 1 year ago

@MrRuslanYT попробуй этот билд - 4995414771. Максимально костыльный фикс, но вроде работает

KitsuneFolk commented 1 year ago

@massivemadness не, все равно баг сохраняется, уже удалил старое приложение и установил новый апк, не помогло

KitsuneFolk commented 1 year ago

@massivemadness Сделал фикс в MainActivity, как я могу сделать pull request? Я попробовал через таб Pull Requestes, не получилось: Can't create a new pull request: Push failed: remote: Permission to massivemadness/Fragula.git denied to MrRuslanYT. unable to access 'https://github.com/massivemadness/Fragula.git/': The requested URL returned error: 403

massivemadness commented 1 year ago

@MrRuslanYT тебе нужно форкнуть репозиторий и запушить в него изменения. Дальше твой форк с изменениями можно будет использовать для создания PR

massivemadness commented 1 year ago

Сделал билд с исправлением, у меня проблема ушла (5098610511). Добавил проверку, чтобы в момент программного или пользовательского скроллинга нельзя было удалить страницу из viewpager-а. Подтверди как освободишься

KitsuneFolk commented 1 year ago

Подтверждаю, баг исправлен, всё работает хорошо.