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

Suggestion - Extend ISwipeable #1008

Closed
1 of 2 tasks
MFlisar opened this issue Sep 2, 2021 · 6 comments
Closed
1 of 2 tasks

Suggestion - Extend ISwipeable #1008

MFlisar opened this issue Sep 2, 2021 · 6 comments
Assignees

Comments

@MFlisar
Copy link
Contributor

MFlisar commented Sep 2, 2021

About this issue

I want to distinguish between items the do allow swipe left / swipe right / both. Currently I can only distinguish can swipe / can not swipe.

My suggestion is to extend the ISwipeable interface:

interface ISwipeable {
    /** @return true if swipeable */
    val isSwipeable: Boolean

    /** @return true if the provided direction is supported */
    fun isDirectionSupported(direction: Int) : Boolean = true
}

What do you think about this? It's a very small and backwards compatible change with the default implementation inside the interface. isDirectionSupported will only be called if isSwipeable return true.

Details

  •  Used library version: 5.4.1
  •  Used support library version: androidx
@mikepenz
Copy link
Owner

mikepenz commented Sep 3, 2021

@MFlisar being able to identify the swipeable direction makes sense.

How would the real implementation for isDirectionSupported look like?
Would a different interface not also fullfil this requirement? (As the implementation itself would also fall in the target apps responsibility it looks like?)

@mikepenz mikepenz self-assigned this Sep 3, 2021
@MFlisar
Copy link
Contributor Author

MFlisar commented Sep 3, 2021

How would the real implementation for isDirectionSupported look like?

I do have items that do support "starting" them and sections, that do not support this. But both items do support delete. so I would use it like following:

In my case like following:

class ItemSection(val data: Data) : IItem, ISwipeable  {

	val isSwipeable: Boolean = true
	
	fun isDirectionSupported(direction: Int) : Boolean {
		return direction = ItemTouchHelper.RIGHT; // only right swipe is supported, sections can only be deleted and can't be started
	}
	
}

class Item(val data: Data) : IItem, ISwipeable  {
	
	val isSwipeable: Boolean = true
	
	fun isDirectionSupported(direction: Int) : Boolean {
		return true; // items can be started and deleted, so both swipe directions are supported
	}
	
}

Would a different interface not also fullfil this requirement?

Sure, but personally I think an interface with default implementation is more discoverable (especially if the features are so closely)

@MFlisar
Copy link
Contributor Author

MFlisar commented Sep 3, 2021

By the way, if backwards compatibility is not required, I would even replace the interface with following for the sake of simplicity:

interface ISwipeable {
    fun isSwipeable(direction: Int) : Boolean
}

Migration guide would simply look like following:

Replace

  override val isSwipeable = true|false

With

 override fun isSwipeable(direction: Int) = true|false

@mikepenz
Copy link
Owner

mikepenz commented Sep 5, 2021

I'd opt for the backwards compatible form. Looked over it, and your proposal makes sense.
It will also need to be integrated SimpleSwipeDrawerCallback and SimpleSwipeCallback

Would you like to open a PR for this?

@MFlisar
Copy link
Contributor Author

MFlisar commented Sep 6, 2021

Would you like to open a PR for this?

Done

@mikepenz
Copy link
Owner

Thank you so much. Will be in the next update

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

2 participants