massivemadness / fragula Goto Github PK
View Code? Open in Web Editor NEWπ§ Fragula is a swipe-to-dismiss extension for navigation component library for Android
License: Apache License 2.0
π§ Fragula is a swipe-to-dismiss extension for navigation component library for Android
License: Apache License 2.0
ΠΡΠΈ ΠΎΠ±Π½ΠΎΠ²Π»Π΅Π½ΠΈΠΈ androidx.navigation:navigation ΠΊ 2.6.0 ΠΌΠ΅ΡΠΎΠ΄ backQueue
(ΠΊΠΎΡΠΎΡΡΠΉ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΡΡΡ Π² SwipeBackFragment.restoreBackStack
ΡΡΠ°Π» ΠΏΡΠΈΠ²Π°ΡΠ½ΡΠΌ, ΠΈΠ·-Π·Π° ΡΡΠΎΠ³ΠΎ Π²ΠΎΠ·Π½ΠΈΠΊΠ°Π΅Ρ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ ΠΏΡΠΈ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠΈ Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΠΈ Ρ ΠΎΠ±Π½ΠΎΠ²Π»ΡΠ½Π½ΠΎΠΉ dependencie, ΠΡΡΡ Π΄ΡΡΠ³ΠΎΠΉ ΠΌΠ΅ΡΠΎΠ΄, Π½ΠΎ ΠΎΠ½ ΡΠ°ΠΊΠΆΠ΅ ΠΎΠ³ΡΠ°Π½ΠΈΡΠ΅Π½ Π² ΠΏΡΠ΅Π΄Π΅Π»Π°Ρ
Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΠΈ ΠΈ ΠΌΠΎΠΆΠ΅Ρ ΡΡΠ°ΡΡ Π½Π΅ Π΄ΠΎΡΡΡΠΏΠ΅Π½ Π² ΡΠ»Π΅Π΄ΡΡΡΠΈΡ
Π²Π΅ΡΡΠΈΡΡ
navigation, ΠΈ Π΅ΡΡ Π΅Π³ΠΎ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠ΅ Π½Π΅ Π²ΡΠ·ΡΠ²Π°Π΅Ρ pop()
Π½Π° ΡΡΠ°Π³ΠΌΠ΅Π½ΡΠ΅ ΠΏΡΠΈ Π½Π°ΠΆΠ°ΡΠΈΠΈ Π½Π° back button, Π° ΡΡΠ°Π·Ρ Π·Π°ΠΊΡΡΠ²Π°Π΅Ρ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅:
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@get:RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public val currentBackStack: StateFlow<List<NavBackStackEntry>> =
_currentBackStack.asStateFlow()
Π’Π΅ΡΡΠΈΡΡΠ΅ΠΌΡΠΉ ΠΊΠΎΠ΄ ΠΌΠ΅ΡΠΎΠ΄Π° Ρ Π±Π°Π³ΠΎΠΌ:
private fun restoreBackStack() {
viewPager?.currentItem = navController?.currentBackStack?.value.orEmpty()
.filter { it.destination is SwipeBackDestination }
.also { navBackStackAdapter?.addAll(it) }
.size
}
Π― ΠΌΠΎΠ³ Π±Ρ ΠΏΠ΅ΡΠ΅ΠΏΠΈΡΠ°ΡΡ Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΡ ΠΈ Π΄ΠΎΠ±Π°Π²ΠΈΡΡ ΠΌΠ΅ΡΠΎΠ΄ Π² NavBackStackAdapter ΡΡΠΎ Π±Ρ ΠΏΠΎΠ»ΡΡΠΈΡΡ ΡΡΠ°Π³ΠΌΠ΅Π½Ρ, Π½ΠΎ Ρ ΠΏΠΎΠ΄ΡΠΌΠ°Π» ΠΌΠΎΠΆΠ΅Ρ ΡΡΡΠ΅ΡΡΠ²ΡΠ΅Ρ Π»ΡΡΡΠΈΠΉ ΡΠΏΠΎΡΠΎΠ±? Π― ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΡ ΡΠ²Π°ΠΉΠΏ ΡΡΠ°Π³ΠΌΠ΅Π½Ρ Ρ Π²Π»ΠΎΠΆΠ΅Π½Π½ΡΠΌΠΈ ΡΡΠ°Π³ΠΌΠ΅Π½ΡΠ°ΠΌΠΈ Π²Π½ΡΡΡΠΈ, ΠΏΡΠΈ Π½Π°ΠΆΠ°ΡΠΈΠΈ Π½Π° Π°ΠΉΡΠ΅ΠΌ ΠΌΠ΅Π½Ρ ΠΌΠ½Π΅ Π½ΡΠΆΠ½ΠΎ ΠΏΠΎΠ»ΡΡΠΈΡΡ ΡΡΠ°Π³ΠΌΠ΅Π½Ρ ΡΡΠΎ Π±Ρ Π²ΡΠ·Π²Π°ΡΡ navigate
Π Π±ΠΈΠ»Π΄Π΅ minSdk ΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½ 23, Ρ ΠΏΠΎΠ½ΠΈΠ·ΠΈΠ» Π΄ΠΎ 21 Π² ΡΠΎΡΠΊΠ½ΡΡΠΎΠΌ ΡΠ΅ΠΏΠΎΠ·ΠΈΡΠΎΡΠΈΠΈ, ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ Π·Π°ΠΏΡΡΠΊΠ°Π΅ΡΡΡ, Π΅ΡΡΡ Π»ΠΈ ΠΊΠ°ΠΊΠ°Ρ ΡΠΎ Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎΡΡΡ Π² ΡΡΡΠ°Π½ΠΎΠ²ΠΊΠΈ minSdk ΠΊΠ°ΠΊ 23 Π²ΠΌΠ΅ΡΡΠΎ 21? ΠΡΠ»ΠΈ Π½Π΅ΡΡ, ΡΠΎ Ρ ΠΌΠΎΠ³Ρ ΡΠ΄Π΅Π»Π°ΡΡ pull request Ρ ΠΏΠΎΠ½ΠΈΠΆΠ΅Π½Π½ΡΠΌ sdk.
In the build file minSdk is set to 23, I downgraded to 21 in my forked repo, the app has started, is there a need to set minSdk as 23 instead of 21? If no, I can make a pull request with minSdk 21.
Please consider making a Pull Request if you are capable of doing so.
Library Version:
2.8
Affected Device(s):
Redmi 9C
Describe the bug
Π’ΠΈΡ
ΠΎΠ΅ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ ΠΏΡΠΈ ΡΠ²Π°ΠΉΠΏΠ΅ ΡΡΠ°Π³ΠΌΠ΅Π½ΡΠ°:
2023-06-13 11:53:36.549 10961-10961 RecyclerView com.fragula2.sample W Cannot call this method in a scroll callback. Scroll callbacks mightbe run during a measure & layout pass where you cannot change theRecyclerView data. Any method call that might change the structureof the RecyclerView or the adapter contents should be postponed tothe next frame.
java.lang.IllegalStateException: androidx.viewpager2.widget.ViewPager2$RecyclerViewImpl{16cf409 VFED..... ......ID 0,0-720,1433 #1}, adapter:com.fragula2.adapter.NavBackStackAdapter@625909f, layout:androidx.viewpager2.widget.ViewPager2$LinearLayoutManagerImpl@a0935ec, context:com.fragula2.sample.MainActivity@56ee45d
at androidx.recyclerview.widget.RecyclerView.assertNotInLayoutOrScroll(RecyclerView.java:3061)
at androidx.recyclerview.widget.RecyclerView$RecyclerViewDataObserver.onItemRangeRemoved(RecyclerView.java:5563)
at androidx.recyclerview.widget.RecyclerView$AdapterDataObservable.notifyItemRangeRemoved(RecyclerView.java:12288)
at androidx.recyclerview.widget.RecyclerView$Adapter.notifyItemRemoved(RecyclerView.java:7515)
at com.fragula2.adapter.NavBackStackAdapter.pop(NavBackStackAdapter.kt:55)
at com.fragula2.navigation.SwipeBackFragment.popBackStack(SwipeBackFragment.kt:163)
at com.fragula2.navigation.SwipeBackNavigator.popBackStack(SwipeBackNavigator.kt:80)
at androidx.navigation.NavController.popBackStackInternal(NavController.kt:274)
at androidx.navigation.NavController.popBackStackInternal(NavController.kt:557)
at androidx.navigation.NavController.popBackStack(NavController.kt:472)
at androidx.navigation.NavController.popBackStack(NavController.kt:449)
at androidx.navigation.NavController.popBackStack(NavController.kt:434)
at com.fragula2.navigation.SwipeBackFragment$onPageChangeCallback$1.onPageScrollStateChanged(SwipeBackFragment.kt:56)
at androidx.viewpager2.widget.CompositeOnPageChangeCallback.onPageScrollStateChanged(CompositeOnPageChangeCallback.java:87)
at androidx.viewpager2.widget.CompositeOnPageChangeCallback.onPageScrollStateChanged(CompositeOnPageChangeCallback.java:87)
at androidx.viewpager2.widget.ScrollEventAdapter.dispatchStateChanged(ScrollEventAdapter.java:426)
at androidx.viewpager2.widget.ScrollEventAdapter.onScrolled(ScrollEventAdapter.java:214)
at androidx.recyclerview.widget.RecyclerView.dispatchOnScrolled(RecyclerView.java:5173)
at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5338)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1041)
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:
ΠΡΠΈ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠΈ
viewPager?.post {
navBackStackAdapter?.pop()
}
Π²ΠΌΠ΅ΡΡΠΎ
navBackStackAdapter?.pop()
ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΡ Π½Π΅ΡΡ, ΡΠ΄Π΅Π»Π°Ρ pr ΠΊΠ°ΠΊ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΡΠΉ ΡΠΈΠΊΡ.
#22
Library Version:
2.7
Affected Device(s):
Redmi 9C with API 29
Describe the bug
Edittext loses it's cursor when clicking on it the first time a swipeable fragment is launched
To Reproduce
Steps to reproduce the behavior:
hello, if there is viewpager2 in my fragment, scrolling is not working, how to fix it, please help
Thank you for submitting! This is to notify you that your library is live on JetpackCompose.app!
Unable navigate from a "fragment" tag fragment to "swipeable" tag fragment or pop to "swipable"
NavController.popBackStack()
methodSwipeController
analogue)Describe the solution you'd like
I hope apply scroll animation when call navController().navigateUp()
Describe alternatives you've considered
I found accompanist-navigation-animation:0.16.1, which does not have gestures, but does this issue: https://medium.com/androiddevelopers/animations-in-navigation-compose-36d48870776b
Is it possible to combine Fragula with it?
Hi, I wanted to ask something. Is it possible to restrict swiping, i.e. if you swipe anywhere other than the farthest part of the screen on the left, it should not go back
Please consider making a Pull Request if you are capable of doing so.
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Describe the bug
There's an issue when navigating from <swipeable>
to <fragment>
destination, the fragment will not be added to the backstack, which makes impossible to go back using popBackStack()
or navigateUp()
methods.
To Reproduce
Steps to reproduce the behavior:
<swipeable>
your start destination<fragment>
destinationpopBackStack()
to return to the previous fragmentAny ideas of how to fix
The issue is not exactly in SwipeBackNavigator, It's the default behavior of androidx.navigation.fragment.FragmentNavigator
, which depends on the backstack size to decide whether it should add a transaction to the backstack or not.
Hey, thank you for this useful library.
How can i have some not-swipeable screen?
imagine i have 10 swipeable screen, but i want to keep one of them normal, i dont want to be swipeable that one.
using composable instead swipeable not working!
example usage with supportFragmentManager please
navController.navigate("List"){
popUpTo(navController.graph.id){
inclusive = true
}
}
when use this code it alway crash
Stack trace:
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
at com.ald.devs47.sam.beckman.palettesetups.models.HomeSetupModel.hashCode(Unknown Source:136)
at androidx.navigation.NavBackStackEntry.hashCode(NavBackStackEntry.kt:256)
at java.util.HashMap.hash(HashMap.java:338)
at java.util.HashMap.put(HashMap.java:611)
at androidx.navigation.NavController.linkChildToParent(NavController.kt:143)
at androidx.navigation.NavController.addEntryToBackStack(NavController.kt:1918)
at androidx.navigation.NavController.addEntryToBackStack$default(NavController.kt:1813)
at androidx.navigation.NavController$navigate$4.invoke(NavController.kt:1721)
at androidx.navigation.NavController$navigate$4.invoke(NavController.kt:1719)
at androidx.navigation.NavController$NavControllerNavigatorState.push(NavController.kt:287)
at com.fragula2.navigation.SwipeBackNavigator.navigate(SwipeBackNavigator.kt:54)
at com.fragula2.navigation.SwipeBackNavigator.navigate(SwipeBackNavigator.kt:33)
at androidx.navigation.NavController.navigateInternal(NavController.kt:260)
at androidx.navigation.NavController.navigate(NavController.kt:1719)
at androidx.navigation.NavController.navigate(NavController.kt:1545)
at androidx.navigation.NavController.navigate(NavController.kt:1472)
at androidx.navigation.NavController.navigate(NavController.kt:1454)
at com.ald.devs47.sam.beckman.palettesetups.recycler.carouselRecycler.CarouselAdapter.onBindViewHolder$lambda$0(CarouselAdapter.kt:136)
at com.ald.devs47.sam.beckman.palettesetups.recycler.carouselRecycler.CarouselAdapter.lambda$TKKZbMgavm5g5IcEqe_Or5TbKTc(Unknown Source:0)
at com.ald.devs47.sam.beckman.palettesetups.recycler.carouselRecycler.-$$Lambda$CarouselAdapter$TKKZbMgavm5g5IcEqe_Or5TbKTc.onClick(Unknown Source:4)
at android.view.View.performClick(View.java:7743)
at android.view.View.performClickInternal(View.java:7720)
at android.view.View.access$3700(View.java:854)
at android.view.View$PerformClick.run(View.java:29111)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8309)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1038)
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:
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.