Skip to content

Comments

Change default move behavior on overscroll from insert to swap#95

Merged
Calvin-LL merged 7 commits intoCalvin-LL:mainfrom
vipulm7:main
Aug 12, 2025
Merged

Change default move behavior on overscroll from insert to swap#95
Calvin-LL merged 7 commits intoCalvin-LL:mainfrom
vipulm7:main

Conversation

@vipulm7
Copy link
Contributor

@vipulm7 vipulm7 commented Aug 12, 2025

… instead of moving them in list

@vipulm7
Copy link
Contributor Author

vipulm7 commented Aug 12, 2025

Please feel free to comment, if you have any doubts or anything.

@Calvin-LL
Copy link
Owner

hmm I'll take a look. at first sight I'm not sure exactly what this does. onMove swaps two items in lazylists already

@Calvin-LL
Copy link
Owner

Calvin-LL commented Aug 12, 2025

Is this generated by GPT-5 or Claude? swap does the same thing as add(to.index, removeAt(from.index))

@Calvin-LL Calvin-LL closed this Aug 12, 2025
@vipulm7
Copy link
Contributor Author

vipulm7 commented Aug 12, 2025

nope. I did the whole changes by myself
You would see the changes in SimpleSwappableLazyVerticalGridScreen and SimpleSwappableLazyHorizontalGridScreen
When you drag the items in opposite orientation, the you would see the difference that items are swapped, rather than moved.
For rest of the screens, it will be same as before.

@vipulm7
Copy link
Contributor Author

vipulm7 commented Aug 12, 2025

also, have a look at swap function

fun MutableList.swap(from: Int, to: Int) {
val temp = this[from]
this[from] = this[to]
this[to] = temp
}

@Calvin-LL Calvin-LL reopened this Aug 12, 2025
@Calvin-LL
Copy link
Owner

oh I see

@Calvin-LL
Copy link
Owner

thank you for the PR. I'll take a deeper look

@vipulm7
Copy link
Contributor Author

vipulm7 commented Aug 12, 2025

Thanks. Took me 2 full days to understand how the code works.
As I said in the beginning,
Please feel free to comment, if you have any doubts or anything.

@Calvin-LL
Copy link
Owner

it sure is complicated. every time I come here to fix an issue it takes me a day to figure out what's going on as well 😆

@vipulm7
Copy link
Contributor Author

vipulm7 commented Aug 12, 2025

Oh, nice

@Calvin-LL
Copy link
Owner

is there reason for isSwappable?

Just changing add(to.index, removeAt(from.index)) to swap(to.index, from.index) seems to do the same thing.

Where can I find a situation where isSwappable = true helps?

@vipulm7
Copy link
Contributor Author

vipulm7 commented Aug 12, 2025

it works nicely when you drag and replace within the visible items.
it will truly help you, when you go out of bounds and it starts scrolling, then you see that if you don't apply below condition, ui doesn't look that smooth
Orientation.Vertical -> item.offset.x == draggingItem.offset.x

@Calvin-LL
Copy link
Owner

ah yes I see you're right

@Calvin-LL Calvin-LL changed the title Swappable Horizontal/Vertical Screens added which swaps items in list… Change swap behavior on overscroll from insert to swap Aug 12, 2025
@Calvin-LL Calvin-LL changed the title Change swap behavior on overscroll from insert to swap Change default move behavior on overscroll from insert to swap Aug 12, 2025
@Calvin-LL Calvin-LL merged commit 311c165 into Calvin-LL:main Aug 12, 2025
@vipulm7
Copy link
Contributor Author

vipulm7 commented Aug 13, 2025

Thanks a lot.

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

Successfully merging this pull request may close these issues.

2 participants